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.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/hashmap.h') diff --git a/src/hashmap.h b/src/hashmap.h index 5a1e22d..981c21b 100644 --- a/src/hashmap.h +++ b/src/hashmap.h @@ -31,16 +31,27 @@ struct hashmap *hashmap_new_with_cap(size_t cap); #define hashmap_new() hashmap_new_with_cap(HASHMAP_CAP) +/* + * 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); +/* Returns a pointer to the value corresponding to the key. */ void *hashmap_get(struct hashmap *hm, const char *key); +/* Retrieve pointer to value by key, handles dot notation for nested hashmaps */ void *hashmap_resolve(struct hashmap *hm, const char *key); +/* + * 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); +/* free hashmap related memory */ void hashmap_free(struct hashmap *hm); -void hashmap_walk(struct hashmap *hm, void (*fn)(void *value)); +void hashmap_walk(struct hashmap *hm, void (*fn)(const void *key, void *value)); #endif -- cgit v1.2.3