From b28d82bdebaa293ac8fe306faf83723d9c71979e Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Sun, 5 May 2013 22:12:05 +0200 Subject: [PATCH] h_hashtable_put generated double entries if the match was last in list --- src/datastructures.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/datastructures.c b/src/datastructures.c index 271f4c6..d5123fd 100644 --- a/src/datastructures.c +++ b/src/datastructures.c @@ -145,12 +145,14 @@ void h_hashtable_put(HHashTable* ht, const void* key, void* value) { HHashTableEntry *hte = &ht->contents[hashval & (ht->capacity - 1)]; if (hte->key != NULL) { - do { + for(;;) { + // check each link, stay on last if not found if (hte->hashval == hashval && ht->equalFunc(key, hte->key)) goto insert_here; - if (hte->next != NULL) - hte = hte->next; - } while (hte->next != NULL); + if (hte->next == NULL) + break; + hte = hte->next; + } // Add a new link... assert (hte->next == NULL); hte->next = h_arena_malloc(ht->arena, sizeof(HHashTableEntry));