]> git.ipfire.org Git - thirdparty/systemd.git/blame - set.h
implement hashmap_replace() and hashmap_remove_value()
[thirdparty/systemd.git] / set.h
CommitLineData
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
14typedef struct Set Set;
15
16Set *set_new(hash_func_t hash_func, compare_func_t compare_func);
91cdde8a
LP
17Set* set_copy(Set *s);
18void set_free(Set* s);
60918275
LP
19
20int set_put(Set *s, void *value);
21void *set_get(Set *s, void *value);
22void *set_remove(Set *s, void *value);
23
91cdde8a
LP
24int set_merge(Set *s, Set *other);
25
60918275
LP
26unsigned set_size(Set *s);
27bool set_isempty(Set *s);
28
91cdde8a
LP
29void *set_iterate(Set *s, void **state);
30void *set_iterate_backwards(Set *s, void **state);
60918275 31
11dd41ce 32void set_clear(Set *s);
91cdde8a
LP
33void *set_steal_first(Set *s);
34void* set_first(Set *s);
35void* set_last(Set *s);
60918275
LP
36
37#define SET_FOREACH(e, s, state) \
38 for ((state) = NULL, (e) = set_iterate((s), &(state)); (e); (e) = set_iterate((s), &(state)))
39
40#define SET_FOREACH_BACKWARDS(e, s, state) \
41 for ((state) = NULL, (e) = set_iterate_backwards((s), &(state)); (e); (e) = set_iterate_backwards((s), &(state)))
42
43#endif