c_hashmap icon indicating copy to clipboard operation
c_hashmap copied to clipboard

Flaw in hashmap_remove()?

Open a1880 opened this issue 10 years ago • 1 comments

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

a1880 avatar Feb 03 '15 14:02 a1880

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

ajayRam2020 avatar Jun 10 '16 10:06 ajayRam2020