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