blob: 6ef27bad92cef51447eea796a185c04cc303ddd8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#ifndef HAMT_H
#define HAMT_H
#include <stdint.h>
typedef struct hamt *hamt_t;
// tagged pointer to either
// hamt_item or hamt_nodelist
typedef uintptr_t hamtptr_t;
struct hamt_item {
uint32_t refs;
void *key;
void *data;
struct hamt_item *next;
};
struct hamt_nodelist {
uint32_t refs;
uint64_t bitmask;
hamtptr_t *list;
};
typedef int (*hamt_equal_fn)(void *key1, void *key2);
typedef uint32_t (*hamt_hash_fn)(void *key);
struct hamt {
hamt_equal_fn equal_fn;
hamt_hash_fn hash_fn;
hamtptr_t root;
};
hamt_t hamt_create(hamt_equal_fn equal_fn, hamt_hash_fn hash_fn);
void hamt_destroy(hamt_t hamt);
hamt_t hamt_clone(hamt_t src);
int hamt_get(hamt_t hamt, void *key, void **data);
int hamt_set(hamt_t hamt, void *key, void *data, void **keyptr, void **prevdata);
#endif
|