From 8a5405629f7dcbc2504ac55f57775180a011b846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Sun, 7 Nov 2021 00:59:26 +0300 Subject: Fixes and improvements * Fix heap corruption on buffer growth. * Define as static functions that are not used outside a TU. * Other minor changes. --- src/hashmap.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/hashmap.c') diff --git a/src/hashmap.c b/src/hashmap.c index fa9a295..2522907 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -117,10 +117,6 @@ hashmap_new_with_cap(size_t cap) return hm; } -/* - * Inserts a key-value pair into the map. Returns NULL if map did not have key, - * old value if it did. - */ void * hashmap_insert(struct hashmap *hm, const char *key, void *value) { @@ -148,7 +144,6 @@ hashmap_insert(struct hashmap *hm, const char *key, void *value) return NULL; } -/* Returns a pointer to the value corresponding to the key. */ void * hashmap_get(struct hashmap *hm, const char *key) { @@ -165,7 +160,6 @@ hashmap_get(struct hashmap *hm, const char *key) return NULL; } -/* Retrieve pointer to value by key, handles dot notation for nested hashmaps */ void * hashmap_resolve(struct hashmap *hm, const char *key) { @@ -192,10 +186,6 @@ hashmap_resolve(struct hashmap *hm, const char *key) return hm; } -/* - * Removes a key from the map, returning the value at the key if the key was - * previously in the map. - */ void * hashmap_remove(struct hashmap *hm, const char *key) { @@ -226,7 +216,7 @@ hashmap_remove(struct hashmap *hm, const char *key) } void -hashmap_walk(struct hashmap *hm, void (*fn)(void *value)) +hashmap_walk(struct hashmap *hm, void (*fn)(const void *key, void *value)) { struct node *node; struct node *next; @@ -235,13 +225,12 @@ hashmap_walk(struct hashmap *hm, void (*fn)(void *value)) node = hm->buckets[i]; while (node) { next = node->next; - fn(node->value); + fn(node->key, node->value); node = next; } } } -/* free hashmap related memory */ void hashmap_free(struct hashmap *hm) { -- cgit v1.2.3