This source file includes following definitions.
- gl_set_create_empty
- gl_set_nx_create_empty
- gl_set_size
- gl_set_search
- gl_set_nx_add
- gl_set_remove
- gl_set_free
- gl_set_iterator
- gl_set_iterator_next
- gl_set_iterator_free
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef _GL_SET_H
19 #define _GL_SET_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_SET_INLINE
29 # define GL_SET_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 typedef bool (*gl_setelement_equals_fn) (const void *elt1, const void *elt2);
78
79
80
81 typedef size_t (*gl_setelement_hashcode_fn) (const void *elt);
82
83 #ifndef _GL_SETELEMENT_DISPOSE_FN_DEFINED
84
85
86 typedef void (*gl_setelement_dispose_fn) (const void *elt);
87 # define _GL_SETELEMENT_DISPOSE_FN_DEFINED 1
88 #endif
89
90 struct gl_set_impl;
91
92 typedef struct gl_set_impl * gl_set_t;
93
94 struct gl_set_implementation;
95
96 typedef const struct gl_set_implementation * gl_set_implementation_t;
97
98 #if 0
99
100
101
102
103
104
105
106 extern gl_set_t gl_set_create_empty (gl_set_implementation_t implementation,
107 gl_setelement_equals_fn equals_fn,
108 gl_setelement_hashcode_fn hashcode_fn,
109 gl_setelement_dispose_fn dispose_fn)
110
111 _GL_ATTRIBUTE_RETURNS_NONNULL;
112
113 extern gl_set_t gl_set_nx_create_empty (gl_set_implementation_t implementation,
114 gl_setelement_equals_fn equals_fn,
115 gl_setelement_hashcode_fn hashcode_fn,
116 gl_setelement_dispose_fn dispose_fn)
117 ;
118
119
120 extern size_t gl_set_size (gl_set_t set);
121
122
123
124 extern bool gl_set_search (gl_set_t set, const void *elt);
125
126
127
128
129 extern bool gl_set_add (gl_set_t set, const void *elt);
130
131
132 _GL_ATTRIBUTE_NODISCARD
133 extern int gl_set_nx_add (gl_set_t set, const void *elt);
134
135
136
137 extern bool gl_set_remove (gl_set_t set, const void *elt);
138
139
140
141
142 extern void gl_set_free (gl_set_t set);
143
144 #endif
145
146
147
148
149
150
151
152
153
154
155
156 typedef struct
157 {
158
159 const struct gl_set_implementation *vtable;
160
161 gl_set_t set;
162 size_t count;
163
164 void *p; void *q;
165 size_t i; size_t j;
166 } gl_set_iterator_t;
167
168 #if 0
169
170
171
172
173 extern gl_set_iterator_t gl_set_iterator (gl_set_t set);
174
175
176
177 extern bool gl_set_iterator_next (gl_set_iterator_t *iterator,
178 const void **eltp);
179
180
181 extern void gl_set_iterator_free (gl_set_iterator_t *iterator);
182
183 #endif
184
185
186
187 struct gl_set_implementation
188 {
189
190 gl_set_t (*nx_create_empty) (gl_set_implementation_t implementation,
191 gl_setelement_equals_fn equals_fn,
192 gl_setelement_hashcode_fn hashcode_fn,
193 gl_setelement_dispose_fn dispose_fn);
194 size_t (*size) (gl_set_t set);
195 bool (*search) (gl_set_t set, const void *elt);
196 int (*nx_add) (gl_set_t set, const void *elt);
197 bool (*remove_elt) (gl_set_t set, const void *elt);
198 void (*set_free) (gl_set_t set);
199
200 gl_set_iterator_t (*iterator) (gl_set_t set);
201 bool (*iterator_next) (gl_set_iterator_t *iterator, const void **eltp);
202 void (*iterator_free) (gl_set_iterator_t *iterator);
203 };
204
205 struct gl_set_impl_base
206 {
207 const struct gl_set_implementation *vtable;
208 gl_setelement_equals_fn equals_fn;
209 gl_setelement_dispose_fn dispose_fn;
210 };
211
212
213
214
215 GL_SET_INLINE
216
217 gl_set_t
218 gl_set_nx_create_empty (gl_set_implementation_t implementation,
219 gl_setelement_equals_fn equals_fn,
220 gl_setelement_hashcode_fn hashcode_fn,
221 gl_setelement_dispose_fn dispose_fn)
222 {
223 return implementation->nx_create_empty (implementation, equals_fn,
224 hashcode_fn, dispose_fn);
225 }
226
227 GL_SET_INLINE size_t
228 gl_set_size (gl_set_t set)
229 {
230 return ((const struct gl_set_impl_base *) set)->vtable->size (set);
231 }
232
233 GL_SET_INLINE bool
234 gl_set_search (gl_set_t set, const void *elt)
235 {
236 return ((const struct gl_set_impl_base *) set)->vtable->search (set, elt);
237 }
238
239 _GL_ATTRIBUTE_NODISCARD GL_SET_INLINE int
240 gl_set_nx_add (gl_set_t set, const void *elt)
241 {
242 return ((const struct gl_set_impl_base *) set)->vtable->nx_add (set, elt);
243 }
244
245 GL_SET_INLINE bool
246 gl_set_remove (gl_set_t set, const void *elt)
247 {
248 return ((const struct gl_set_impl_base *) set)->vtable->remove_elt (set, elt);
249 }
250
251 GL_SET_INLINE void
252 gl_set_free (gl_set_t set)
253 {
254 ((const struct gl_set_impl_base *) set)->vtable->set_free (set);
255 }
256
257 GL_SET_INLINE gl_set_iterator_t
258 gl_set_iterator (gl_set_t set)
259 {
260 return ((const struct gl_set_impl_base *) set)->vtable->iterator (set);
261 }
262
263 GL_SET_INLINE bool
264 gl_set_iterator_next (gl_set_iterator_t *iterator, const void **eltp)
265 {
266 return iterator->vtable->iterator_next (iterator, eltp);
267 }
268
269 GL_SET_INLINE void
270 gl_set_iterator_free (gl_set_iterator_t *iterator)
271 {
272 iterator->vtable->iterator_free (iterator);
273 }
274
275 #ifdef __cplusplus
276 }
277 #endif
278
279 _GL_INLINE_HEADER_END
280
281 #endif