]>
Commit | Line | Data |
---|---|---|
60918275 LP |
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); | |
91cdde8a | 17 | void set_free(Set* s); |
034c6ed7 LP |
18 | Set* set_copy(Set *s); |
19 | int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func); | |
60918275 LP |
20 | |
21 | int set_put(Set *s, void *value); | |
f00b3eda | 22 | int set_replace(Set *s, void *value); |
60918275 LP |
23 | void *set_get(Set *s, void *value); |
24 | void *set_remove(Set *s, void *value); | |
25 | ||
91cdde8a LP |
26 | int set_merge(Set *s, Set *other); |
27 | ||
60918275 LP |
28 | unsigned set_size(Set *s); |
29 | bool set_isempty(Set *s); | |
30 | ||
034c6ed7 LP |
31 | void *set_iterate(Set *s, Iterator *i); |
32 | void *set_iterate_backwards(Set *s, Iterator *i); | |
33 | void *set_iterate_skip(Set *s, void *value, Iterator *i); | |
60918275 | 34 | |
11dd41ce | 35 | void set_clear(Set *s); |
91cdde8a LP |
36 | void *set_steal_first(Set *s); |
37 | void* set_first(Set *s); | |
38 | void* set_last(Set *s); | |
60918275 | 39 | |
034c6ed7 LP |
40 | #define SET_FOREACH(e, s, i) \ |
41 | for ((i) = ITERATOR_FIRST, (e) = set_iterate((s), &(i)); (e); (e) = set_iterate((s), &(i))) | |
60918275 | 42 | |
034c6ed7 LP |
43 | #define SET_FOREACH_BACKWARDS(e, s, i) \ |
44 | for ((i) = ITERATOR_LAST, (e) = set_iterate_backwards((s), &(i)); (e); (e) = set_iterate_backwards((s), &(i))) | |
60918275 LP |
45 | |
46 | #endif |