much simpler rehashing that doesn't invalidate references and allocates less

master
Daniel Kolesa 2015-06-16 21:52:37 +01:00
parent 7265aee0d9
commit 3a659c1412
1 changed files with 6 additions and 10 deletions

View File

@ -418,25 +418,21 @@ namespace detail {
memset(nch, 0, count * sizeof(Chain *)); memset(nch, 0, count * sizeof(Chain *));
p_data.first() = nch; p_data.first() = nch;
Chunk *chunks = p_chunks;
octa::Size osize = p_size; octa::Size osize = p_size;
p_chunks = nullptr;
p_unused = nullptr;
p_size = count; p_size = count;
p_len = 0;
for (octa::Size i = 0; i < osize; ++i) { for (octa::Size i = 0; i < osize; ++i) {
for (Chain *oc = och[i]; oc; oc = oc->next) { for (Chain *oc = och[i]; oc;) {
octa::Size h = get_hash()(B::get_key(oc->value)) & (count - 1); octa::Size h = get_hash()(B::get_key(oc->value)) & (p_size - 1);
Chain *nc = insert(h); Chain *nxc = oc->next;
B::swap_elem(oc->value, nc->value); oc->next = nch[h];
nch[h] = oc;
oc = nxc;
} }
} }
if (och && osize) octa::allocator_deallocate(get_cpalloc(), if (och && osize) octa::allocator_deallocate(get_cpalloc(),
och, osize); och, osize);
delete_chunks(chunks);
} }
void rehash_up() { void rehash_up() {