Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

Viewing file on branch master

1#ifndef HASHMAP_H
2#define HASHMAP_H
3
4#include <stdint.h>
5#include <stddef.h>
6
7
8// collision list
9struct hashmap_col_list {
10 struct hashmap_col_list * next;
11 struct hashmap_col_list * prev;
12
13 unsigned long hash;
14 char * key;
15 void * val;
16};
17
18
19struct hashmap_bucket {
20 struct hashmap_col_list * entries;
21 struct hashmap_col_list * last;
22};
23
24
25typedef struct {
26 void (*destroyer)(void*);
27 struct hashmap_bucket ** buckets;
28 size_t len; // total entries
29 size_t max;
30} hashmap;
31
32
33typedef struct {
34 size_t curbuck;
35 struct hashmap_col_list * col;
36
37 char * key;
38 void * val;
39} hashmap_walk_state;
40
41
42hashmap * hashmap_new(void (*destroyer)(void*));
43void hashmap_insert(hashmap *, char *, void *);
44void * hashmap_get(const hashmap *, const char *);
45void hashmap_remove(hashmap *, char *);
46int hashmap_walk(hashmap *, hashmap_walk_state *);
47void hashmap_destroy(hashmap *);
48
49#endif /* HASHMAP_H */
50