]> begriffs open source - libderp/blob - include/hashmap.h
Hashmap iterator
[libderp] / include / hashmap.h
1 #ifndef LIBDERP_HASHMAP_H
2 #define LIBDERP_HASHMAP_H
3
4 #include "common.h"
5 #include "list.h"
6
7 #include <stdbool.h>
8 #include <stddef.h>
9
10 /* for public consumption */
11 struct hm_pair
12 {
13         void *k;
14         void *v;
15 };
16
17 typedef struct hashmap hashmap;
18
19 /* don't look inside, clients */
20 typedef struct hm_iter
21 {
22         hashmap *h;
23         size_t bucket;
24         list_item *offset;
25 } hm_iter;
26
27 hashmap * hm_new(size_t, hashfn *, comparator *, void *cmp_aux);
28 void      hm_free(hashmap *);
29 void      hm_dtor(hashmap *, dtor *key_dtor, dtor *val_dtor, void *aux);
30 size_t    hm_length(const hashmap *);
31 bool      hm_is_empty(const hashmap *);
32 void *    hm_at(const hashmap *, const void *);
33 bool      hm_insert(hashmap *, void *key, void *val);
34 bool      hm_remove(hashmap *, void *);
35 void      hm_clear(hashmap *);
36
37 bool            hm_iter_begin(hashmap *h, hm_iter *i);
38 struct hm_pair* hm_iter_next(hm_iter *);
39
40 #endif