diff --git a/hashtable.c b/hashtable.c index 0d286e44ae75b609cf8f8475fab4f6be8b6d0da0..23c17ce8631fc88901aed4c43ff0ac2f7e458a2c 100644 --- a/hashtable.c +++ b/hashtable.c @@ -9,11 +9,22 @@ #include <string.h> hm *hm_create(unsigned int length) { - return NULL; + hm *hashmap = malloc(sizeof(hm)); + hashmap->length = length; + hashmap->entries = malloc(sizeof(entry) * length); + for (int i = 0; i < length; i++) { + hashmap->entries[i] = malloc(sizeof(entry)); + } + + return hashmap; } void hm_destroy(hm **hm) { - + for (int i = 0; i < (*hm)->length; i++) { + free((*hm)->entries[i]); + } + free((*hm)->entries); + free((*hm)); } hm *hm_set(hm *hm, const char *const key, const char *const value) { diff --git a/main.c b/main.c index df0280e64212cccf9b2028951c8713148afd51ff..09ae288928dd80d4db07b75589fe999f4b0ccdad 100644 --- a/main.c +++ b/main.c @@ -5,7 +5,11 @@ #include <stdio.h> #include <stdlib.h> +#include "hashtable.h" int main() { + hm *hashmap = hm_create(10); + hm_destroy(&hashmap); + return EXIT_SUCCESS; }