Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes HklHash misrepresenting size

HklHash had a small bug in the insert function causing it to double
in size much too often and misrepresent the number of buckets used.
  • Loading branch information...
commit 712cba15566c6fcb440826ce9ad84a0fb65c3851 1 parent 0a45d3b
@cknadler cknadler authored
Showing with 2 additions and 6 deletions.
  1. +2 −6 src/hkl_hash.c
View
8 src/hkl_hash.c
@@ -144,6 +144,7 @@ void hkl_hash_insert(HklHash* hash, HklString* key, void* value)
HklHashElement* element = &hash->buckets[index];
assert(element != NULL);
+ // Collision
if (element->data != NULL)
{
if (element->is_tree)
@@ -160,13 +161,11 @@ void hkl_hash_insert(HklHash* hash, HklString* key, void* value)
hkl_tree_insert((HklTree*) element->data, key, value);
- // The number of entries of the table increases
- ++hash->length;
-
// Mark the element as a tree
element->is_tree = true;
}
}
+ // No Collision
else
{
// Nothing exists here. Make a pair
@@ -177,10 +176,7 @@ void hkl_hash_insert(HklHash* hash, HklString* key, void* value)
// If the hash table is 75% full
if (hash->length >= 0.75*hash->size)
- {
- // Grow the table
hkl_hash_double(hash);
- }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.