This source file includes following definitions.
- gl_omap_create_empty
- gl_omap_nx_create_empty
- gl_omap_size
- gl_omap_search
- gl_omap_search_atleast
- gl_omap_nx_getput
- gl_omap_getremove
- gl_omap_free
- gl_omap_iterator
- gl_omap_iterator_next
- gl_omap_iterator_free
- gl_omap_get
- gl_omap_nx_put
- gl_omap_remove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef _GL_OMAP_H
19 #define _GL_OMAP_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_OMAP_INLINE
29 # define GL_OMAP_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
81
82 typedef int (*gl_mapkey_compar_fn) (const void *key1, const void *key2);
83
84 #ifndef _GL_MAP_DISPOSE_FNS_DEFINED
85
86
87
88 typedef void (*gl_mapkey_dispose_fn) (const void *key);
89
90
91
92 typedef void (*gl_mapvalue_dispose_fn) (const void *value);
93
94 # define _GL_MAP_DISPOSE_FNS_DEFINED 1
95 #endif
96
97
98
99 typedef bool (*gl_mapkey_threshold_fn) (const void *key, const void *threshold);
100
101 struct gl_omap_impl;
102
103 typedef struct gl_omap_impl * gl_omap_t;
104
105 struct gl_omap_implementation;
106
107 typedef const struct gl_omap_implementation * gl_omap_implementation_t;
108
109 #if 0
110
111
112
113
114
115
116
117 extern gl_omap_t gl_omap_create_empty (gl_omap_implementation_t implementation,
118 gl_mapkey_compar_fn compar_fn,
119 gl_mapkey_dispose_fn kdispose_fn,
120 gl_mapvalue_dispose_fn vdispose_fn)
121
122 _GL_ATTRIBUTE_RETURNS_NONNULL;
123
124 extern gl_omap_t gl_omap_nx_create_empty (gl_omap_implementation_t implementation,
125 gl_mapkey_compar_fn compar_fn,
126 gl_mapkey_dispose_fn kdispose_fn,
127 gl_mapvalue_dispose_fn vdispose_fn)
128 ;
129
130
131 extern size_t gl_omap_size (gl_omap_t map);
132
133
134
135 extern const void * gl_omap_get (gl_omap_t map, const void *key);
136
137
138
139
140 extern bool gl_omap_search (gl_omap_t map, const void *key,
141 const void **valuep);
142
143
144
145
146
147
148 extern bool gl_omap_search_atleast (gl_omap_t map,
149 gl_mapkey_threshold_fn threshold_fn,
150 const void *threshold,
151 const void **keyp, const void **valuep);
152
153
154
155
156
157
158
159 extern bool gl_omap_put (gl_omap_t map, const void *key, const void *value);
160
161 _GL_ATTRIBUTE_NODISCARD
162 extern int gl_omap_nx_put (gl_omap_t map, const void *key, const void *value);
163
164
165
166
167
168
169
170 extern bool gl_omap_getput (gl_omap_t map, const void *key, const void *value,
171 const void **oldvaluep);
172
173 _GL_ATTRIBUTE_NODISCARD
174 extern int gl_omap_nx_getput (gl_omap_t map, const void *key, const void *value,
175 const void **oldvaluep);
176
177
178
179
180 extern bool gl_omap_remove (gl_omap_t map, const void *key);
181
182
183
184
185
186 extern bool gl_omap_getremove (gl_omap_t map, const void *key,
187 const void **oldvaluep);
188
189
190
191
192
193 extern void gl_omap_free (gl_omap_t map);
194
195 #endif
196
197
198
199
200
201
202
203
204 typedef struct
205 {
206
207 const struct gl_omap_implementation *vtable;
208
209 gl_omap_t map;
210 size_t count;
211
212 void *p; void *q;
213 size_t i; size_t j;
214 } gl_omap_iterator_t;
215
216 #if 0
217
218
219
220
221
222 extern gl_omap_iterator_t gl_omap_iterator (gl_omap_t map);
223
224
225
226 extern bool gl_omap_iterator_next (gl_omap_iterator_t *iterator,
227 const void **keyp, const void **valuep);
228
229
230 extern void gl_omap_iterator_free (gl_omap_iterator_t *iterator);
231
232 #endif
233
234
235
236 struct gl_omap_implementation
237 {
238
239 gl_omap_t (*nx_create_empty) (gl_omap_implementation_t implementation,
240 gl_mapkey_compar_fn compar_fn,
241 gl_mapkey_dispose_fn kdispose_fn,
242 gl_mapvalue_dispose_fn vdispose_fn);
243 size_t (*size) (gl_omap_t map);
244 bool (*search) (gl_omap_t map, const void *key, const void **valuep);
245 bool (*search_atleast) (gl_omap_t map,
246 gl_mapkey_threshold_fn threshold_fn,
247 const void *threshold,
248 const void **keyp, const void **valuep);
249 int (*nx_getput) (gl_omap_t map, const void *key, const void *value,
250 const void **oldvaluep);
251 bool (*getremove) (gl_omap_t map, const void *key, const void **oldvaluep);
252 void (*omap_free) (gl_omap_t map);
253
254 gl_omap_iterator_t (*iterator) (gl_omap_t map);
255 bool (*iterator_next) (gl_omap_iterator_t *iterator,
256 const void **keyp, const void **valuep);
257 void (*iterator_free) (gl_omap_iterator_t *iterator);
258 };
259
260 struct gl_omap_impl_base
261 {
262 const struct gl_omap_implementation *vtable;
263 gl_mapkey_compar_fn compar_fn;
264 gl_mapkey_dispose_fn kdispose_fn;
265 gl_mapvalue_dispose_fn vdispose_fn;
266 };
267
268
269
270
271 GL_OMAP_INLINE
272
273 gl_omap_t
274 gl_omap_nx_create_empty (gl_omap_implementation_t implementation,
275 gl_mapkey_compar_fn compar_fn,
276 gl_mapkey_dispose_fn kdispose_fn,
277 gl_mapvalue_dispose_fn vdispose_fn)
278 {
279 return implementation->nx_create_empty (implementation, compar_fn,
280 kdispose_fn, vdispose_fn);
281 }
282
283 GL_OMAP_INLINE size_t
284 gl_omap_size (gl_omap_t map)
285 {
286 return ((const struct gl_omap_impl_base *) map)->vtable->size (map);
287 }
288
289 GL_OMAP_INLINE bool
290 gl_omap_search (gl_omap_t map, const void *key, const void **valuep)
291 {
292 return ((const struct gl_omap_impl_base *) map)->vtable
293 ->search (map, key, valuep);
294 }
295
296 GL_OMAP_INLINE bool
297 gl_omap_search_atleast (gl_omap_t map,
298 gl_mapkey_threshold_fn threshold_fn,
299 const void *threshold,
300 const void **keyp, const void **valuep)
301 {
302 return ((const struct gl_omap_impl_base *) map)->vtable
303 ->search_atleast (map, threshold_fn, threshold, keyp, valuep);
304 }
305
306 _GL_ATTRIBUTE_NODISCARD GL_OMAP_INLINE int
307 gl_omap_nx_getput (gl_omap_t map, const void *key, const void *value,
308 const void **oldvaluep)
309 {
310 return ((const struct gl_omap_impl_base *) map)->vtable
311 ->nx_getput (map, key, value, oldvaluep);
312 }
313
314 GL_OMAP_INLINE bool
315 gl_omap_getremove (gl_omap_t map, const void *key, const void **oldvaluep)
316 {
317 return ((const struct gl_omap_impl_base *) map)->vtable
318 ->getremove (map, key, oldvaluep);
319 }
320
321 GL_OMAP_INLINE void
322 gl_omap_free (gl_omap_t map)
323 {
324 ((const struct gl_omap_impl_base *) map)->vtable->omap_free (map);
325 }
326
327 GL_OMAP_INLINE gl_omap_iterator_t
328 gl_omap_iterator (gl_omap_t map)
329 {
330 return ((const struct gl_omap_impl_base *) map)->vtable->iterator (map);
331 }
332
333 GL_OMAP_INLINE bool
334 gl_omap_iterator_next (gl_omap_iterator_t *iterator,
335 const void **keyp, const void **valuep)
336 {
337 return iterator->vtable->iterator_next (iterator, keyp, valuep);
338 }
339
340 GL_OMAP_INLINE void
341 gl_omap_iterator_free (gl_omap_iterator_t *iterator)
342 {
343 iterator->vtable->iterator_free (iterator);
344 }
345
346
347
348
349 GL_OMAP_INLINE const void *
350 gl_omap_get (gl_omap_t map, const void *key)
351 {
352 const void *value = NULL;
353 gl_omap_search (map, key, &value);
354 return value;
355 }
356
357 _GL_ATTRIBUTE_NODISCARD GL_OMAP_INLINE int
358 gl_omap_nx_put (gl_omap_t map, const void *key, const void *value)
359 {
360 const void *oldvalue;
361 int result = gl_omap_nx_getput (map, key, value, &oldvalue);
362 if (result == 0)
363 {
364 gl_mapvalue_dispose_fn vdispose_fn =
365 ((const struct gl_omap_impl_base *) map)->vdispose_fn;
366 if (vdispose_fn != NULL)
367 vdispose_fn (oldvalue);
368 }
369 return result;
370 }
371
372 GL_OMAP_INLINE bool
373 gl_omap_remove (gl_omap_t map, const void *key)
374 {
375 const void *oldvalue;
376 bool result = gl_omap_getremove (map, key, &oldvalue);
377 if (result)
378 {
379 gl_mapvalue_dispose_fn vdispose_fn =
380 ((const struct gl_omap_impl_base *) map)->vdispose_fn;
381 if (vdispose_fn != NULL)
382 vdispose_fn (oldvalue);
383 }
384 return result;
385 }
386
387 #ifdef __cplusplus
388 }
389 #endif
390
391 _GL_INLINE_HEADER_END
392
393 #endif