1 #ifndef HASHMAP_H 2 # define HASHMAP_H 3 4 # include <stdlib.h> 5 # include <stdint.h> 6 7 struct hashmap { 8 uint32_t size; 9 uint32_t(*hash)(const void *key); 10 void(*free)(void*); 11 struct hashmap_entry *first; 12 struct hashmap_entry *last; 13 struct hashmap_entry { 14 void *data; 15 const void *key; 16 struct hashmap_entry *next; 17 struct hashmap_entry *list_next; 18 struct hashmap_entry *list_prev; 19 } *entries[0]; 20 }; 21 22 struct hashmap *hashmap_create(uint32_t(*hash_fct)(const void*), 23 void(*free_fct)(void*), size_t size); 24 void hashmap_add(struct hashmap *h, void *data, const void *key); 25 void *hashmap_lookup(struct hashmap *h, const void *key); 26 void *hashmap_iter_in_order(struct hashmap *h, struct hashmap_entry **it); 27 void hashmap_del(struct hashmap *h, struct hashmap_entry *e); 28 void hashmap_free(struct hashmap *h); 29 30 uint32_t djb2_hash(const void *str); 31 32 #endif /* !HASHMAP_H */ 33