]>
Commit | Line | Data |
---|---|---|
1d8fe1f7 MR |
1 | #ifndef _HASHTABLE_H_ |
2 | #define _HASHTABLE_H_ | |
3 | ||
4 | #include <stdint.h> | |
5 | #include <stdbool.h> | |
6 | #include <stddef.h> | |
7 | ||
8 | #define TABLESIZE (1<<20) | |
9 | ||
10 | typedef uint64_t (*HashFunc)(const void*); | |
11 | typedef bool (*EqualFunc)(const void*, const void*); | |
8c5be416 | 12 | typedef void (*FreeFunc)(void*); |
f3e1ef9f | 13 | typedef void (*PrintFunc)(void*); |
1d8fe1f7 | 14 | typedef struct _Hashtable Hashtable; |
8c5be416 MR |
15 | typedef void (*ForeachFunc)(void*, void*, void*); |
16 | ||
17 | typedef struct _HashtableIter { | |
18 | /* Private */ | |
19 | void* dummy1; | |
20 | void* dummy2; | |
21 | void* dummy3; | |
22 | int64_t dummy4; | |
23 | } HashtableIter; | |
24 | ||
25 | ||
26 | typedef struct _List { | |
27 | void* data; | |
28 | struct _List* next; | |
29 | } List; | |
30 | ||
1d8fe1f7 MR |
31 | |
32 | uint64_t int_hash(const void*); | |
33 | uint64_t str_hash(const void*); | |
34 | uint64_t ptr_hash(const void*); | |
35 | bool int_equal(const void*, const void*); | |
36 | bool str_equal(const void*, const void*); | |
37 | bool ptr_equal(const void*, const void*); | |
38 | ||
39 | Hashtable* hash_table_create(HashFunc hf, EqualFunc ef); | |
8c5be416 | 40 | Hashtable* hash_table_create_notify(HashFunc hf, EqualFunc ef, FreeFunc ff); |
f3e1ef9f | 41 | Hashtable* hash_table_create_full(HashFunc hf, EqualFunc ef, uint32_t size, FreeFunc ff, PrintFunc pf); |
1d8fe1f7 MR |
42 | void hash_table_destroy(Hashtable* ht); |
43 | void hash_table_print(Hashtable* ht); | |
44 | bool hash_table_insert(Hashtable* ht, const void* key, void* obj); | |
45 | void* hash_table_lookup(Hashtable* ht, const void* key); | |
46 | void* hash_table_delete(Hashtable* ht, const void* key); | |
8c5be416 MR |
47 | List* hash_table_keys(Hashtable* ht); |
48 | List* hash_table_values(Hashtable* ht); | |
49 | void hash_table_list_free(List* list); | |
50 | void hash_table_foreach(Hashtable* ht, ForeachFunc, void* userdata); | |
51 | void hash_table_iter_init(HashtableIter* iter, Hashtable* ht); | |
52 | bool hash_table_iter_next(HashtableIter* iter, void** key, void** value); | |
dd3da95a MR |
53 | bool hash_table_contains(Hashtable* ht, const void* key); |
54 | uint64_t hash_table_size(Hashtable* ht); | |
55 | bool hash_table_replace(Hashtable* ht, void* key, void* value); | |
f3e1ef9f | 56 | void hash_table_set_print_func(Hashtable* ht, PrintFunc pf); |
1d8fe1f7 MR |
57 | |
58 | #endif | |
59 |