#ifndef _HASHTABLE_H_ #define _HASHTABLE_H_ #include #include #include #define TABLESIZE (1<<20) typedef uint64_t (*HashFunc)(const void*); typedef bool (*EqualFunc)(const void*, const void*); typedef void (*FreeFunc)(void*); typedef void (*PrintFunc)(void*); typedef struct _Hashtable Hashtable; typedef void (*ForeachFunc)(void*, void*, void*); typedef struct _HashtableIter { /* Private */ void* dummy1; void* dummy2; void* dummy3; int64_t dummy4; } HashtableIter; typedef struct _List { void* data; struct _List* next; } List; uint64_t int_hash(const void*); uint64_t str_hash(const void*); uint64_t ptr_hash(const void*); bool int_equal(const void*, const void*); bool str_equal(const void*, const void*); bool ptr_equal(const void*, const void*); Hashtable* hash_table_create(HashFunc hf, EqualFunc ef); Hashtable* hash_table_create_notify(HashFunc hf, EqualFunc ef, FreeFunc ff); Hashtable* hash_table_create_full(HashFunc hf, EqualFunc ef, uint32_t size, FreeFunc ff, PrintFunc pf); void hash_table_destroy(Hashtable* ht); void hash_table_print(Hashtable* ht); bool hash_table_insert(Hashtable* ht, const void* key, void* obj); void* hash_table_lookup(Hashtable* ht, const void* key); void* hash_table_delete(Hashtable* ht, const void* key); List* hash_table_keys(Hashtable* ht); List* hash_table_values(Hashtable* ht); void hash_table_list_free(List* list); void hash_table_foreach(Hashtable* ht, ForeachFunc, void* userdata); void hash_table_iter_init(HashtableIter* iter, Hashtable* ht); bool hash_table_iter_next(HashtableIter* iter, void** key, void** value); bool hash_table_contains(Hashtable* ht, const void* key); uint64_t hash_table_size(Hashtable* ht); bool hash_table_replace(Hashtable* ht, void* key, void* value); void hash_table_set_print_func(Hashtable* ht, PrintFunc pf); #endif