aboutsummaryrefslogtreecommitdiff
path: root/hashmap.c
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-12 09:30:29 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-12 09:30:29 +0100
commitcd70ca266bb212d6a32d2dd808c7708bb7be6f1f (patch)
tree5cfe0289c5a964520dee96691561f8844023ad50 /hashmap.c
parentedf331cd2573726d8053ce76e3497203a12d99b9 (diff)
downloadunja-cd70ca266bb212d6a32d2dd808c7708bb7be6f1f.tar.gz
unja-cd70ca266bb212d6a32d2dd808c7708bb7be6f1f.zip
move files to src/ subdir
Diffstat (limited to 'hashmap.c')
-rw-r--r--hashmap.c74
1 files changed, 0 insertions, 74 deletions
diff --git a/hashmap.c b/hashmap.c
deleted file mode 100644
index 3d9edd0..0000000
--- a/hashmap.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <err.h>
-#include "hashmap.h"
-
-struct node {
- char *key;
- void *value;
- struct node *next;
-};
-
-struct hashmap *hashmap_new() {
- struct hashmap *hm = malloc(sizeof *hm);
- if (!hm) err(EXIT_FAILURE, "out of memory");
- for (int i=0; i < 26; i++) {
- hm->buckets[i] = NULL;
- }
-
- return hm;
-}
-
-void hashmap_insert(struct hashmap *hm, char *key, void *value) {
- int pos = (key[0] - 'a') % 26;
- struct node *head = hm->buckets[pos];
- struct node *node = head;
-
- while (node) {
- if (strcmp(node->key, key) == 0) {
- node->value = value;
- return;
- }
- node = node->next;
- }
-
- node = malloc(sizeof *node);
- node->key = key;
- node->value = value;
- node->next = head;
- hm->buckets[pos] = node;
-}
-
-void *hashmap_get(struct hashmap *hm, char *key) {
- int pos = (key[0] - 'a') % 26;
- struct node *node = hm->buckets[pos];
- while (node) {
- if (strcmp(node->key, key) == 0) {
- return node->value;
- }
-
- node = node->next;
- }
-
- return NULL;
-}
-
-void hashmap_remove(char *key) {
-
-}
-
-void hashmap_free(struct hashmap *hm) {
- struct node *node;
- struct node *next;
-
- for (int i=0; i < 26; i++) {
- node = hm->buckets[i];
- while (node) {
- next = node->next;
- free(node);
- node = next;
- }
- }
-
- free(hm);
-} \ No newline at end of file