]> git.ipfire.org Git - thirdparty/systemd.git/blame - hashmap.h
parse socket files properly
[thirdparty/systemd.git] / hashmap.h
CommitLineData
60918275
LP
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3#ifndef foohashmaphfoo
4#define foohashmaphfoo
5
6#include <stdbool.h>
7
8/* Pretty straightforward hash table implementation. As a minor
9 * optimization a NULL hashmap object will be treated as empty hashmap
10 * for all read operations. That way it is not necessary to
11 * instantiate an object for each Hashmap use. */
12
13typedef struct Hashmap Hashmap;
14
15typedef unsigned (*hash_func_t)(const void *p);
16typedef int (*compare_func_t)(const void *a, const void *b);
17
18unsigned string_hash_func(const void *p);
19int string_compare_func(const void *a, const void *b);
20
21unsigned trivial_hash_func(const void *p);
22int trivial_compare_func(const void *a, const void *b);
23
24Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func);
91cdde8a
LP
25void hashmap_free(Hashmap *h);
26Hashmap *hashmap_copy(Hashmap *h);
60918275
LP
27
28int hashmap_put(Hashmap *h, const void *key, void *value);
29void* hashmap_get(Hashmap *h, const void *key);
30void* hashmap_remove(Hashmap *h, const void *key);
31
91cdde8a
LP
32int hashmap_merge(Hashmap *h, Hashmap *other);
33
60918275
LP
34unsigned hashmap_size(Hashmap *h);
35bool hashmap_isempty(Hashmap *h);
36
37void *hashmap_iterate(Hashmap *h, void **state, const void **key);
38void *hashmap_iterate_backwards(Hashmap *h, void **state, const void **key);
39
40void *hashmap_steal_first(Hashmap *h);
41void* hashmap_first(Hashmap *h);
42void* hashmap_last(Hashmap *h);
43
44#define HASHMAP_FOREACH(e, h, state) \
45 for ((state) = NULL, (e) = hashmap_iterate((h), &(state), NULL); (e); (e) = hashmap_iterate((h), &(state), NULL))
46
47#define HASHMAP_FOREACH_BACKWARDS(e, h, state) \
48 for ((state) = NULL, (e) = hashmap_iterate_backwards((h), &(state), NULL); (e); (e) = hashmap_iterate_backwards((h), &(state), NULL))
49
50#endif