summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-08-24 01:45:08 -0700
committerOri Bernstein <ori@eigenstate.org>2015-08-24 22:12:13 -0700
commit4c2029561abd571e9a4853f113ec776d79523c5b (patch)
tree47b61efaa1fbe6a8dc408fcbf137eea68859f823
parent60a248049f2cdcb1e7a53e9d77374769b4436545 (diff)
downloadmc-4c2029561abd571e9a4853f113ec776d79523c5b.tar.gz
Handle hash tables full of tombstones.
-rw-r--r--parse/htab.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/parse/htab.c b/parse/htab.c
index 49bed75..8f5cb51 100644
--- a/parse/htab.c
+++ b/parse/htab.c
@@ -85,6 +85,7 @@ static void grow(Htab *ht, int sz)
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 @@ conflicted:
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 @@ void htdel(Htab *ht, void *k)
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++;
}