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 <kristoimenov@gmail.com>
This commit is contained in:
Kristiyan Stoimenov 2022-05-23 23:23:28 +03:00
parent 90d1f7f199
commit 2c523ff895
No known key found for this signature in database
GPG Key ID: 520809DAFC3B373C
1 changed files with 1 additions and 6 deletions

View File

@ -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;