From f0409c6d05dc3747bf629596d9fe21c60a0a8f1f Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Sun, 11 Sep 2022 12:16:35 -0400 Subject: [PATCH] Fix access of protected member, and add test for templated swap() --- parallel_hashmap/phmap.h | 9 +++++++-- tests/flat_hash_map_test.cc | 10 ++++++++++ tests/parallel_flat_hash_map_mutex_test.cc | 2 ++ tests/parallel_hash_map_test.cc | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index cf6789e..48173fe 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -3372,6 +3372,11 @@ public: fCallback(set); } + // unsafe, for internal use only + Inner& get_inner(size_t idx) { + return sets_[idx]; + } + // Extension API: support for heterogeneous keys. // // std::unordered_set s; @@ -3485,8 +3490,8 @@ public: for (size_t i=0; i, class Alloc = phmap::priv::Allocator< phmap::priv::Pair>> using ThisMap = THIS_HASH_MAP; + +template , + class Eq = phmap::priv::hash_default_eq, + class Alloc = phmap::priv::Allocator< + phmap::priv::Pair>> +using ThisMap_NullMutex = THIS_HASH_MAP; static_assert(!std::is_standard_layout(), ""); diff --git a/tests/parallel_flat_hash_map_mutex_test.cc b/tests/parallel_flat_hash_map_mutex_test.cc index 73dbf7b..e88e7da 100644 --- a/tests/parallel_flat_hash_map_mutex_test.cc +++ b/tests/parallel_flat_hash_map_mutex_test.cc @@ -9,4 +9,6 @@ #define THIS_EXTRA_TPL_PARAMS , 4, boost::upgrade_mutex #endif +#define THIS_EXTRA_TPL_PARAMS_NULLMUTEX , 4, phmap::NullMutex + #include "parallel_hash_map_test.cc" diff --git a/tests/parallel_hash_map_test.cc b/tests/parallel_hash_map_test.cc index 4812e06..0188691 100644 --- a/tests/parallel_hash_map_test.cc +++ b/tests/parallel_hash_map_test.cc @@ -9,6 +9,24 @@ namespace phmap { namespace priv { namespace { +TEST(THIS_TEST_NAME, Swap) { + using Map = ThisMap; + using MapB = ThisMap_NullMutex; + + Map t; + EXPECT_TRUE(t.find(0) == t.end()); + auto res = t.emplace(0, 1); + EXPECT_TRUE(res.second); + EXPECT_EQ(1, t.size()); + MapB u; + t.swap(u); + EXPECT_EQ(0, t.size()); + EXPECT_EQ(1, u.size()); + EXPECT_TRUE(t.find(0) == t.end()); + EXPECT_TRUE(u[0] == 1); +} + + TEST(THIS_TEST_NAME, IfContains) { // ---------------- // test if_contains