diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-07 00:59:26 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-07 00:59:26 +0300 |
commit | 8a5405629f7dcbc2504ac55f57775180a011b846 (patch) | |
tree | d5009f3bce187a92386148b633b59787d6499244 /src/hashmap.c | |
parent | 33bdfde2be7e1c568d5e12ad1b27b7023dbd1b1b (diff) | |
download | unja-8a5405629f7dcbc2504ac55f57775180a011b846.tar.gz unja-8a5405629f7dcbc2504ac55f57775180a011b846.zip |
Fixes and improvements
* Fix heap corruption on buffer growth.
* Define as static functions that are not used outside a TU.
* Other minor changes.
Diffstat (limited to 'src/hashmap.c')
-rw-r--r-- | src/hashmap.c | 15 |
1 files changed, 2 insertions, 13 deletions
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) { |