From 7df85b52a4af12628da8a9af824bfab838913e55 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Sun, 3 Sep 2023 23:56:44 -0400 Subject: [PATCH] Fix issue with my previous change (memory not deleted for node_hash_set/map. --- include/gtl/phmap.hpp | 14 ++++++++++---- tests/phmap/raw_hash_set_allocator_test.cpp | 1 + tests/phmap/raw_hash_set_test.cpp | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/gtl/phmap.hpp b/include/gtl/phmap.hpp index bb68b51..29c5f70 100644 --- a/include/gtl/phmap.hpp +++ b/include/gtl/phmap.hpp @@ -1532,8 +1532,9 @@ class raw_hash_set 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); @@ -2329,8 +2330,9 @@ class raw_hash_set 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 for (size_t i = 0; i != capacity_; ++i) { if (IsFull(ctrl_[i])) { PolicyTraits::destroy(&alloc_ref(), slots_ + i); @@ -4981,6 +4983,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) @@ -5022,6 +5025,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) @@ -5110,6 +5114,7 @@ struct NodeHashSetPolicy : gtl::priv::node_hash_policy> 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) @@ -5151,6 +5156,7 @@ class NodeHashMapPolicy 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/phmap/raw_hash_set_allocator_test.cpp b/tests/phmap/raw_hash_set_allocator_test.cpp index 843c422..64bb308 100644 --- a/tests/phmap/raw_hash_set_allocator_test.cpp +++ b/tests/phmap/raw_hash_set_allocator_test.cpp @@ -143,6 +143,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, Args&&... args) diff --git a/tests/phmap/raw_hash_set_test.cpp b/tests/phmap/raw_hash_set_test.cpp index 6407bc8..322a386 100644 --- a/tests/phmap/raw_hash_set_test.cpp +++ b/tests/phmap/raw_hash_set_test.cpp @@ -276,6 +276,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*) {} @@ -325,6 +326,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) @@ -653,6 +655,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)