diff --git a/include/boost/unordered/detail/foa/concurrent_table.hpp b/include/boost/unordered/detail/foa/concurrent_table.hpp index 550a3e28..8e41d185 100644 --- a/include/boost/unordered/detail/foa/concurrent_table.hpp +++ b/include/boost/unordered/detail/foa/concurrent_table.hpp @@ -799,6 +799,34 @@ public: return erase_if(x,[](const value_type&){return true;}); } +#if defined(BOOST_UNORDERED_LATCH_FREE) + template + BOOST_FORCEINLINE auto erase_if(const Key& x,F&& f)->typename std::enable_if< + !is_execution_policy::value,std::size_t>::type + { + auto lck=shared_access(); + auto hash=this->hash_for(x); + std::size_t res=0; + unprotected_internal_visit( + group_shared{},x,this->position_for(hash),hash, + [&,this](group_type* pg,unsigned int n,element_type* p) + { + auto expected=group_type::reduced_hash(hash); + if(reinterpret_cast*>(pg)[n]. + compare_exchange_strong(expected,1)){ + if(f(cast_for(group_shared{},type_policy::value_from(*p)))){ + wait_for_epochs(); + super::erase(pg,n,p); + res=1; + } + else{ + pg->set(n,expected); + } + } + }); + return res; + } +#else template BOOST_FORCEINLINE auto erase_if(const Key& x,F&& f)->typename std::enable_if< !is_execution_policy::value,std::size_t>::type @@ -817,6 +845,7 @@ public: }); return res; } +#endif template std::size_t erase_if(F&& f) @@ -1825,7 +1854,7 @@ private: void wait_for_epochs() { for(std::size_t i=0;i1){} } } #endif diff --git a/include/boost/unordered/detail/foa/core.hpp b/include/boost/unordered/detail/foa/core.hpp index 0ffbfc03..6a8f1eb9 100644 --- a/include/boost/unordered/detail/foa/core.hpp +++ b/include/boost/unordered/detail/foa/core.hpp @@ -382,11 +382,13 @@ private: return (int)word[narrow_cast(hash)]; } +public: inline static unsigned char reduced_hash(std::size_t hash) { return narrow_cast(match_word(hash)); } +private: inline slot_type& at(std::size_t pos) { return m[pos]; @@ -532,6 +534,7 @@ private: #endif } +public: inline static unsigned char reduced_hash(std::size_t hash) { static constexpr unsigned char table[]={ @@ -556,6 +559,7 @@ private: return table[(unsigned char)hash]; } +private: /* Copied from * https://github.com/simd-everywhere/simde/blob/master/simde/x86/ * sse2.h#L3763