aboutsummaryrefslogtreecommitdiff
path: root/include/hashmap.h
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2025-05-22 15:16:40 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2025-05-22 15:16:40 +0200
commit987a7c553701251d48b11a2243892ecd74ce6c4d (patch)
tree92ba268dc32b33724fbb05b6500af7288dac9617 /include/hashmap.h
parent056adf22dcbeacbbd64623961f2b8825420f90c5 (diff)
downloadimp-987a7c553701251d48b11a2243892ecd74ce6c4d.tar.gz
imp-987a7c553701251d48b11a2243892ecd74ce6c4d.zip
[doc] added documentation in ast and hashmap headers
Diffstat (limited to 'include/hashmap.h')
-rw-r--r--include/hashmap.h44
1 files changed, 42 insertions, 2 deletions
diff --git a/include/hashmap.h b/include/hashmap.h
index 5273497..57ebafe 100644
--- a/include/hashmap.h
+++ b/include/hashmap.h
@@ -1,21 +1,61 @@
#ifndef HASHMAP_H
#define HASHMAP_H
-
+/* Hashmap Handle */
typedef struct HashMap *hashmap_t;
+/* Hashmap Key Iterator Handle */
typedef struct HashMapKeysIter *hashmap_keys_iter_t;
-
+/*
+ Creates hashmap that maps char* to void*.
+ Keys are copied, and will be freed when the hashmap is freed.
+ Elements are not copied, and must be freed by the caller.
+ Caller is responsible for freeing the hashmap using hashmap_free.
+*/
hashmap_t hashmap_create(void);
+
+/*
+ Frees the hashmap and all keys.
+ Elements are not freed, and must be freed by the caller.
+*/
void hashmap_free(hashmap_t map);
+/*
+ Looks up element with given key.
+ Returns pointer to element, or NULL if not found.
+*/
void **hashmap_get(hashmap_t map, const char *key);
+
+/*
+ Inserts element with given key.
+ If key already exists, the old element is replaced (caller is responsible for freeing beforehand).
+*/
void hashmap_insert(hashmap_t map, const char *key, void *value);
+
+/*
+ Deletes element with given key.
+ Caller is responsible for freeing the element.
+ Returns 0 on success, -1 when not found.
+*/
int hashmap_delete(hashmap_t map, const char *key);
+
+/*
+ Creates iterator for keys.
+ Caller is responsible for freeing the iterator using hashmap_keys_iter_free.
+ Iterator is invalid when the hashmap is modified and must be freed.
+*/
hashmap_keys_iter_t hashmap_keys_iter_create(hashmap_t map);
+
+/*
+ Returns next key in the iterator.
+ Returns NULL when there are no more keys.
+ Keys are not copied, and must not be freed.
+*/
const char *hashmap_keys_iter_next(hashmap_keys_iter_t iter);
+
+/* Frees the iterator. */
void hashmap_keys_iter_free(hashmap_keys_iter_t iter);