h_hashtable_put generated double entries if the match was last in list
This commit is contained in:
parent
5dee5fec6c
commit
b28d82bdeb
1 changed files with 6 additions and 4 deletions
|
|
@ -145,12 +145,14 @@ void h_hashtable_put(HHashTable* ht, const void* key, void* value) {
|
||||||
|
|
||||||
HHashTableEntry *hte = &ht->contents[hashval & (ht->capacity - 1)];
|
HHashTableEntry *hte = &ht->contents[hashval & (ht->capacity - 1)];
|
||||||
if (hte->key != NULL) {
|
if (hte->key != NULL) {
|
||||||
do {
|
for(;;) {
|
||||||
|
// check each link, stay on last if not found
|
||||||
if (hte->hashval == hashval && ht->equalFunc(key, hte->key))
|
if (hte->hashval == hashval && ht->equalFunc(key, hte->key))
|
||||||
goto insert_here;
|
goto insert_here;
|
||||||
if (hte->next != NULL)
|
if (hte->next == NULL)
|
||||||
|
break;
|
||||||
hte = hte->next;
|
hte = hte->next;
|
||||||
} while (hte->next != NULL);
|
}
|
||||||
// Add a new link...
|
// Add a new link...
|
||||||
assert (hte->next == NULL);
|
assert (hte->next == NULL);
|
||||||
hte->next = h_arena_malloc(ht->arena, sizeof(HHashTableEntry));
|
hte->next = h_arena_malloc(ht->arena, sizeof(HHashTableEntry));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue