diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index b10a0e2..6185a61 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -3322,11 +3322,11 @@ public: // ---------------------------------------------------------------------------------------------------- template bool erase_if(const key_arg& key, F&& f) { - return erase_if_impl(key, std::forward(f)); + return !!erase_if_impl(key, std::forward(f)); } template - bool erase_if_impl(const key_arg& key, F&& f) { + size_type erase_if_impl(const key_arg& key, F&& f) { #if __cplusplus >= 201703L static_assert(std::is_invocable::value); #endif @@ -3336,19 +3336,19 @@ public: L m(inner); auto it = set.find(key, hashval); if (it == set.end()) - return false; + return 0; if (m.switch_to_unique()) { // we did an unlock/lock, need to call `find()` again it = set.find(key, hashval); if (it == set.end()) - return false; + return 0; } if (std::forward(f)(const_cast(*it))) { set._erase(it); - return true; + return 1; } - return false; + return 0; } // if map already contains key, the first lambda is called with the mapped value (under @@ -3462,19 +3462,8 @@ public: // -------------------------------------------------------------------- template size_type erase(const key_arg& key) { - auto hashval = this->hash(key); - Inner& inner = sets_[subidx(hashval)]; - auto& set = inner.set_; - typename Lockable::ReadWriteLock m(inner); - auto it = set.find(key, hashval); - if (it == set.end()) - return 0; - - if (m.switch_to_unique()) { - it = set.find(key, hashval); - } - set._erase(it); - return 1; + auto always_erase = [](const value_type&){ return true; }; + return erase_if_impl(key, std::move(always_erase)); } // --------------------------------------------------------------------