aboutsummaryrefslogtreecommitdiff
path: root/src/hashmap.h
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-07 00:59:26 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-07 00:59:26 +0300
commit8a5405629f7dcbc2504ac55f57775180a011b846 (patch)
treed5009f3bce187a92386148b633b59787d6499244 /src/hashmap.h
parent33bdfde2be7e1c568d5e12ad1b27b7023dbd1b1b (diff)
downloadunja-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.h')
-rw-r--r--src/hashmap.h13
1 files changed, 12 insertions, 1 deletions
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