From 6968d22348e93967bfc120d73f4983a96e72d15e Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 25 Mar 2019 07:58:34 -0400 Subject: [PATCH] add parallel_node variants --- CMakeLists.txt | 6 ++ parallel_hashmap/phmap.h | 132 +++++++++++++++++++++++++++ tests/parallel_node_hash_map_test.cc | 4 + tests/parallel_node_hash_set_test.cc | 4 + 4 files changed, 146 insertions(+) create mode 100644 tests/parallel_node_hash_map_test.cc create mode 100644 tests/parallel_node_hash_set_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index d37aecf..72256b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,12 @@ if (PHMAP_BUILD_TESTS) phmap_cc_test(NAME node_hash_set SRCS "tests/node_hash_set_test.cc" COPTS "-DUNORDERED_SET_CXX17" DEPS gmock_main) + phmap_cc_test(NAME parallel_node_hash_map SRCS "tests/parallel_node_hash_map_test.cc" + DEPS gmock_main) + + phmap_cc_test(NAME parallel_node_hash_set SRCS "tests/parallel_node_hash_set_test.cc" + COPTS "-DUNORDERED_SET_CXX17" DEPS gmock_main) + endif() if (PHMAP_BUILD_EXAMPLES) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 1870231..f0e8173 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -4535,6 +4535,138 @@ public: using Base::key_eq; }; +// ----------------------------------------------------------------------------- +// phmap::parallel_node_hash_set +// ----------------------------------------------------------------------------- +// An `phmap::node_hash_set` is an unordered associative container which +// has been optimized for both speed and memory footprint in most common use +// cases. Its interface is similar to that of `std::unordered_set` with the +// following notable differences: +// +// * Supports heterogeneous lookup, through `find()`, `operator[]()` and +// `insert()`, provided that the map is provided a compatible heterogeneous +// hashing function and equality operator. +// * Contains a `capacity()` member function indicating the number of element +// slots (open, deleted, and empty) within the hash set. +// * Returns `void` from the `erase(iterator)` overload. +// ----------------------------------------------------------------------------- +template , + class Eq = phmap::container_internal::hash_default_eq, + class Alloc = std::allocator, + size_t N = 4, + class Mutex = phmap::NullMutex> +class parallel_node_hash_set + : public phmap::container_internal::parallel_hash_set< + N, phmap::container_internal::raw_hash_set, Mutex, + phmap::container_internal::NodeHashSetPolicy, Hash, Eq, Alloc> +{ + using Base = typename parallel_node_hash_set::parallel_hash_set; + +public: + parallel_node_hash_set() {} + using Base::Base; + using Base::begin; + using Base::cbegin; + using Base::cend; + using Base::end; + using Base::capacity; + using Base::empty; + using Base::max_size; + using Base::size; + using Base::clear; + using Base::erase; + using Base::insert; + using Base::emplace; + using Base::emplace_hint; + using Base::extract; + using Base::merge; + using Base::swap; + using Base::rehash; + using Base::reserve; + using Base::contains; + using Base::count; + using Base::equal_range; + using Base::find; + using Base::bucket_count; + using Base::load_factor; + using Base::max_load_factor; + using Base::get_allocator; + using Base::hash_function; + using Base::key_eq; + typename Base::hasher hash_funct() { return this->hash_function(); } + void resize(typename Base::size_type hint) { this->rehash(hint); } +}; + +// ----------------------------------------------------------------------------- +// phmap::parallel_node_hash_map +// ----------------------------------------------------------------------------- +// +// An `phmap::node_hash_map` is an unordered associative container which +// has been optimized for both speed and memory footprint in most common use +// cases. Its interface is similar to that of `std::unordered_map` with +// the following notable differences: +// +// * Supports heterogeneous lookup, through `find()`, `operator[]()` and +// `insert()`, provided that the map is provided a compatible heterogeneous +// hashing function and equality operator. +// * Contains a `capacity()` member function indicating the number of element +// slots (open, deleted, and empty) within the hash map. +// * Returns `void` from the `erase(iterator)` overload. +// ----------------------------------------------------------------------------- +template , + class Eq = phmap::container_internal::hash_default_eq, + class Alloc = std::allocator>, + size_t N = 4, + class Mutex = phmap::NullMutex> +class parallel_node_hash_map + : public phmap::container_internal::parallel_hash_map< + N, phmap::container_internal::raw_hash_set, Mutex, + phmap::container_internal::NodeHashMapPolicy, Hash, Eq, + Alloc> +{ + using Base = typename parallel_node_hash_map::parallel_hash_map; + +public: + parallel_node_hash_map() {} + using Base::Base; + using Base::begin; + using Base::cbegin; + using Base::cend; + using Base::end; + using Base::capacity; + using Base::empty; + using Base::max_size; + using Base::size; + using Base::clear; + using Base::erase; + using Base::insert; + using Base::insert_or_assign; + using Base::emplace; + using Base::emplace_hint; + using Base::try_emplace; + using Base::extract; + using Base::merge; + using Base::swap; + using Base::rehash; + using Base::reserve; + using Base::at; + using Base::contains; + using Base::count; + using Base::equal_range; + using Base::find; + using Base::operator[]; + using Base::bucket_count; + using Base::load_factor; + using Base::max_load_factor; + using Base::get_allocator; + using Base::hash_function; + using Base::key_eq; + typename Base::hasher hash_funct() { return this->hash_function(); } + void resize(typename Base::size_type hint) { this->rehash(hint); } +}; + } // namespace phmap #endif // phmap_h_guard_ diff --git a/tests/parallel_node_hash_map_test.cc b/tests/parallel_node_hash_map_test.cc new file mode 100644 index 0000000..615a0ba --- /dev/null +++ b/tests/parallel_node_hash_map_test.cc @@ -0,0 +1,4 @@ +#define THIS_HASH_MAP parallel_node_hash_map +#define THIS_TEST_NAME ParallelNodeHashMap + +#include "flat_hash_map_test.cc" diff --git a/tests/parallel_node_hash_set_test.cc b/tests/parallel_node_hash_set_test.cc new file mode 100644 index 0000000..f3b1c1b --- /dev/null +++ b/tests/parallel_node_hash_set_test.cc @@ -0,0 +1,4 @@ +#define THIS_HASH_SET parallel_node_hash_set +#define THIS_TEST_NAME ParallelNodeHashSet + +#include "node_hash_set_test.cc"