mirror of
https://github.com/boostorg/unordered.git
synced 2026-05-05 12:14:18 +02:00
tested boost::concurrent_flat_set
This commit is contained in:
+107
-45
@@ -1,10 +1,12 @@
|
||||
// Copyright (C) 2023 Christian Mazakas
|
||||
// Copyright (C) 2023 Joaquin M Lopez Munoz
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||
#include <boost/unordered/concurrent_flat_set.hpp>
|
||||
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
|
||||
@@ -15,6 +17,9 @@ namespace {
|
||||
{
|
||||
template <class T, class X> void operator()(std::vector<T>& values, X& x)
|
||||
{
|
||||
static constexpr auto value_type_cardinality =
|
||||
value_cardinality<typename X::value_type>::value;
|
||||
|
||||
std::atomic<std::uint64_t> num_erased{0};
|
||||
auto const old_size = x.size();
|
||||
|
||||
@@ -26,11 +31,11 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor + raii::copy_constructor +
|
||||
raii::move_constructor,
|
||||
raii::destructor + 2 * x.size());
|
||||
raii::destructor + value_type_cardinality * x.size());
|
||||
|
||||
thread_runner(values, [&values, &num_erased, &x](boost::span<T>) {
|
||||
for (auto const& k : values) {
|
||||
auto count = x.erase(k.first);
|
||||
for (auto const& v : values) {
|
||||
auto count = x.erase(get_key(v));
|
||||
num_erased += count;
|
||||
BOOST_TEST_LE(count, 1u);
|
||||
BOOST_TEST_GE(count, 0u);
|
||||
@@ -41,7 +46,7 @@ namespace {
|
||||
BOOST_TEST_EQ(raii::copy_constructor, old_cc);
|
||||
BOOST_TEST_EQ(raii::move_constructor, old_mc);
|
||||
|
||||
BOOST_TEST_EQ(raii::destructor, old_d + 2 * old_size);
|
||||
BOOST_TEST_EQ(raii::destructor, old_d + value_type_cardinality * old_size);
|
||||
|
||||
BOOST_TEST_EQ(x.size(), 0u);
|
||||
BOOST_TEST(x.empty());
|
||||
@@ -53,6 +58,9 @@ namespace {
|
||||
{
|
||||
template <class T, class X> void operator()(std::vector<T>& values, X& x)
|
||||
{
|
||||
static constexpr auto value_type_cardinality =
|
||||
value_cardinality<typename X::value_type>::value;
|
||||
|
||||
std::atomic<std::uint64_t> num_erased{0};
|
||||
auto const old_size = x.size();
|
||||
|
||||
@@ -64,7 +72,7 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor + raii::copy_constructor +
|
||||
raii::move_constructor,
|
||||
raii::destructor + 2 * x.size());
|
||||
raii::destructor + value_type_cardinality * x.size());
|
||||
|
||||
thread_runner(values, [&num_erased, &x](boost::span<T> s) {
|
||||
for (auto const& k : s) {
|
||||
@@ -92,6 +100,15 @@ namespace {
|
||||
template <class T, class X> void operator()(std::vector<T>& values, X& x)
|
||||
{
|
||||
using value_type = typename X::value_type;
|
||||
static constexpr auto value_type_cardinality =
|
||||
value_cardinality<value_type>::value;
|
||||
|
||||
// concurrent_flat_set visit is always const access
|
||||
using arg_type = typename std::conditional<
|
||||
std::is_same<typename X::key_type, typename X::value_type>::value,
|
||||
typename X::value_type const,
|
||||
typename X::value_type
|
||||
>::type;
|
||||
|
||||
std::atomic<std::uint64_t> num_erased{0};
|
||||
|
||||
@@ -105,8 +122,8 @@ namespace {
|
||||
|
||||
auto max = 0;
|
||||
x.visit_all([&max](value_type const& v) {
|
||||
if (v.second.x_ > max) {
|
||||
max = v.second.x_;
|
||||
if (get_value(v).x_ > max) {
|
||||
max = get_value(v).x_;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -114,15 +131,15 @@ namespace {
|
||||
|
||||
auto expected_erasures = 0u;
|
||||
x.visit_all([&expected_erasures, threshold](value_type const& v) {
|
||||
if (v.second.x_ > threshold) {
|
||||
if (get_value(v).x_ > threshold) {
|
||||
++expected_erasures;
|
||||
}
|
||||
});
|
||||
|
||||
thread_runner(values, [&num_erased, &x, threshold](boost::span<T> s) {
|
||||
for (auto const& k : s) {
|
||||
auto count = x.erase_if(k.first,
|
||||
[threshold](value_type& v) { return v.second.x_ > threshold; });
|
||||
for (auto const& v : s) {
|
||||
auto count = x.erase_if(get_key(v),
|
||||
[threshold](arg_type& w) { return get_value(w).x_ > threshold; });
|
||||
num_erased += count;
|
||||
BOOST_TEST_LE(count, 1u);
|
||||
BOOST_TEST_GE(count, 0u);
|
||||
@@ -136,7 +153,8 @@ namespace {
|
||||
BOOST_TEST_EQ(raii::copy_constructor, old_cc);
|
||||
BOOST_TEST_EQ(raii::move_constructor, old_mc);
|
||||
|
||||
BOOST_TEST_EQ(raii::destructor, old_d + 2 * num_erased);
|
||||
BOOST_TEST_EQ(
|
||||
raii::destructor, old_d + value_type_cardinality * num_erased);
|
||||
}
|
||||
} lvalue_eraser_if;
|
||||
|
||||
@@ -145,6 +163,15 @@ namespace {
|
||||
template <class T, class X> void operator()(std::vector<T>& values, X& x)
|
||||
{
|
||||
using value_type = typename X::value_type;
|
||||
static constexpr auto value_type_cardinality =
|
||||
value_cardinality<value_type>::value;
|
||||
|
||||
// concurrent_flat_set visit is always const access
|
||||
using arg_type = typename std::conditional<
|
||||
std::is_same<typename X::key_type, typename X::value_type>::value,
|
||||
typename X::value_type const,
|
||||
typename X::value_type
|
||||
>::type;
|
||||
|
||||
std::atomic<std::uint64_t> num_erased{0};
|
||||
|
||||
@@ -158,8 +185,8 @@ namespace {
|
||||
|
||||
auto max = 0;
|
||||
x.visit_all([&max](value_type const& v) {
|
||||
if (v.second.x_ > max) {
|
||||
max = v.second.x_;
|
||||
if (get_value(v).x_ > max) {
|
||||
max = get_value(v).x_;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -167,15 +194,15 @@ namespace {
|
||||
|
||||
auto expected_erasures = 0u;
|
||||
x.visit_all([&expected_erasures, threshold](value_type const& v) {
|
||||
if (v.second.x_ > threshold) {
|
||||
if (get_value(v).x_ > threshold) {
|
||||
++expected_erasures;
|
||||
}
|
||||
});
|
||||
|
||||
thread_runner(values, [&num_erased, &x, threshold](boost::span<T> s) {
|
||||
for (auto const& k : s) {
|
||||
auto count = x.erase_if(k.first.x_,
|
||||
[threshold](value_type& v) { return v.second.x_ > threshold; });
|
||||
for (auto const& v : s) {
|
||||
auto count = x.erase_if(get_key(v).x_,
|
||||
[threshold](arg_type& w) { return get_value(w).x_ > threshold; });
|
||||
num_erased += count;
|
||||
BOOST_TEST_LE(count, 1u);
|
||||
BOOST_TEST_GE(count, 0u);
|
||||
@@ -189,7 +216,8 @@ namespace {
|
||||
BOOST_TEST_EQ(raii::copy_constructor, old_cc);
|
||||
BOOST_TEST_EQ(raii::move_constructor, old_mc);
|
||||
|
||||
BOOST_TEST_EQ(raii::destructor, old_d + 2 * num_erased);
|
||||
BOOST_TEST_EQ(
|
||||
raii::destructor, old_d + value_type_cardinality * num_erased);
|
||||
}
|
||||
} transp_lvalue_eraser_if;
|
||||
|
||||
@@ -198,6 +226,15 @@ namespace {
|
||||
template <class T, class X> void operator()(std::vector<T>& values, X& x)
|
||||
{
|
||||
using value_type = typename X::value_type;
|
||||
static constexpr auto value_type_cardinality =
|
||||
value_cardinality<value_type>::value;
|
||||
|
||||
// concurrent_flat_set visit is always const access
|
||||
using arg_type = typename std::conditional<
|
||||
std::is_same<typename X::key_type, typename X::value_type>::value,
|
||||
typename X::value_type const,
|
||||
typename X::value_type
|
||||
>::type;
|
||||
|
||||
std::atomic<std::uint64_t> num_erased{0};
|
||||
|
||||
@@ -211,8 +248,8 @@ namespace {
|
||||
|
||||
auto max = 0;
|
||||
x.visit_all([&max](value_type const& v) {
|
||||
if (v.second.x_ > max) {
|
||||
max = v.second.x_;
|
||||
if (get_value(v).x_ > max) {
|
||||
max = get_value(v).x_;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -220,7 +257,7 @@ namespace {
|
||||
|
||||
auto expected_erasures = 0u;
|
||||
x.visit_all([&expected_erasures, threshold](value_type const& v) {
|
||||
if (v.second.x_ > threshold) {
|
||||
if (get_value(v).x_ > threshold) {
|
||||
++expected_erasures;
|
||||
}
|
||||
});
|
||||
@@ -229,7 +266,7 @@ namespace {
|
||||
values, [&num_erased, &x, threshold](boost::span<T> /* s */) {
|
||||
for (std::size_t i = 0; i < 128; ++i) {
|
||||
auto count = x.erase_if(
|
||||
[threshold](value_type& v) { return v.second.x_ > threshold; });
|
||||
[threshold](arg_type& v) { return get_value(v).x_ > threshold; });
|
||||
num_erased += count;
|
||||
}
|
||||
});
|
||||
@@ -241,7 +278,8 @@ namespace {
|
||||
BOOST_TEST_EQ(raii::copy_constructor, old_cc);
|
||||
BOOST_TEST_EQ(raii::move_constructor, old_mc);
|
||||
|
||||
BOOST_TEST_EQ(raii::destructor, old_d + 2 * num_erased);
|
||||
BOOST_TEST_EQ(
|
||||
raii::destructor, old_d + value_type_cardinality * num_erased);
|
||||
}
|
||||
} erase_if;
|
||||
|
||||
@@ -250,6 +288,15 @@ namespace {
|
||||
template <class T, class X> void operator()(std::vector<T>& values, X& x)
|
||||
{
|
||||
using value_type = typename X::value_type;
|
||||
static constexpr auto value_type_cardinality =
|
||||
value_cardinality<value_type>::value;
|
||||
|
||||
// concurrent_flat_set visit is always const access
|
||||
using arg_type = typename std::conditional<
|
||||
std::is_same<typename X::key_type, typename X::value_type>::value,
|
||||
typename X::value_type const,
|
||||
typename X::value_type
|
||||
>::type;
|
||||
|
||||
std::atomic<std::uint64_t> num_erased{0};
|
||||
|
||||
@@ -263,8 +310,8 @@ namespace {
|
||||
|
||||
auto max = 0;
|
||||
x.visit_all([&max](value_type const& v) {
|
||||
if (v.second.x_ > max) {
|
||||
max = v.second.x_;
|
||||
if (get_value(v).x_ > max) {
|
||||
max = get_value(v).x_;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -272,7 +319,7 @@ namespace {
|
||||
|
||||
auto expected_erasures = 0u;
|
||||
x.visit_all([&expected_erasures, threshold](value_type const& v) {
|
||||
if (v.second.x_ > threshold) {
|
||||
if (get_value(v).x_ > threshold) {
|
||||
++expected_erasures;
|
||||
}
|
||||
});
|
||||
@@ -281,7 +328,8 @@ namespace {
|
||||
values, [&num_erased, &x, threshold](boost::span<T> /* s */) {
|
||||
for (std::size_t i = 0; i < 128; ++i) {
|
||||
auto count = boost::unordered::erase_if(x,
|
||||
[threshold](value_type& v) { return v.second.x_ > threshold; });
|
||||
[threshold](arg_type& v) {
|
||||
return get_value(v).x_ > threshold; });
|
||||
num_erased += count;
|
||||
}
|
||||
});
|
||||
@@ -293,7 +341,8 @@ namespace {
|
||||
BOOST_TEST_EQ(raii::copy_constructor, old_cc);
|
||||
BOOST_TEST_EQ(raii::move_constructor, old_mc);
|
||||
|
||||
BOOST_TEST_EQ(raii::destructor, old_d + 2 * num_erased);
|
||||
BOOST_TEST_EQ(
|
||||
raii::destructor, old_d + value_type_cardinality * num_erased);
|
||||
}
|
||||
} free_fn_erase_if;
|
||||
|
||||
@@ -303,6 +352,15 @@ namespace {
|
||||
{
|
||||
#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
|
||||
using value_type = typename X::value_type;
|
||||
static constexpr auto value_type_cardinality =
|
||||
value_cardinality<value_type>::value;
|
||||
|
||||
// concurrent_flat_set visit is always const access
|
||||
using arg_type = typename std::conditional<
|
||||
std::is_same<typename X::key_type, typename X::value_type>::value,
|
||||
typename X::value_type const,
|
||||
typename X::value_type
|
||||
>::type;
|
||||
|
||||
std::atomic<std::uint64_t> num_invokes{0};
|
||||
|
||||
@@ -316,8 +374,8 @@ namespace {
|
||||
|
||||
auto max = 0;
|
||||
x.visit_all([&max](value_type const& v) {
|
||||
if (v.second.x_ > max) {
|
||||
max = v.second.x_;
|
||||
if (get_value(v).x_ > max) {
|
||||
max = get_value(v).x_;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -325,7 +383,7 @@ namespace {
|
||||
|
||||
auto expected_erasures = 0u;
|
||||
x.visit_all([&expected_erasures, threshold](value_type const& v) {
|
||||
if (v.second.x_ > threshold) {
|
||||
if (get_value(v).x_ > threshold) {
|
||||
++expected_erasures;
|
||||
}
|
||||
});
|
||||
@@ -333,9 +391,9 @@ namespace {
|
||||
thread_runner(values, [&num_invokes, &x, threshold](boost::span<T> s) {
|
||||
(void)s;
|
||||
x.erase_if(
|
||||
std::execution::par, [&num_invokes, threshold](value_type& v) {
|
||||
std::execution::par, [&num_invokes, threshold](arg_type& v) {
|
||||
++num_invokes;
|
||||
return v.second.x_ > threshold;
|
||||
return get_value(v).x_ > threshold;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -346,7 +404,8 @@ namespace {
|
||||
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);
|
||||
BOOST_TEST_EQ(
|
||||
raii::destructor, old_d + value_type_cardinality * expected_erasures);
|
||||
#else
|
||||
(void)values;
|
||||
(void)x;
|
||||
@@ -354,12 +413,12 @@ namespace {
|
||||
}
|
||||
} erase_if_exec_policy;
|
||||
|
||||
template <class X, class G, class F>
|
||||
void erase(X*, G gen, F eraser, test::random_generator rg)
|
||||
template <class X, class GF, class F>
|
||||
void erase(X*, GF gen_factory, F eraser, test::random_generator rg)
|
||||
{
|
||||
auto gen = gen_factory.template get<X>();
|
||||
auto values = make_random_values(1024 * 16, [&] { return gen(rg); });
|
||||
auto reference_map =
|
||||
boost::unordered_flat_map<raii, raii>(values.begin(), values.end());
|
||||
auto reference_cont = reference_container<X>(values.begin(), values.end());
|
||||
raii::reset_counts();
|
||||
|
||||
{
|
||||
@@ -367,20 +426,23 @@ namespace {
|
||||
|
||||
x.insert(values.begin(), values.end());
|
||||
|
||||
BOOST_TEST_EQ(x.size(), reference_map.size());
|
||||
BOOST_TEST_EQ(x.size(), reference_cont.size());
|
||||
|
||||
test_fuzzy_matches_reference(x, reference_map, rg);
|
||||
test_fuzzy_matches_reference(x, reference_cont, rg);
|
||||
|
||||
eraser(values, x);
|
||||
test_fuzzy_matches_reference(x, reference_map, rg);
|
||||
test_fuzzy_matches_reference(x, reference_cont, rg);
|
||||
}
|
||||
|
||||
check_raii_counts();
|
||||
}
|
||||
|
||||
boost::unordered::concurrent_flat_map<raii, raii>* map;
|
||||
boost::unordered::concurrent_flat_set<raii>* set;
|
||||
boost::unordered::concurrent_flat_map<raii, raii, transp_hash,
|
||||
transp_key_equal>* transparent_map;
|
||||
boost::unordered::concurrent_flat_map<raii, transp_hash,
|
||||
transp_key_equal>* transparent_set;
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -391,15 +453,15 @@ using test::sequential;
|
||||
// clang-format off
|
||||
UNORDERED_TEST(
|
||||
erase,
|
||||
((map))
|
||||
((value_type_generator)(init_type_generator))
|
||||
((map)(set))
|
||||
((value_type_generator_factory)(init_type_generator_factory))
|
||||
((lvalue_eraser)(lvalue_eraser_if)(erase_if)(free_fn_erase_if)(erase_if_exec_policy))
|
||||
((default_generator)(sequential)(limited_range)))
|
||||
|
||||
UNORDERED_TEST(
|
||||
erase,
|
||||
((transparent_map))
|
||||
((value_type_generator)(init_type_generator))
|
||||
((value_type_generator_factory)(init_type_generator_factory))
|
||||
((transp_lvalue_eraser)(transp_lvalue_eraser_if)(erase_if_exec_policy))
|
||||
((default_generator)(sequential)(limited_range)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user