blob: 3541b43c312cb2e3450ea65d2c6584d45c0c4927 (
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/*
* tkRangeListPriv.h --
*
* Private implementation for range list.
*
* Copyright (c) 2015-2017 Gregor Cramer
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#ifndef _TKRANGELIST
# error "do not include this private header file"
#endif
#ifdef _TK_NEED_IMPLEMENTATION
#include <stddef.h>
#include <assert.h>
#ifdef _MSC_VER
# if _MSC_VER >= 1900
# define inline __inline
# else
# define inline
# endif
#elif __STDC_VERSION__ < 199901L
# define inline /* we are not C99 conform */
#endif
inline
int
TkRangeSpan(
const TkRange *range)
{
assert(range);
return range->high - range->low + 1;
}
inline
bool
TkRangeTest(
const TkRange *range,
int value)
{
assert(range);
return range->low <= value && value <= range->high;
}
inline
bool
TkRangeListIsEmpty(
const TkRangeList *ranges)
{
assert(ranges);
return ranges->size == 0;
}
inline
int
TkRangeListLow(
const TkRangeList *ranges)
{
assert(ranges);
assert(!TkRangeListIsEmpty(ranges));
return ranges->items[0].low;
}
inline
int
TkRangeListHigh(
const TkRangeList *ranges)
{
assert(ranges);
assert(!TkRangeListIsEmpty(ranges));
return ranges->items[ranges->size - 1].high;
}
inline
unsigned
TkRangeListSpan(
const TkRangeList *ranges)
{
assert(ranges);
return ranges->size ? TkRangeListHigh(ranges) - TkRangeListLow(ranges) + 1 : 0;
}
inline
unsigned
TkRangeListSize(
const TkRangeList *ranges)
{
assert(ranges);
return ranges->size;
}
inline
unsigned
TkRangeListCount(
const TkRangeList *ranges)
{
assert(ranges);
return ranges->count;
}
inline
const TkRange *
TkRangeListAccess(
const TkRangeList *ranges,
unsigned index)
{
assert(ranges);
assert(index < TkRangeListSize(ranges));
return &ranges->items[index];
}
inline
bool
TkRangeListContains(
const TkRangeList *ranges,
int value)
{
return !!TkRangeListFind(ranges, value);
}
inline
bool
TkRangeListContainsRange(
const TkRangeList *ranges,
int low,
int high)
{
const TkRange *range = TkRangeListFind(ranges, low);
return range && range->high <= high;
}
inline
const TkRange *
TkRangeListFirst(
const TkRangeList *ranges)
{
assert(ranges);
return ranges->size == 0 ? NULL : ranges->items;
}
inline
const TkRange *
TkRangeListNext(
const TkRangeList *ranges,
const TkRange *item)
{
assert(item);
assert(ranges);
assert(ranges->items <= item && item < ranges->items + ranges->size);
return ++item == ranges->items + ranges->size ? NULL : item;
}
#undef _TK_NEED_IMPLEMENTATION
#endif /* _TK_NEED_IMPLEMENTATION */
/* vi:set ts=8 sw=4: */
|