diff --git a/README.md b/README.md index 7b8392c..1f02fbe 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This repository aims to provide a set of excellent **hash map** implementations, - Easy to **forward declare**: just include `phmap_fwd_decl.h` in your header files to forward declare Parallel Hashmap containers [note: this does not work currently for hash maps with pointer keys] -- **Dump/load** feature: when a hash map stores data that is `std::trivially_copyable`, the table can be dumped to disk and restored as a single array, very efficiently, and without requiring any hash computation. This is typically about 10 times faster than doing element-wise serialization to disk, but it will use 10% to 60% extra disk space. See `examples/serialize.cc`. _(hash map/set only)_ +- **Dump/load** feature: when a `flat` hash map stores data that is `std::trivially_copyable`, the table can be dumped to disk and restored as a single array, very efficiently, and without requiring any hash computation. This is typically about 10 times faster than doing element-wise serialization to disk, but it will use 10% to 60% extra disk space. See `examples/serialize.cc`. _(flat hash map/set only)_ - **Tested** on Windows (vs2015 & vs2017, vs2019, Intel compiler 18 and 19), linux (g++ 4.8.4, 5, 6, 7, 8, clang++ 3.9, 4.0, 5.0) and MacOS (g++ and clang++) - click on travis and appveyor icons above for detailed test status. diff --git a/parallel_hashmap/btree.h b/parallel_hashmap/btree.h index 0cb44a4..7c73162 100644 --- a/parallel_hashmap/btree.h +++ b/parallel_hashmap/btree.h @@ -54,25 +54,12 @@ #pragma warning(disable : 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified #endif -#include -#include -#include -#include -#include -#include #include #include #include -#include -#include #include #include -#include -#include -#include -#include -#include #include "phmap_fwd_decl.h" #include "phmap_base.h" diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 630dfee..880938b 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -3434,6 +3434,8 @@ public: return modify_if_impl(key, std::forward(f)); } + + template MappedReference

operator[](key_arg&& key) { return Policy::value(&*try_emplace(std::forward(key)).first); diff --git a/tests/parallel_hash_map_test.cc b/tests/parallel_hash_map_test.cc index fcac843..48241eb 100644 --- a/tests/parallel_hash_map_test.cc +++ b/tests/parallel_hash_map_test.cc @@ -13,13 +13,20 @@ 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 m = { {1, 7}, {2, 9} }; - auto val = 0; - - auto func = [&val](int& v) { val = v; }; - EXPECT_TRUE(m.if_contains(2, func)); + const ThisMap& const_m(m); + + auto val = 0; + auto get_value = [&val](const int& v) { val = v; }; + EXPECT_TRUE(const_m.if_contains(2, get_value)); EXPECT_EQ(val, 9); - EXPECT_FALSE(m.if_contains(3, func)); + EXPECT_FALSE(m.if_contains(3, get_value)); + + auto set_value = [&val](int& v) { v = 11; }; + EXPECT_TRUE(m. modify_if(2, set_value)); + EXPECT_EQ(m[2], 11); + + EXPECT_FALSE(m.modify_if(3, set_value)); } } // namespace