Skip to content

Commit

Permalink
Fixed ska::flat_hash_map across DLL boundaries, I think? Enabled it a…
Browse files Browse the repository at this point in the history
…s default HashMap.
  • Loading branch information
amzeratul committed Dec 5, 2021
1 parent 7d834cb commit 37cc635
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/contrib/skarupke/flat_hash_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@ struct sherwood_v3_entry
sherwood_v3_entry()
{
}
sherwood_v3_entry(int8_t distance_from_desired)
sherwood_v3_entry(int8_t distance_from_desired, bool isDefault = false)
: distance_from_desired(distance_from_desired)
, isDefault(isDefault)
{
}
~sherwood_v3_entry()
{
}
static sherwood_v3_entry * empty_default_table()
{
static sherwood_v3_entry result[min_lookups] = { {}, {}, {}, {special_end_value} };
static sherwood_v3_entry result[min_lookups] = { {-1, true}, {}, {}, {special_end_value} };
return result;
}

Expand Down Expand Up @@ -201,6 +202,7 @@ struct sherwood_v3_entry
}

int8_t distance_from_desired = -1;
bool isDefault = false;
static constexpr int8_t special_end_value = 0;
union { T value; };
};
Expand Down Expand Up @@ -878,7 +880,7 @@ 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())
if (!static_cast<sherwood_v3_entry<T>*>(begin)[0].isDefault)
{
AllocatorTraits::deallocate(*this, begin, num_slots_minus_one + max_lookups + 1);
}
Expand Down
14 changes: 8 additions & 6 deletions src/engine/utils/include/halley/bytes/byte_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ namespace Halley {
}

template <typename T, typename U>
Serializer& operator<<(const FlatMap<T, U>& val)
Serializer& operator<<(const HashMap<T, U>& val)
{
*this << static_cast<unsigned int>(val.size());
for (auto& kv : val) {
*this << kv.first << kv.second;
// Convert to map first to make order deterministic
std::map<T, U> m;
for (auto& kv: val) {
m[kv.first] = kv.second;
}
return *this;
return (*this << m);
}

template <typename K, typename V, typename Cmp, typename Allocator>
Expand All @@ -151,6 +152,7 @@ namespace Halley {
template <typename T, typename U>
Serializer& operator<<(const std::unordered_map<T, U>& val)
{
// Convert to map first to make order deterministic
std::map<T, U> m;
for (auto& kv: val) {
m[kv.first] = kv.second;
Expand Down Expand Up @@ -355,7 +357,7 @@ namespace Halley {
}

template <typename T, typename U>
Deserializer& operator>>(FlatMap<T, U>& val)
Deserializer& operator>>(HashMap<T, U>& val)
{
unsigned int sz;
*this >> sz;
Expand Down
7 changes: 4 additions & 3 deletions src/engine/utils/include/halley/data_structures/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ namespace Halley {
*/

/*
#include <unordered_map>
namespace Halley {
template<typename Key, typename T> using HashMap = std::unordered_map<Key, T, std::hash<Key>>;
}
*/


/*
#ifdef min
#undef min
#endif
Expand All @@ -26,7 +28,6 @@ namespace Halley {
#include "../../../../../contrib/skarupke/flat_hash_map.hpp"

namespace Halley {

template<typename K, typename V> using HashMap = ska::flat_hash_map<K, V>;
}
*/

0 comments on commit 37cc635

Please sign in to comment.