diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-28 01:27:24 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-28 01:27:24 +0300 |
commit | bf330c19cd3813da8a9c0ae4f48316747f3fa93a (patch) | |
tree | 653e78e541412ff2bdd3a29a2950d4d1ae5be756 /src/hashmap.h | |
parent | 282914669483405a34000ed24b541201f8d29c4b (diff) | |
download | unja-bf330c19cd3813da8a9c0ae4f48316747f3fa93a.tar.gz unja-bf330c19cd3813da8a9c0ae4f48316747f3fa93a.zip |
hashmap: hashma_destroyrevela
Added function to free all of a hashmap's content before freeing the
hashmap's own memory.
Diffstat (limited to 'src/hashmap.h')
-rw-r--r-- | src/hashmap.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/hashmap.h b/src/hashmap.h index 981c21b..52df625 100644 --- a/src/hashmap.h +++ b/src/hashmap.h @@ -19,6 +19,8 @@ #define HASHMAP_GROW_RATE 2 #endif +typedef void (hashmap_cb)(const void *key, void *value); + struct hashmap { struct node **buckets; size_t init_cap; @@ -49,9 +51,13 @@ void *hashmap_resolve(struct hashmap *hm, const char *key); */ void *hashmap_remove(struct hashmap *hm, const char *key); +/* Iterate over keys in the hashmap */ +void hashmap_walk(struct hashmap *hm, hashmap_cb); + +/* free hashmap related memory calling a function before freeing each node */ +void hashmap_destroy(struct hashmap *hm, hashmap_cb cb); + /* free hashmap related memory */ void hashmap_free(struct hashmap *hm); -void hashmap_walk(struct hashmap *hm, void (*fn)(const void *key, void *value)); - #endif |