diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 3d11e0e..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; @@ -3473,15 +3478,20 @@ public: return it == end() ? node_type() : extract(const_iterator{it}); } - void swap(parallel_hash_set& that) noexcept( - IsNoThrowSwappable() && - (!AllocTraits::propagate_on_container_swap::value || - IsNoThrowSwappable())) { + template + void swap(parallel_hash_set& that) + noexcept(IsNoThrowSwappable() && + (!AllocTraits::propagate_on_container_swap::value || + IsNoThrowSwappable())) + { using std::swap; + using Lockable2 = phmap::LockableImpl; + for (size_t i=0; i friend void swap(parallel_hash_set& a, - parallel_hash_set& b) noexcept(noexcept(a.swap(b))) { + parallel_hash_set& b) + noexcept(noexcept(a.swap(b))) + { a.swap(b); } @@ -3700,14 +3713,16 @@ private: // TODO(alkis): Optimize this assuming *this and that don't overlap. // -------------------------------------------------------------------- - parallel_hash_set& move_assign(parallel_hash_set&& that, std::true_type) { - parallel_hash_set tmp(std::move(that)); + template + parallel_hash_set& move_assign(parallel_hash_set&& that, std::true_type) { + parallel_hash_set tmp(std::move(that)); swap(tmp); return *this; } - parallel_hash_set& move_assign(parallel_hash_set&& that, std::false_type) { - parallel_hash_set tmp(std::move(that), alloc_ref()); + template + parallel_hash_set& move_assign(parallel_hash_set&& that, std::false_type) { + parallel_hash_set tmp(std::move(that), alloc_ref()); swap(tmp); return *this; } diff --git a/tests/flat_hash_map_test.cc b/tests/flat_hash_map_test.cc index d6d50d2..f64bbdd 100644 --- a/tests/flat_hash_map_test.cc +++ b/tests/flat_hash_map_test.cc @@ -22,6 +22,10 @@ #define THIS_EXTRA_TPL_PARAMS #endif +#ifndef THIS_EXTRA_TPL_PARAMS_NULLMUTEX + #define THIS_EXTRA_TPL_PARAMS_NULLMUTEX +#endif + #include "parallel_hashmap/phmap.h" #if defined(PHMAP_HAVE_STD_ANY) @@ -62,6 +66,12 @@ template , 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