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
+10
View File
@@ -3408,6 +3408,16 @@ public:
return true;
}
template <class K = key_type, class F>
bool if_contains(const key_arg<K>& key, F&& f) {
typename Lockable::SharedLock m;
auto it = const_cast<parallel_hash_map*>(this)->find(key, hash(key), m);
if (it == this->end())
return false;
std::forward<F>(f)(Policy::value(&*it));
return true;
}
template <class K = key_type, class P = Policy, K* = nullptr>
MappedReference<P> operator[](key_arg<K>&& key) {
return Policy::value(&*try_emplace(std::forward<K>(key)).first);