Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Flaw in hashmap_remove()? #6

Open
a1880 opened this issue Feb 3, 2015 · 1 comment
Open

Flaw in hashmap_remove()? #6

a1880 opened this issue Feb 3, 2015 · 1 comment

Comments

@a1880
Copy link

a1880 commented Feb 3, 2015

Hi Pete,
hashmap_remove() might open a gap in a sequence of entries which share the same hash value. This might lead to the situation that a hashmap_put() creates a duplicate key rather than updating an existing key.
A remedy would be to insert the "in_use=0" gap at the end of a sequence of entries with the same hash.

Example:

before hashmap_remove()

entry A; hash H; in_use=1
entry B; hash H; in_use=1
entry C; hash H; in_use=1

after hashmap_remove(map, "B")

entry A; hash H; in_use=1
entry -; hash -; in_use=0
entry C; hash H; in_use=1

after hashmap_put(map, "C")

entry A; hash H; in_use=1
entry C; hash H; in_use=1
entry C; hash H; in_use=1

I could write a fixed version, but I am not yet familiar enough with github to deal with pull requests.

Greetings

Axel Kemper

@ajayRam2020
Copy link

is it possible for you to paste the fix in comment section ?

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

No branches or pull requests

2 participants