From f6337521ab7df4f76c3c7f1e8d30bba94696023a Mon Sep 17 00:00:00 2001 From: Colin Gaudreau Date: Fri, 7 Aug 2020 13:08:45 -0500 Subject: [PATCH 1/3] Added `modify_if` method - Added method to safely modify a value in a map using the UniqueLock. --- parallel_hashmap/phmap.h | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index f1b7996..630dfee 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -3222,11 +3222,11 @@ private: } protected: - template - iterator find(const key_arg& key, size_t hashval, typename Lockable::SharedLock &mutexlock) { + template + iterator find(const key_arg& key, size_t hashval, L &mutexlock) { Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - mutexlock = std::move(typename Lockable::SharedLock(inner)); + mutexlock = std::move(L(inner)); auto it = set.find(key, hashval); return make_iterator(&inner, it); } @@ -3426,15 +3426,12 @@ public: template bool if_contains(const key_arg& key, F&& f) const { -#if __cplusplus >= 201703L - static_assert(std::is_invocable::value); -#endif - typename Lockable::SharedLock m; - auto it = const_cast(this)->find(key, this->hash(key), m); - if (it == this->end()) - return false; - std::forward(f)(Policy::value(&*it)); - return true; + return const_cast(this)->if_modify_impl(key, std::forward(f)); + } + + template + bool modify_if(const key_arg& key, F&& f) { + return modify_if_impl(key, std::forward(f)); } template @@ -3448,6 +3445,19 @@ public: } private: + template + bool modify_if_impl(const key_arg& key, F&& f) { +#if __cplusplus >= 201703L + static_assert(std::is_invocable::value); +#endif + L m; + auto it = find(key, this->hash(key), m); + if (it == this->end()) + return false; + std::forward(f)(Policy::value(&*it)); + return true; + } + template std::pair insert_or_assign_impl(K&& k, V&& v) { typename Lockable::UniqueLock m; From 9baa437c3f1178e3d8919fc167bcf03a9e0f1757 Mon Sep 17 00:00:00 2001 From: Colin Gaudreau Date: Sun, 9 Aug 2020 21:48:07 -0500 Subject: [PATCH 2/3] Fixed merge with upstream to work on gcc --- parallel_hashmap/phmap.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 880938b..1e57971 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -244,7 +244,7 @@ static_assert(kEmpty == -128, "existence efficient (psignb xmm, xmm)"); static_assert(~kEmpty & ~kDeleted & kSentinel & 0x7F, "kEmpty and kDeleted must share an unset bit that is not shared " - "by kSentinel to make the scalar test for MatchEmptyOrDeleted() " + "by kSentinel to make the scalar test for MatchEmptyOrDceleted() " "efficient"); static_assert(kDeleted == -2, "kDeleted must be -2 to make the implementation of " @@ -3222,7 +3222,7 @@ private: } protected: - template + template iterator find(const key_arg& key, size_t hashval, L &mutexlock) { Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; @@ -3426,16 +3426,14 @@ public: template bool if_contains(const key_arg& key, F&& f) const { - return const_cast(this)->if_modify_impl(key, std::forward(f)); + return const_cast(this)->template modify_if_impl(key, std::forward(f)); } template bool modify_if(const key_arg& key, F&& f) { - return modify_if_impl(key, std::forward(f)); + return modify_if_impl(key, std::forward(f)); } - - template MappedReference

operator[](key_arg&& key) { return Policy::value(&*try_emplace(std::forward(key)).first); @@ -3453,7 +3451,7 @@ private: static_assert(std::is_invocable::value); #endif L m; - auto it = find(key, this->hash(key), m); + auto it = this->template find(key, this->hash(key), m); if (it == this->end()) return false; std::forward(f)(Policy::value(&*it)); From edc886bcda33cac2b04867c04f1e5321b766b953 Mon Sep 17 00:00:00 2001 From: Colin Gaudreau Date: Sun, 9 Aug 2020 21:51:07 -0500 Subject: [PATCH 3/3] Fixed accidental typo. --- parallel_hashmap/phmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 1e57971..7cf22b3 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -244,7 +244,7 @@ static_assert(kEmpty == -128, "existence efficient (psignb xmm, xmm)"); static_assert(~kEmpty & ~kDeleted & kSentinel & 0x7F, "kEmpty and kDeleted must share an unset bit that is not shared " - "by kSentinel to make the scalar test for MatchEmptyOrDceleted() " + "by kSentinel to make the scalar test for MatchEmptyOrDeleted() " "efficient"); static_assert(kDeleted == -2, "kDeleted must be -2 to make the implementation of "