hash.c (ht_set_without_ib_adjustment): need to skip tombstone; #6421

If a tombstone (a deleted entry slot) is found in searching the entry,
it should be skipped, but we had added the new entry even if the entry
to be replaced might be found in the further search. #6414 and #6421
tried to rehash the table to remove tombstone. But rehashing consumes
memory. So for the time being, we just skip tombstones in the search.
Maybe we will add some heuristics to rehash when the table has too many
tombstones. close #6414
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-11-20 10:41:19 +09:00
parent 9ea6bda781
commit 33357d4f35
+5 -4
View File
@@ -295,8 +295,7 @@ static void ht_init(
mrb_state *mrb, struct RHash *h, uint32_t size,
hash_entry *ea, uint32_t ea_capa, hash_table *ht, uint32_t ib_bit);
static void ht_set(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val);
static void ht_set_without_ib_adjustment(
mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val);
static void ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val);
static uint32_t
next_power2(uint32_t v)
@@ -847,8 +846,7 @@ ht_set_as_ar(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val)
}
static void
ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h,
mrb_value key, mrb_value val)
ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val)
{
mrb_assert(ht_size(h) < ib_bit_to_capa(ib_bit(h)));
ib_cycle_by_key(mrb, h, key, it, {
@@ -856,6 +854,9 @@ ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h,
if (!obj_eql(mrb, key, ib_it_entry(it)->key, h)) continue;
ib_it_entry(it)->val = val;
}
else if (ib_it_deleted_p(it)) {
continue;
}
else {
uint32_t ea_n_used = ht_ea_n_used(h);
if (ea_n_used == H_MAX_SIZE) {