Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions include/ska/flat_hash_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ struct sherwood_v3_entry
~sherwood_v3_entry()
{
}
static sherwood_v3_entry * empty_default_table()
{
static sherwood_v3_entry result[min_lookups] = { {}, {}, {}, {special_end_value} };
return result;
}

bool has_value() const
{
return distance_from_desired >= 0;
Expand Down Expand Up @@ -755,13 +749,22 @@ class sherwood_v3_table : private EntryAlloc, private Hasher, private Equal
}

private:
EntryPointer entries = Entry::empty_default_table();
EntryPointer entries = empty_default_table();
size_t num_slots_minus_one = 0;
typename HashPolicySelector<ArgumentHash>::type hash_policy;
int8_t max_lookups = detailv3::min_lookups - 1;
float _max_load_factor = 0.5f;
size_t num_elements = 0;

EntryPointer empty_default_table()
{
EntryPointer result = AllocatorTraits::allocate(*this, detailv3::min_lookups);
EntryPointer special_end_item = result + static_cast<ptrdiff_t>(detailv3::min_lookups - 1);
for (EntryPointer it = result; it != special_end_item; ++it)
it->distance_from_desired = -1;
special_end_item->distance_from_desired = Entry::special_end_value;
return result;
}
static int8_t compute_max_lookups(size_t num_buckets)
{
int8_t desired = detailv3::log2(num_buckets);
Expand Down Expand Up @@ -841,16 +844,13 @@ class sherwood_v3_table : private EntryAlloc, private Hasher, private Equal

void deallocate_data(EntryPointer begin, size_t num_slots_minus_one_, int8_t max_lookups_)
{
if (begin != Entry::empty_default_table())
{
AllocatorTraits::deallocate(*this, begin, num_slots_minus_one_ + max_lookups_ + 1);
}
AllocatorTraits::deallocate(*this, begin, num_slots_minus_one_ + max_lookups_ + 1);
}

void reset_to_empty_state()
{
deallocate_data(entries, num_slots_minus_one, max_lookups);
entries = Entry::empty_default_table();
entries = empty_default_table();
num_slots_minus_one = 0;
hash_policy.reset();
max_lookups = detailv3::min_lookups - 1;
Expand Down