Skip to content

Hashmap: Do not insert duplicate keys#98

Open
boki1 wants to merge 1 commit intorui314:mainfrom
boki1:bugfix/53-duplicate-keys-in-hash-table
Open

Hashmap: Do not insert duplicate keys#98
boki1 wants to merge 1 commit intorui314:mainfrom
boki1:bugfix/53-duplicate-keys-in-hash-table

Conversation

@boki1
Copy link
Copy Markdown

@boki1 boki1 commented May 23, 2022

Description
While looking into the table for a spot for the new key, search
until an empty one is found and do not overwrite tombstones.

Reported as #53.

Test

I was not able to find FNV colliding strings so instead I replaced the hash function and used a "dumb" one instead:

static uint64_t dumb_hash(char *s, int len) {
    if (len < 5)
        return 0;
    return 1;
}

Then using the following test case I reproduced the issue:

  hashmap_put(map, "123", (void *)(size_t)3);
  hashmap_put(map, "345", (void *)(size_t)3);
  assert(hashmap_get(map, "123") == (void *)(size_t) 3);
  assert(hashmap_get(map, "345") == (void *)(size_t) 3);
  hashmap_delete(map, "123");
  hashmap_put(map, "345", (void *)(size_t)3);
  assert(hashmap_get(map, "345") == (void *)(size_t) 3);
  hashmap_delete(map, "345");
  assert(hashmap_get(map, "345") == (void *)(size_t) 3);

The test passes when using 2c523f.

Signed-off-by: Kristiyan Stoimenov kristoimenov@gmail.com

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>
fuhsnn added a commit to fuhsnn/slimcc that referenced this pull request Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant