Add "if_contains" to parallel_hash_map so the value does not need to be copied to be read in a thread-safe manner

Add tests for parallel_hash_map thread-safe functions.
This commit is contained in:
Brian McKinnon
2020-05-02 16:47:33 -05:00
parent 13853156fc
commit 0e723143fa
5 changed files with 45 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
#ifndef THIS_HASH_MAP
#define THIS_HASH_MAP parallel_flat_hash_map
#define THIS_TEST_NAME ParallelFlatHashMap
#endif
namespace phmap {
namespace container_internal {
namespace {
TEST(THIS_TEST_NAME, ThreadSafeContains) {
// We can't test mutable keys, or non-copyable keys with ThisMap.
// 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_EQ(val, 7);
EXPECT_FALSE(m.contains(3, val));
#if __cplusplus > 199711L
auto func = [&val](int& v) { val = v; };
EXPECT_TRUE(m.if_contains(2, func));
EXPECT_EQ(val, 9);
EXPECT_FALSE(m.if_contains(3, func));
#endif
}
} // namespace
} // namespace container_internal
} // namespace phmap