ref: 4c2029561abd571e9a4853f113ec776d79523c5b
parent: 60a248049f2cdcb1e7a53e9d77374769b4436545
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Aug 23 21:45:08 EDT 2015
Handle hash tables full of tombstones.
--- a/parse/htab.c
+++ b/parse/htab.c
@@ -85,6 +85,7 @@
for (i = 0; i < oldsz; i++)
if (oldh[i] && !oldd[i])
htput(ht, oldk[i], oldv[i]);
+
free(oldh);
free(oldk);
free(oldv);
@@ -123,9 +124,10 @@
ht->keys[i] = k;
ht->vals[i] = v;
ht->dead[i] = 0;
- if (ht->sz < ht->nelt*2)
- grow(ht, ht->sz*2);
- if (ht->sz < ht->ndead*4)
+
+ if (ht->sz < ht->nelt * 2)
+ grow(ht, ht->sz * 2);
+ if (ht->sz < ht->ndead * 4)
grow(ht, ht->sz);
return 1;
}
@@ -176,10 +178,11 @@
i = htidx(ht, k);
if (i < 0)
return;
- if (!ht->dead[i])
- ht->ndead++;
+ assert(!ht->dead[i]);
+ assert(ht->hashes[i]);
ht->dead[i] = 1;
ht->nelt--;
+ ht->ndead++;
}