mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
Renamed the thread-safe "contains" to if_contains.
Add tests to parallel_flat_hash_map_mutex_test
This commit is contained in:
Vendored
+6
-9
@@ -3393,15 +3393,11 @@ public:
|
||||
return Policy::value(&*it);
|
||||
}
|
||||
|
||||
template <class K = key_type>
|
||||
bool contains(const key_arg<K>& key) const {
|
||||
return Base::contains(key);
|
||||
}
|
||||
|
||||
template <class K = key_type, class V = mapped_type>
|
||||
bool contains(const key_arg<K>& key, V& v) const {
|
||||
std::enable_if_t<std::is_assignable<mapped_type&, V>::value,
|
||||
bool> if_contains(const key_arg<K>& key, V& v) const {
|
||||
typename Lockable::SharedLock m;
|
||||
auto it = const_cast<parallel_hash_map *>(this)->find(key, Base::hash(key), m);
|
||||
auto it = const_cast<parallel_hash_map *>(this)->find(key, this->hash(key), m);
|
||||
if (it == this->end())
|
||||
return false;
|
||||
v = Policy::value(&*it);
|
||||
@@ -3409,9 +3405,10 @@ public:
|
||||
}
|
||||
|
||||
template <class K = key_type, class F>
|
||||
bool if_contains(const key_arg<K>& key, F&& f) const {
|
||||
std::enable_if_t<!std::is_assignable<mapped_type&, F>::value && std::is_invocable<F, mapped_type&>::value,
|
||||
bool> if_contains(const key_arg<K>& key, F&& f) const {
|
||||
typename Lockable::SharedLock m;
|
||||
auto it = const_cast<parallel_hash_map*>(this)->find(key, Base::hash(key), m);
|
||||
auto it = const_cast<parallel_hash_map*>(this)->find(key, this->hash(key), m);
|
||||
if (it == this->end())
|
||||
return false;
|
||||
std::forward<F>(f)(Policy::value(&*it));
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
#define THIS_EXTRA_TPL_PARAMS , 4, boost::upgrade_mutex
|
||||
#endif
|
||||
|
||||
#include "flat_hash_map_test.cc"
|
||||
#include "parallel_hash_map_test.cc"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#define THIS_HASH_MAP parallel_flat_hash_map
|
||||
#define THIS_TEST_NAME ParallelFlatHashMap
|
||||
|
||||
#include "flat_hash_map_test.cc"
|
||||
#include "parallel_hash_map_test.cc"
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#define THIS_TEST_NAME ParallelFlatHashMap
|
||||
#endif
|
||||
|
||||
#include "flat_hash_map_test.cc"
|
||||
|
||||
namespace phmap {
|
||||
namespace container_internal {
|
||||
namespace {
|
||||
@@ -12,10 +14,10 @@ TEST(THIS_TEST_NAME, ThreadSafeContains) {
|
||||
// Test that the nodes have the proper API.
|
||||
ThisMap<int, int> m = { {1, 7}, {2, 9} };
|
||||
auto val = 0;
|
||||
EXPECT_TRUE(m.contains(1, val));
|
||||
EXPECT_TRUE(m.if_contains(1, val));
|
||||
EXPECT_EQ(val, 7);
|
||||
|
||||
EXPECT_FALSE(m.contains(3, val));
|
||||
EXPECT_FALSE(m.if_contains(3, val));
|
||||
|
||||
#if __cplusplus > 199711L
|
||||
auto func = [&val](int& v) { val = v; };
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#define THIS_HASH_MAP parallel_node_hash_map
|
||||
#define THIS_TEST_NAME ParallelNodeHashMap
|
||||
|
||||
#include "flat_hash_map_test.cc"
|
||||
#include "parallel_hash_map_test.cc"
|
||||
|
||||
Reference in New Issue
Block a user