summaryrefslogtreecommitdiff
path: root/src/pcm/interval_inline.h
blob: bf6b784a62ea838f8978b493d7e57807db8d4463 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 *  Interval inlines
 *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
 *
 *
 *   This library is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as
 *   published by the Free Software Foundation; either version 2.1 of
 *   the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */
  
#define INTERVAL_INLINE static inline

INTERVAL_INLINE void snd_interval_any(snd_interval_t *i)
{
	i->min = 0;
	i->openmin = 0;
	i->max = UINT_MAX;
	i->openmax = 0;
	i->integer = 0;
	i->empty = 0;
}

INTERVAL_INLINE void snd_interval_none(snd_interval_t *i)
{
	i->empty = 1;
}

INTERVAL_INLINE int snd_interval_checkempty(const snd_interval_t *i)
{
	return (i->min > i->max ||
		(i->min == i->max && (i->openmin || i->openmax)));
}

INTERVAL_INLINE int snd_interval_empty(const snd_interval_t *i)
{
	return i->empty;
}

INTERVAL_INLINE int snd_interval_single(const snd_interval_t *i)
{
	assert(!snd_interval_empty(i));
	return (i->min == i->max || 
		(i->min + 1 == i->max && i->openmax));
}

INTERVAL_INLINE int snd_interval_value(const snd_interval_t *i)
{
	assert(snd_interval_single(i));
	return i->min;
}

INTERVAL_INLINE void snd_interval_set_value(snd_interval_t *i, unsigned int val)
{
	i->openmax = i->openmin = 0;
	i->min = i->max = val;
	i->integer = 0;
	i->empty = 0;
}

INTERVAL_INLINE int snd_interval_min(const snd_interval_t *i)
{
	assert(!snd_interval_empty(i));
	return i->min;
}

INTERVAL_INLINE int snd_interval_max(const snd_interval_t *i)
{
	assert(!snd_interval_empty(i));
	return i->max;
}

INTERVAL_INLINE void snd_interval_set_minmax(snd_interval_t *i, unsigned int min, unsigned int max)
{
	i->openmax = i->openmin = 0;
	i->min = min;
	i->max = max;
	i->integer = 0;
	i->empty = 0;
}

INTERVAL_INLINE int snd_interval_test(const snd_interval_t *i, unsigned int val)
{
	return !((i->min > val || (i->min == val && i->openmin) ||
		  i->max < val || (i->max == val && i->openmax)));
}

INTERVAL_INLINE void snd_interval_copy(snd_interval_t *d, const snd_interval_t *s)
{
	*d = *s;
}

INTERVAL_INLINE int snd_interval_setinteger(snd_interval_t *i)
{
	if (i->integer)
		return 0;
	if (i->openmin && i->openmax && i->min == i->max)
		return -EINVAL;
	i->integer = 1;
	return 1;
}

INTERVAL_INLINE void snd_interval_floor(snd_interval_t *i)
{
	if (i->integer || snd_interval_empty(i))
		return;
	i->openmin = 0;
	if (i->openmax) {
		i->max--;
		i->openmax = 0;
	}
	i->integer = 1;
}

INTERVAL_INLINE void snd_interval_unfloor(snd_interval_t *i)
{
	if (snd_interval_empty(i))
		return;
	if (i->max == UINT_MAX)
		return;
	if (i->openmax)
		return;
	i->max++;
	i->openmax = 1;
	i->integer = 0;
}


INTERVAL_INLINE int snd_interval_always_eq(const snd_interval_t *i1, const snd_interval_t *i2)
{
	return snd_interval_single(i1) && snd_interval_single(i2) &&
		snd_interval_value(i1) == snd_interval_value(i2);
}

INTERVAL_INLINE int snd_interval_never_eq(const snd_interval_t *i1, const snd_interval_t *i2)
{
	
	return (i1->max < i2->min || 
		(i1->max == i2->min &&
		 (i1->openmax || i1->openmin)) ||
		i1->min > i2->max ||
		(i1->min == i2->max &&
		 (i1->openmin || i2->openmax)));
}