This source file includes following definitions.
- gl_oset_create_empty
- gl_oset_nx_create_empty
- gl_oset_size
- gl_oset_search
- gl_oset_search_atleast
- gl_oset_nx_add
- gl_oset_remove
- gl_oset_update
- gl_oset_free
- gl_oset_iterator
- gl_oset_iterator_atleast
- gl_oset_iterator_next
- gl_oset_iterator_free
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef _GL_OSET_H
19 #define _GL_OSET_H
20
21 #include <stdbool.h>
22 #include <stddef.h>
23
24 #ifndef _GL_INLINE_HEADER_BEGIN
25 #error "Please include config.h first."
26 #endif
27 _GL_INLINE_HEADER_BEGIN
28 #ifndef GL_OSET_INLINE
29 # define GL_OSET_INLINE _GL_INLINE
30 #endif
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
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 typedef int (*gl_setelement_compar_fn) (const void *elt1, const void *elt2);
81
82 #ifndef _GL_SETELEMENT_DISPOSE_FN_DEFINED
83
84
85 typedef void (*gl_setelement_dispose_fn) (const void *elt);
86 # define _GL_SETELEMENT_DISPOSE_FN_DEFINED 1
87 #endif
88
89
90
91 typedef bool (*gl_setelement_threshold_fn) (const void *elt, const void *threshold);
92
93 struct gl_oset_impl;
94
95 typedef struct gl_oset_impl * gl_oset_t;
96
97 struct gl_oset_implementation;
98
99 typedef const struct gl_oset_implementation * gl_oset_implementation_t;
100
101 #if 0
102
103
104
105
106
107
108 extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
109 gl_setelement_compar_fn compar_fn,
110 gl_setelement_dispose_fn dispose_fn)
111
112 _GL_ATTRIBUTE_RETURNS_NONNULL;
113
114 extern gl_oset_t gl_oset_nx_create_empty (gl_oset_implementation_t implementation,
115 gl_setelement_compar_fn compar_fn,
116 gl_setelement_dispose_fn dispose_fn)
117 ;
118
119
120 extern size_t gl_oset_size (gl_oset_t set);
121
122
123
124 extern bool gl_oset_search (gl_oset_t set, const void *elt);
125
126
127
128
129
130
131 extern bool gl_oset_search_atleast (gl_oset_t set,
132 gl_setelement_threshold_fn threshold_fn,
133 const void *threshold,
134 const void **eltp);
135
136
137
138
139 extern bool gl_oset_add (gl_oset_t set, const void *elt);
140
141
142 _GL_ATTRIBUTE_NODISCARD
143 extern int gl_oset_nx_add (gl_oset_t set, const void *elt);
144
145
146
147 extern bool gl_oset_remove (gl_oset_t set, const void *elt);
148
149
150
151
152
153
154
155
156
157 extern int gl_oset_update (gl_oset_t set, const void *elt,
158 void (*action) (const void *elt, void *action_data),
159 void *action_data);
160
161
162
163
164 extern void gl_oset_free (gl_oset_t set);
165
166 #endif
167
168
169
170
171
172
173
174
175 typedef struct
176 {
177
178 const struct gl_oset_implementation *vtable;
179
180 gl_oset_t set;
181 size_t count;
182
183 void *p; void *q;
184 size_t i; size_t j;
185 } gl_oset_iterator_t;
186
187 #if 0
188
189
190
191
192 extern gl_oset_iterator_t gl_oset_iterator (gl_oset_t set);
193
194
195
196
197 extern gl_oset_iterator_t gl_oset_iterator_atleast (gl_oset_t set,
198 gl_setelement_threshold_fn threshold_fn,
199 const void *threshold);
200
201
202
203 extern bool gl_oset_iterator_next (gl_oset_iterator_t *iterator,
204 const void **eltp);
205
206
207 extern void gl_oset_iterator_free (gl_oset_iterator_t *iterator);
208
209 #endif
210
211
212
213 struct gl_oset_implementation
214 {
215
216 gl_oset_t (*nx_create_empty) (gl_oset_implementation_t implementation,
217 gl_setelement_compar_fn compar_fn,
218 gl_setelement_dispose_fn dispose_fn);
219 size_t (*size) (gl_oset_t set);
220 bool (*search) (gl_oset_t set, const void *elt);
221 bool (*search_atleast) (gl_oset_t set,
222 gl_setelement_threshold_fn threshold_fn,
223 const void *threshold, const void **eltp);
224 int (*nx_add) (gl_oset_t set, const void *elt);
225 bool (*remove_elt) (gl_oset_t set, const void *elt);
226 int (*update) (gl_oset_t set, const void *elt,
227 void (*action) (const void * , void * ),
228 void *action_data);
229 void (*oset_free) (gl_oset_t set);
230
231 gl_oset_iterator_t (*iterator) (gl_oset_t set);
232 gl_oset_iterator_t (*iterator_atleast) (gl_oset_t set,
233 gl_setelement_threshold_fn threshold_fn,
234 const void *threshold);
235 bool (*iterator_next) (gl_oset_iterator_t *iterator, const void **eltp);
236 void (*iterator_free) (gl_oset_iterator_t *iterator);
237 };
238
239 struct gl_oset_impl_base
240 {
241 const struct gl_oset_implementation *vtable;
242 gl_setelement_compar_fn compar_fn;
243 gl_setelement_dispose_fn dispose_fn;
244 };
245
246
247
248
249 GL_OSET_INLINE
250
251 gl_oset_t
252 gl_oset_nx_create_empty (gl_oset_implementation_t implementation,
253 gl_setelement_compar_fn compar_fn,
254 gl_setelement_dispose_fn dispose_fn)
255 {
256 return implementation->nx_create_empty (implementation, compar_fn,
257 dispose_fn);
258 }
259
260 GL_OSET_INLINE size_t
261 gl_oset_size (gl_oset_t set)
262 {
263 return ((const struct gl_oset_impl_base *) set)->vtable->size (set);
264 }
265
266 GL_OSET_INLINE bool
267 gl_oset_search (gl_oset_t set, const void *elt)
268 {
269 return ((const struct gl_oset_impl_base *) set)->vtable->search (set, elt);
270 }
271
272 GL_OSET_INLINE bool
273 gl_oset_search_atleast (gl_oset_t set,
274 gl_setelement_threshold_fn threshold_fn,
275 const void *threshold, const void **eltp)
276 {
277 return ((const struct gl_oset_impl_base *) set)->vtable
278 ->search_atleast (set, threshold_fn, threshold, eltp);
279 }
280
281 _GL_ATTRIBUTE_NODISCARD GL_OSET_INLINE int
282 gl_oset_nx_add (gl_oset_t set, const void *elt)
283 {
284 return ((const struct gl_oset_impl_base *) set)->vtable->nx_add (set, elt);
285 }
286
287 GL_OSET_INLINE bool
288 gl_oset_remove (gl_oset_t set, const void *elt)
289 {
290 return ((const struct gl_oset_impl_base *) set)->vtable
291 ->remove_elt (set, elt);
292 }
293
294 GL_OSET_INLINE int
295 gl_oset_update (gl_oset_t set, const void *elt,
296 void (*action) (const void * , void * ),
297 void *action_data)
298 {
299 return ((const struct gl_oset_impl_base *) set)->vtable
300 ->update (set, elt, action, action_data);
301 }
302
303 GL_OSET_INLINE void
304 gl_oset_free (gl_oset_t set)
305 {
306 ((const struct gl_oset_impl_base *) set)->vtable->oset_free (set);
307 }
308
309 GL_OSET_INLINE gl_oset_iterator_t
310 gl_oset_iterator (gl_oset_t set)
311 {
312 return ((const struct gl_oset_impl_base *) set)->vtable->iterator (set);
313 }
314
315 GL_OSET_INLINE gl_oset_iterator_t
316 gl_oset_iterator_atleast (gl_oset_t set,
317 gl_setelement_threshold_fn threshold_fn,
318 const void *threshold)
319 {
320 return ((const struct gl_oset_impl_base *) set)->vtable
321 ->iterator_atleast (set, threshold_fn, threshold);
322 }
323
324 GL_OSET_INLINE bool
325 gl_oset_iterator_next (gl_oset_iterator_t *iterator, const void **eltp)
326 {
327 return iterator->vtable->iterator_next (iterator, eltp);
328 }
329
330 GL_OSET_INLINE void
331 gl_oset_iterator_free (gl_oset_iterator_t *iterator)
332 {
333 iterator->vtable->iterator_free (iterator);
334 }
335
336 #ifdef __cplusplus
337 }
338 #endif
339
340 _GL_INLINE_HEADER_END
341
342 #endif