1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
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. */
14 typedef struct Set Set
;
16 Set
*set_new(hash_func_t hash_func
, compare_func_t compare_func
);
17 Set
* set_copy(Set
*s
);
18 void set_free(Set
* s
);
20 int set_put(Set
*s
, void *value
);
21 int set_replace(Set
*s
, void *value
);
22 void *set_get(Set
*s
, void *value
);
23 void *set_remove(Set
*s
, void *value
);
25 int set_merge(Set
*s
, Set
*other
);
27 unsigned set_size(Set
*s
);
28 bool set_isempty(Set
*s
);
30 void *set_iterate(Set
*s
, void **state
);
31 void *set_iterate_backwards(Set
*s
, void **state
);
33 void set_clear(Set
*s
);
34 void *set_steal_first(Set
*s
);
35 void* set_first(Set
*s
);
36 void* set_last(Set
*s
);
38 #define SET_FOREACH(e, s, state) \
39 for ((state) = NULL, (e) = set_iterate((s), &(state)); (e); (e) = set_iterate((s), &(state)))
41 #define SET_FOREACH_BACKWARDS(e, s, state) \
42 for ((state) = NULL, (e) = set_iterate_backwards((s), &(state)); (e); (e) = set_iterate_backwards((s), &(state)))