diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-08-23 23:52:12 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-08-23 23:52:12 -0700 |
commit | 3321a6568822c6278aa4e85845592596521a523f (patch) | |
tree | dad9c29c4088829dc361931888f4cdd3da9eba36 | |
parent | 48996257e5e74a72258db974a03ba8e40ce9287f (diff) | |
download | mc-3321a6568822c6278aa4e85845592596521a523f.tar.gz |
Fix hash table bug.
This table was intially designed with no provisions for
deletion.
-rw-r--r-- | parse/htab.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/parse/htab.c b/parse/htab.c index 529f809..8b69584 100644 --- a/parse/htab.c +++ b/parse/htab.c @@ -135,12 +135,14 @@ static ssize_t htidx(Htab *ht, void *k) di = 0; h = hash(ht, k); i = h & (ht->sz - 1); - while (ht->hashes[i] && !ht->dead[i] && ht->hashes[i] != h) { + while (ht->hashes[i] && ht->hashes[i] != h) { searchmore: di++; i = (h + di) & (ht->sz - 1); } - if (!ht->hashes[i] || ht->dead[i]) + if (ht->dead[i]) + goto searchmore; + if (!ht->hashes[i]) return -1; if (!ht->cmp(ht->keys[i], k)) goto searchmore; /* collision */ |