From 2c523ff895f801fa48fb8d540b04e287d1e897b5 Mon Sep 17 00:00:00 2001 From: Kristiyan Stoimenov Date: Mon, 23 May 2022 23:23:28 +0300 Subject: [PATCH] Hashmap: Do not insert duplicate keys While looking into the table for a spot for the new key, search until an empty one is found and do not overwrite tombstones. Signed-off-by: Kristiyan Stoimenov --- hashmap.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/hashmap.c b/hashmap.c index a83934d11..efb5d690c 100644 --- a/hashmap.c +++ b/hashmap.c @@ -23,7 +23,7 @@ static uint64_t fnv_hash(char *s, int len) { return hash; } -// Make room for new entires in a given hashmap by removing +// Make room for new entries in a given hashmap by removing // tombstones and possibly extending the bucket size. static void rehash(HashMap *map) { // Compute the size of the new hashmap. @@ -89,11 +89,6 @@ static HashEntry *get_or_insert_entry(HashMap *map, char *key, int keylen) { if (match(ent, key, keylen)) return ent; - if (ent->key == TOMBSTONE) { - ent->key = key; - ent->keylen = keylen; - return ent; - } if (ent->key == NULL) { ent->key = key;