Define a LH_LOAD_FACTOR constant and note the range that it can be set to.

Change the resize check from "count > size" to "count >= size" to avoid a
potential infinite loop with high load factors and a full hash table.
This commit is contained in:
Eric Haszlakiewicz
2012-03-31 17:33:58 -05:00
committed by Keith Derrick
parent e6668b1406
commit 7c4a964002
2 changed files with 8 additions and 1 deletions

View File

@@ -125,7 +125,7 @@ int lh_table_insert(struct lh_table *t, void *k, const void *v)
unsigned long h, n;
t->inserts++;
if(t->count > t->size * 0.66) lh_table_resize(t, t->size * 2);
if(t->count >= t->size * LH_LOAD_FACTOR) lh_table_resize(t, t->size * 2);
h = t->hash_fn(k);
n = h % t->size;