#ifndef UNJA_HASHMAP_H #define UNJA_HASHMAP_H #include #include #ifndef HASHMAP_CAP #define HASHMAP_CAP 32 #endif #ifndef HASHMAP_MIN_LOAD #define HASHMAP_MIN_LOAD 0.2 #endif #ifndef HASHMAP_MAX_LOAD #define HASHMAP_MAX_LOAD 0.75 #endif #ifndef HASHMAP_GROW_RATE #define HASHMAP_GROW_RATE 2 #endif struct hashmap { struct node **buckets; size_t init_cap; size_t cur_cap; size_t size; }; /* allocate a new hashmap */ struct hashmap *hashmap_new_with_cap(size_t cap); #define hashmap_new() hashmap_new_with_cap(HASHMAP_CAP) void *hashmap_insert(struct hashmap *hm, const char *key, void *value); void *hashmap_get(struct hashmap *hm, const char *key); void *hashmap_resolve(struct hashmap *hm, const char *key); void *hashmap_remove(struct hashmap *hm, const char *key); void hashmap_free(struct hashmap *hm); void hashmap_walk(struct hashmap *hm, void (*fn)(void *value)); #endif