forked from boostorg/unordered
Add ExecutionPolicy overload of erase_if
This commit is contained in:
@ -41,6 +41,23 @@
|
||||
namespace boost{
|
||||
namespace unordered{
|
||||
namespace detail{
|
||||
|
||||
#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
|
||||
|
||||
template<typename ExecutionPolicy>
|
||||
using is_execution_policy=std::is_execution_policy<
|
||||
typename std::remove_cv<
|
||||
typename std::remove_reference<ExecutionPolicy>::type
|
||||
>::type
|
||||
>;
|
||||
|
||||
#else
|
||||
|
||||
template<typename ExecutionPolicy>
|
||||
using is_execution_policy=std::false_type;
|
||||
|
||||
#endif
|
||||
|
||||
namespace foa{
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
@ -277,18 +294,6 @@ class concurrent_table:
|
||||
using super::N;
|
||||
using prober=typename super::prober;
|
||||
|
||||
#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
|
||||
template<typename ExecutionPolicy>
|
||||
using is_execution_policy=std::is_execution_policy<
|
||||
typename std::remove_cv<
|
||||
typename std::remove_reference<ExecutionPolicy>::type
|
||||
>::type
|
||||
>;
|
||||
#else
|
||||
template<typename ExecutionPolicy>
|
||||
using is_execution_policy=std::false_type;
|
||||
#endif
|
||||
|
||||
public:
|
||||
using key_type=typename super::key_type;
|
||||
using init_type=typename super::init_type;
|
||||
@ -1060,7 +1065,7 @@ private:
|
||||
last=first+this->arrays.groups_size_mask+1;
|
||||
std::for_each(std::forward<ExecutionPolicy>(policy),first,last,
|
||||
[&,this](group_type& g){
|
||||
std::size_t pos=&g-first;
|
||||
std::size_t pos=static_cast<std::size_t>(&g-first);
|
||||
auto p=this->arrays.elements+pos*N;
|
||||
auto lck=access(access_mode,pos);
|
||||
auto mask=this->match_really_occupied(&g,last);
|
||||
|
@ -245,6 +245,63 @@ namespace {
|
||||
}
|
||||
} erase_if;
|
||||
|
||||
struct erase_if_exec_policy_type
|
||||
{
|
||||
template <class T, class X> void operator()(std::vector<T>& values, X& x)
|
||||
{
|
||||
#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
|
||||
using value_type = typename X::value_type;
|
||||
|
||||
std::atomic<std::uint64_t> num_invokes{0};
|
||||
|
||||
auto const old_size = x.size();
|
||||
|
||||
auto const old_dc = +raii::default_constructor;
|
||||
auto const old_cc = +raii::copy_constructor;
|
||||
auto const old_mc = +raii::move_constructor;
|
||||
|
||||
auto const old_d = +raii::destructor;
|
||||
|
||||
auto max = 0;
|
||||
x.visit_all([&max](value_type const& v) {
|
||||
if (v.second.x_ > max) {
|
||||
max = v.second.x_;
|
||||
}
|
||||
});
|
||||
|
||||
auto threshold = max / 2;
|
||||
|
||||
auto expected_erasures = 0u;
|
||||
x.visit_all([&expected_erasures, threshold](value_type const& v) {
|
||||
if (v.second.x_ > threshold) {
|
||||
++expected_erasures;
|
||||
}
|
||||
});
|
||||
|
||||
thread_runner(values, [&num_invokes, &x, threshold](boost::span<T> s) {
|
||||
(void)s;
|
||||
x.erase_if(
|
||||
std::execution::par_unseq, [&num_invokes, threshold](value_type& v) {
|
||||
++num_invokes;
|
||||
return v.second.x_ > threshold;
|
||||
});
|
||||
});
|
||||
|
||||
BOOST_TEST_GE(+num_invokes, old_size);
|
||||
BOOST_TEST_LE(+num_invokes, old_size * num_threads);
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor, old_dc);
|
||||
BOOST_TEST_EQ(raii::copy_constructor, old_cc);
|
||||
BOOST_TEST_EQ(raii::move_constructor, old_mc);
|
||||
|
||||
BOOST_TEST_EQ(raii::destructor, old_d + 2 * expected_erasures);
|
||||
#else
|
||||
(void)values;
|
||||
(void)x;
|
||||
#endif
|
||||
}
|
||||
} erase_if_exec_policy;
|
||||
|
||||
template <class X, class G, class F>
|
||||
void erase(X*, G gen, F eraser, test::random_generator rg)
|
||||
{
|
||||
@ -296,14 +353,14 @@ UNORDERED_TEST(
|
||||
erase,
|
||||
((map))
|
||||
((value_type_generator)(init_type_generator))
|
||||
((lvalue_eraser)(lvalue_eraser_if)(erase_if))
|
||||
((lvalue_eraser)(lvalue_eraser_if)(erase_if)(erase_if_exec_policy))
|
||||
((default_generator)(sequential)(limited_range)))
|
||||
|
||||
UNORDERED_TEST(
|
||||
erase,
|
||||
((transparent_map))
|
||||
((value_type_generator)(init_type_generator))
|
||||
((transp_lvalue_eraser)(transp_lvalue_eraser_if))
|
||||
((transp_lvalue_eraser)(transp_lvalue_eraser_if)(erase_if_exec_policy))
|
||||
((default_generator)(sequential)(limited_range)))
|
||||
|
||||
// clang-format on
|
||||
|
Reference in New Issue
Block a user