chiark / gitweb /
util: add parsers for boolean and integers
[elogind.git] / set.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef foosethfoo
4 #define foosethfoo
5
6 /* Pretty straightforward set implementation. Internally based on the
7  * hashmap. That means that as a minor optimization a NULL set
8  * object will be treated as empty set for all read
9  * operations. That way it is not necessary to instantiate an object
10  * for each set use. */
11
12 #include "hashmap.h"
13
14 typedef struct Set Set;
15
16 Set *set_new(hash_func_t hash_func, compare_func_t compare_func);
17 void set_free(Set* set);
18
19 int set_put(Set *s, void *value);
20 void *set_get(Set *s, void *value);
21 void *set_remove(Set *s, void *value);
22
23 unsigned set_size(Set *s);
24 bool set_isempty(Set *s);
25
26 void *set_iterate(Set *h, void **state);
27 void *set_iterate_backwards(Set *h, void **state);
28
29 void *set_steal_first(Set *h);
30 void* set_first(Set *h);
31 void* set_last(Set *h);
32
33 #define SET_FOREACH(e, s, state) \
34         for ((state) = NULL, (e) = set_iterate((s), &(state)); (e); (e) = set_iterate((s), &(state)))
35
36 #define SET_FOREACH_BACKWARDS(e, s, state) \
37         for ((state) = NULL, (e) = set_iterate_backwards((s), &(state)); (e); (e) = set_iterate_backwards((s), &(state)))
38
39 #endif