Skip to content

Commit 57b1448

Browse files
committed
Fix flat_hash_map when used across library boundaries.
Now it works with dll. For more details see: skarupke/flat_hash_map#26
1 parent 3d1fac2 commit 57b1448

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

include/ska/flat_hash_map.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,6 @@ struct sherwood_v3_entry
164164
~sherwood_v3_entry()
165165
{
166166
}
167-
static sherwood_v3_entry * empty_default_table()
168-
{
169-
static sherwood_v3_entry result[min_lookups] = { {}, {}, {}, {special_end_value} };
170-
return result;
171-
}
172-
173167
bool has_value() const
174168
{
175169
return distance_from_desired >= 0;
@@ -755,13 +749,22 @@ class sherwood_v3_table : private EntryAlloc, private Hasher, private Equal
755749
}
756750

757751
private:
758-
EntryPointer entries = Entry::empty_default_table();
752+
EntryPointer entries = empty_default_table();
759753
size_t num_slots_minus_one = 0;
760754
typename HashPolicySelector<ArgumentHash>::type hash_policy;
761755
int8_t max_lookups = detailv3::min_lookups - 1;
762756
float _max_load_factor = 0.5f;
763757
size_t num_elements = 0;
764758

759+
EntryPointer empty_default_table()
760+
{
761+
EntryPointer result = AllocatorTraits::allocate(*this, detailv3::min_lookups);
762+
EntryPointer special_end_item = result + static_cast<ptrdiff_t>(detailv3::min_lookups - 1);
763+
for (EntryPointer it = result; it != special_end_item; ++it)
764+
it->distance_from_desired = -1;
765+
special_end_item->distance_from_desired = Entry::special_end_value;
766+
return result;
767+
}
765768
static int8_t compute_max_lookups(size_t num_buckets)
766769
{
767770
int8_t desired = detailv3::log2(num_buckets);
@@ -841,16 +844,13 @@ class sherwood_v3_table : private EntryAlloc, private Hasher, private Equal
841844

842845
void deallocate_data(EntryPointer begin, size_t num_slots_minus_one_, int8_t max_lookups_)
843846
{
844-
if (begin != Entry::empty_default_table())
845-
{
846-
AllocatorTraits::deallocate(*this, begin, num_slots_minus_one_ + max_lookups_ + 1);
847-
}
847+
AllocatorTraits::deallocate(*this, begin, num_slots_minus_one_ + max_lookups_ + 1);
848848
}
849849

850850
void reset_to_empty_state()
851851
{
852852
deallocate_data(entries, num_slots_minus_one, max_lookups);
853-
entries = Entry::empty_default_table();
853+
entries = empty_default_table();
854854
num_slots_minus_one = 0;
855855
hash_policy.reset();
856856
max_lookups = detailv3::min_lookups - 1;

0 commit comments

Comments
 (0)