Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Hashmap: Do not insert duplicate keys #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

boki1
Copy link

@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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant