Skip to content
Snippets Groups Projects
Commit 8aec952c authored by dario.genga's avatar dario.genga
Browse files

Add hashmap create and destroy methods

parent 7a5d149b
Branches
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment