forked from OctaForge/libostd
better hashtable erase
parent
71f5df79ce
commit
852ae9ea37
|
@ -554,28 +554,29 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Size erase(const K &key) {
|
Size erase(const K &key) {
|
||||||
if (!p_len) return 0;
|
Size h = 0;
|
||||||
Size olen = p_len;
|
Chain *c = find(key, h);
|
||||||
Size h = bucket(key);
|
if (!c) return 0;
|
||||||
Chain **cp = p_data.first();
|
Chain **cp = p_data.first();
|
||||||
for (Chain *c = cp[h], *e = cp[h + 1]; c != e; c = c->next)
|
Size olen = p_len;
|
||||||
if (get_eq()(key, B::get_key(c->value))) {
|
for (Chain *e = cp[h + 1]; c != e; c = c->next) {
|
||||||
--p_len;
|
if (!get_eq()(key, B::get_key(c->value))) break;
|
||||||
Size hh = h;
|
--p_len;
|
||||||
Chain *next = c->next;
|
Size hh = h;
|
||||||
for (; cp[hh] == c; --hh) {
|
Chain *next = c->next;
|
||||||
cp[hh] = next;
|
for (; cp[hh] == c; --hh) {
|
||||||
if (!hh) break;
|
cp[hh] = next;
|
||||||
}
|
if (!hh) break;
|
||||||
if (c->prev) c->prev->next = next;
|
|
||||||
if (next) next->prev = c->prev;
|
|
||||||
c->next = p_unused;
|
|
||||||
c->prev = nullptr;
|
|
||||||
p_unused = c;
|
|
||||||
allocator_destroy(get_alloc(), &c->value);
|
|
||||||
allocator_construct(get_alloc(), &c->value);
|
|
||||||
if (!Multihash) return 1;
|
|
||||||
}
|
}
|
||||||
|
if (c->prev) c->prev->next = next;
|
||||||
|
if (next) next->prev = c->prev;
|
||||||
|
c->next = p_unused;
|
||||||
|
c->prev = nullptr;
|
||||||
|
p_unused = c;
|
||||||
|
allocator_destroy(get_alloc(), &c->value);
|
||||||
|
allocator_construct(get_alloc(), &c->value);
|
||||||
|
if (!Multihash) return 1;
|
||||||
|
}
|
||||||
return olen - p_len;
|
return olen - p_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue