]> git.datanom.net - hashtable.git/blob - hashtable.h
almost complete
[hashtable.git] / hashtable.h
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*);
12 typedef void (*FreeFunc)(void*);
13 typedef struct _Hashtable Hashtable;
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
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);
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);
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);
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);
52
53 #endif
54
This page took 0.059685 seconds and 6 git commands to generate.