From 3362017f22d28d840ea231461397ea5f2ce0608a Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Sun, 3 Sep 2023 23:48:09 -0400 Subject: [PATCH] Fix issue with my previous change for issue #205 --- parallel_hashmap/phmap.h | 17 ++++++++++++----- tests/raw_hash_set_allocator_test.cc | 1 + tests/raw_hash_set_test.cc | 3 +++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index dd53f6c..0af75ea 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -1271,8 +1271,9 @@ public: if (empty()) return; if (capacity_) { - if constexpr (!std::is_trivially_destructible::value) { - // not trivially destructible... we need to iterate and destroy values one by one + if constexpr (!std::is_trivially_destructible::value || + std::is_same::value) { + // node map or not trivially destructible... we need to iterate and destroy values one by one for (size_t i = 0; i != capacity_; ++i) { if (IsFull(ctrl_[i])) { PolicyTraits::destroy(&alloc_ref(), slots_ + i); @@ -2008,14 +2009,16 @@ private: if (!capacity_) return; - if constexpr (!std::is_trivially_destructible::value) { - // not trivially destructible... we need to iterate and destroy values one by one + if constexpr (!std::is_trivially_destructible::value || + std::is_same::value) { + // node map, or not trivially destructible... we need to iterate and destroy values one by one + // std::cout << "either this is a node map or " << type_name() << " is not trivially_destructible\n"; for (size_t i = 0; i != capacity_; ++i) { if (IsFull(ctrl_[i])) { PolicyTraits::destroy(&alloc_ref(), slots_ + i); } } - } + } auto layout = MakeLayout(capacity_); // Unpoison before returning the memory to the allocator. SanitizerUnpoisonMemoryRegion(slots_, sizeof(slot_type) * capacity_); @@ -4183,6 +4186,7 @@ struct FlatHashSetPolicy using key_type = T; using init_type = T; using constant_iterators = std::true_type; + using is_flat = std::true_type; template static void construct(Allocator* alloc, slot_type* slot, Args&&... args) { @@ -4225,6 +4229,7 @@ struct FlatHashMapPolicy using key_type = K; using mapped_type = V; using init_type = std::pair; + using is_flat = std::true_type; template static void construct(Allocator* alloc, slot_type* slot, Args&&... args) { @@ -4307,6 +4312,7 @@ struct NodeHashSetPolicy using key_type = T; using init_type = T; using constant_iterators = std::true_type; + using is_flat = std::false_type; template static T* new_element(Allocator* alloc, Args&&... args) { @@ -4352,6 +4358,7 @@ public: using key_type = Key; using mapped_type = Value; using init_type = std::pair; + using is_flat = std::false_type; template static value_type* new_element(Allocator* alloc, Args&&... args) { diff --git a/tests/raw_hash_set_allocator_test.cc b/tests/raw_hash_set_allocator_test.cc index a6388bb..5930377 100644 --- a/tests/raw_hash_set_allocator_test.cc +++ b/tests/raw_hash_set_allocator_test.cc @@ -129,6 +129,7 @@ struct Policy { using slot_type = Tracked; using init_type = Tracked; using key_type = int32_t; + using is_flat = std::false_type; template static void construct(allocator_type* alloc, slot_type* slot, diff --git a/tests/raw_hash_set_test.cc b/tests/raw_hash_set_test.cc index 91946a4..775fdff 100644 --- a/tests/raw_hash_set_test.cc +++ b/tests/raw_hash_set_test.cc @@ -259,6 +259,7 @@ struct IntPolicy { using slot_type = int64_t; using key_type = int64_t; using init_type = int64_t; + using is_flat = std::false_type; static void construct(void*, int64_t* slot, int64_t v) { *slot = v; } static void destroy(void*, int64_t*) {} @@ -301,6 +302,7 @@ class StringPolicy { using key_type = std::string; using init_type = std::pair; + using is_flat = std::false_type; template static void construct(allocator_type* alloc, slot_type* slot, Args... args) { @@ -598,6 +600,7 @@ struct DecomposePolicy { using slot_type = DecomposeType; using key_type = DecomposeType; using init_type = DecomposeType; + using is_flat = std::false_type; template static void construct(void*, DecomposeType* slot, T&& v) {