• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Interval inlines
3  *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
4  *
5  *
6  *   This library is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU Lesser General Public License as
8  *   published by the Free Software Foundation; either version 2.1 of
9  *   the License, or (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU Lesser General Public License for more details.
15  *
16  *   You should have received a copy of the GNU Lesser General Public
17  *   License along with this library; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 
22 #define INTERVAL_INLINE static inline
23 
snd_interval_any(snd_interval_t * i)24 INTERVAL_INLINE void snd_interval_any(snd_interval_t *i)
25 {
26 	i->min = 0;
27 	i->openmin = 0;
28 	i->max = UINT_MAX;
29 	i->openmax = 0;
30 	i->integer = 0;
31 	i->empty = 0;
32 }
33 
snd_interval_none(snd_interval_t * i)34 INTERVAL_INLINE void snd_interval_none(snd_interval_t *i)
35 {
36 	i->empty = 1;
37 }
38 
snd_interval_checkempty(const snd_interval_t * i)39 INTERVAL_INLINE int snd_interval_checkempty(const snd_interval_t *i)
40 {
41 	return (i->min > i->max ||
42 		(i->min == i->max && (i->openmin || i->openmax)));
43 }
44 
snd_interval_empty(const snd_interval_t * i)45 INTERVAL_INLINE int snd_interval_empty(const snd_interval_t *i)
46 {
47 	return i->empty;
48 }
49 
snd_interval_single(const snd_interval_t * i)50 INTERVAL_INLINE int snd_interval_single(const snd_interval_t *i)
51 {
52 	assert(!snd_interval_empty(i));
53 	return (i->min == i->max ||
54 		(i->min + 1 == i->max && (i->openmin || i->openmax)));
55 }
56 
snd_interval_value(const snd_interval_t * i)57 INTERVAL_INLINE int snd_interval_value(const snd_interval_t *i)
58 {
59 	assert(snd_interval_single(i));
60 	if (i->openmin && !i->openmax)
61 		return i->max;
62 	return i->min;
63 }
64 
snd_interval_set_value(snd_interval_t * i,unsigned int val)65 INTERVAL_INLINE void snd_interval_set_value(snd_interval_t *i, unsigned int val)
66 {
67 	i->openmax = i->openmin = 0;
68 	i->min = i->max = val;
69 	i->integer = 0;
70 	i->empty = 0;
71 }
72 
snd_interval_min(const snd_interval_t * i)73 INTERVAL_INLINE int snd_interval_min(const snd_interval_t *i)
74 {
75 	assert(!snd_interval_empty(i));
76 	return i->min;
77 }
78 
snd_interval_max(const snd_interval_t * i)79 INTERVAL_INLINE int snd_interval_max(const snd_interval_t *i)
80 {
81 	assert(!snd_interval_empty(i));
82 	return i->max;
83 }
84 
snd_interval_set_minmax(snd_interval_t * i,unsigned int min,unsigned int max)85 INTERVAL_INLINE void snd_interval_set_minmax(snd_interval_t *i, unsigned int min, unsigned int max)
86 {
87 	i->openmax = i->openmin = 0;
88 	i->min = min;
89 	i->max = max;
90 	i->integer = 0;
91 	i->empty = 0;
92 }
93 
snd_interval_test(const snd_interval_t * i,unsigned int val)94 INTERVAL_INLINE int snd_interval_test(const snd_interval_t *i, unsigned int val)
95 {
96 	return !((i->min > val || (i->min == val && i->openmin) ||
97 		  i->max < val || (i->max == val && i->openmax)));
98 }
99 
snd_interval_copy(snd_interval_t * d,const snd_interval_t * s)100 INTERVAL_INLINE void snd_interval_copy(snd_interval_t *d, const snd_interval_t *s)
101 {
102 	*d = *s;
103 }
104 
snd_interval_setinteger(snd_interval_t * i)105 INTERVAL_INLINE int snd_interval_setinteger(snd_interval_t *i)
106 {
107 	if (i->integer)
108 		return 0;
109 	if (i->openmin && i->openmax && i->min == i->max)
110 		return -EINVAL;
111 	i->integer = 1;
112 	return 1;
113 }
114 
snd_interval_floor(snd_interval_t * i)115 INTERVAL_INLINE void snd_interval_floor(snd_interval_t *i)
116 {
117 	if (i->integer || snd_interval_empty(i))
118 		return;
119 	i->openmin = 0;
120 	if (i->openmax) {
121 		i->max--;
122 		i->openmax = 0;
123 	}
124 	i->integer = 1;
125 }
126 
snd_interval_unfloor(snd_interval_t * i)127 INTERVAL_INLINE void snd_interval_unfloor(snd_interval_t *i)
128 {
129 	if (snd_interval_empty(i))
130 		return;
131 	if (i->max == UINT_MAX)
132 		return;
133 	if (i->openmax)
134 		return;
135 	i->max++;
136 	i->openmax = 1;
137 	i->integer = 0;
138 }
139 
140 
snd_interval_always_eq(const snd_interval_t * i1,const snd_interval_t * i2)141 INTERVAL_INLINE int snd_interval_always_eq(const snd_interval_t *i1, const snd_interval_t *i2)
142 {
143 	return snd_interval_single(i1) && snd_interval_single(i2) &&
144 		snd_interval_value(i1) == snd_interval_value(i2);
145 }
146 
snd_interval_never_eq(const snd_interval_t * i1,const snd_interval_t * i2)147 INTERVAL_INLINE int snd_interval_never_eq(const snd_interval_t *i1, const snd_interval_t *i2)
148 {
149 
150 	return (i1->max < i2->min ||
151 		(i1->max == i2->min &&
152 		 (i1->openmax || i1->openmin)) ||
153 		i1->min > i2->max ||
154 		(i1->min == i2->max &&
155 		 (i1->openmin || i2->openmax)));
156 }
157 
158 
159 
160