mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-30 00:50:38 +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));
|
||||
|
||||
Reference in New Issue
Block a user