diff options
author | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-03-13 15:22:12 +0100 |
---|---|---|
committer | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-03-13 15:22:12 +0100 |
commit | 8f48266d0b428fb627a67092105091b29a0ce038 (patch) | |
tree | 5149b3342e030a7e1f38b4f5cb550288acb24c1f /src/hashmap.c | |
parent | 679ab3947763cba53cd4d77743e0a497148b4bc5 (diff) | |
download | unja-8f48266d0b428fb627a67092105091b29a0ce038.tar.gz unja-8f48266d0b428fb627a67092105091b29a0ce038.zip |
maybe get ready fur custom parsing... still wrapping my head around the set-up
Diffstat (limited to 'src/hashmap.c')
-rw-r--r-- | src/hashmap.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/hashmap.c b/src/hashmap.c index 9f36a58..6797475 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -11,6 +11,7 @@ struct node { struct node *next; }; +/* allocate a new hashmap */ struct hashmap *hashmap_new() { struct hashmap *hm = malloc(sizeof *hm); if (!hm) err(EXIT_FAILURE, "out of memory"); @@ -21,6 +22,7 @@ struct hashmap *hashmap_new() { return hm; } +/* insert key-value into hashmap */ void hashmap_insert(struct hashmap *hm, char *key, void *value) { int pos = HASH(key); struct node *head = hm->buckets[pos]; @@ -41,6 +43,7 @@ void hashmap_insert(struct hashmap *hm, char *key, void *value) { hm->buckets[pos] = node; } +/* retrieve value by key */ void *hashmap_get(struct hashmap *hm, char *key) { int pos = HASH(key); struct node *node = hm->buckets[pos]; @@ -55,6 +58,7 @@ void *hashmap_get(struct hashmap *hm, char *key) { return NULL; } +/* retrieve value by key, handles dot notation for nested hashmaps */ void *hashmap_resolve(struct hashmap *hm, char *key) { char tmp_key[64]; int i = 0; @@ -83,6 +87,7 @@ void hashmap_remove(char *key) { // TODO: Implement this } +/* free hashmap related memory */ void hashmap_free(struct hashmap *hm) { struct node *node; struct node *next; |