From 144bd88ff5146af4df99596606a7bf2a624723fc Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 24 Dec 2022 02:25:49 +0100 Subject: Simplify hashmaps by not freeing keys --- src/gehashmap.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/gehashmap.h') diff --git a/src/gehashmap.h b/src/gehashmap.h index 0a3d7c1..311c2c3 100644 --- a/src/gehashmap.h +++ b/src/gehashmap.h @@ -1,5 +1,5 @@ -#ifndef GEHASHMAP_H -#define GEHASHMAP_H +#ifndef LIBGE_GEHASHMAP_H +#define LIBGE_GEHASHMAP_H #include #include @@ -32,7 +32,6 @@ int n##_remove(n##_t *, k); \ int n##_resize(n##_t *, size_t); \ bool n##_key_iseq(k, k); \ - void n##_key_free(k); \ size_t n##_key_hash(k); #define GEHASHMAP_IMPL(k, v, n) \ @@ -60,7 +59,6 @@ struct n##_entry *entry = map->entries[i]; \ while (entry != NULL) { \ struct n##_entry *next = entry->next; \ - n##_key_free(entry->key); \ free(entry); \ entry = next; \ } \ @@ -171,9 +169,8 @@ } \ \ /* Function to remove an element with a given key from a hashmap. If - * the value was dynamically allocated it will not be freed. The key - * will be freed however as per n##_key_free(). On error -1 is - * returned, otherwise 0 is returned. + * the key or value were dynamically allocated they will not be freed. + * On error -1 is returned, otherwise 0 is returned. */ \ int \ n##_remove(n##_t *map, k key) \ @@ -186,7 +183,6 @@ \ if (n##_key_iseq(entry->key, key)) { \ map->entries[hash] = entry->next; \ - n##_key_free(entry->key); \ free(entry); \ map->size--; \ return 0; \ @@ -196,7 +192,6 @@ if (n##_key_iseq(entry->next->key, key)) { \ struct n##_entry *next = entry->next; \ entry->next = next->next; \ - n##_key_free(next->key); \ free(next); \ map->size--; \ return 0; \ @@ -207,4 +202,4 @@ return -1; \ } -#endif /* !GEHASHMAP_H */ +#endif /* !LIBGE_GEHASHMAP_H */ -- cgit v1.2.3