2023-04-06 13:42:57 -07:00
|
|
|
// Copyright (C) 2023 Christian Mazakas
|
2023-09-10 18:35:51 +02:00
|
|
|
// Copyright (C) 2023 Joaquin M Lopez Munoz
|
2023-04-06 13:42:57 -07:00
|
|
|
// 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>
|
2023-09-10 18:35:51 +02:00
|
|
|
#include <boost/unordered/concurrent_flat_set.hpp>
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
#include <boost/core/ignore_unused.hpp>
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
#include <array>
|
2023-04-06 13:42:57 -07:00
|
|
|
#include <functional>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
test::seed_t initialize_seed(335740237);
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto non_present_keys = []
|
|
|
|
|
{
|
|
|
|
|
std::array<raii,128> a;
|
|
|
|
|
for(std::size_t i = 0; i < a.size(); ++i) {
|
|
|
|
|
a[i].x_ = -((int)i + 1);
|
|
|
|
|
}
|
|
|
|
|
return a;
|
|
|
|
|
}();
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
raii const & get_non_present_key(T const & x)
|
|
|
|
|
{
|
2023-09-11 09:54:16 +02:00
|
|
|
return non_present_keys[
|
|
|
|
|
(std::size_t)get_key(x).x_ % non_present_keys.size()];
|
2023-09-10 18:35:51 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-06 13:42:57 -07:00
|
|
|
struct lvalue_visitor_type
|
|
|
|
|
{
|
2023-04-07 12:39:39 -07:00
|
|
|
template <class T, class X, class M>
|
2023-09-10 18:35:51 +02:00
|
|
|
void operator()(std::vector<T>& values, X& x, M const& reference_cont)
|
2023-04-06 13:42:57 -07:00
|
|
|
{
|
|
|
|
|
using value_type = typename X::value_type;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
// 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;
|
|
|
|
|
|
2023-04-06 13:42:57 -07:00
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
std::atomic<std::uint64_t> total_count{0};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto mut_visitor = [&num_visits, &reference_cont](arg_type& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-04-07 12:39:39 -07:00
|
|
|
++num_visits;
|
2023-04-06 13:42:57 -07:00
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto const_visitor =
|
|
|
|
|
[&num_visits, &reference_cont](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-04-07 12:39:39 -07:00
|
|
|
++num_visits;
|
2023-04-06 13:42:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(
|
|
|
|
|
values, [&x, &mut_visitor, &total_count](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-04-10 10:17:05 +02:00
|
|
|
BOOST_TEST(r >= 0);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = x.visit(get_key(val), mut_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
BOOST_TEST_EQ(count, 1u);
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
count = x.visit(get_non_present_key(val), mut_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(num_visits, values.size());
|
|
|
|
|
BOOST_TEST_EQ(total_count, values.size());
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(
|
|
|
|
|
values, [&x, &const_visitor, &total_count](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-04-10 10:17:05 +02:00
|
|
|
BOOST_TEST(r >= 0);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
auto const& y = x;
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = y.visit(get_key(val), const_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(count, 1u);
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
count = y.visit(get_non_present_key(val), const_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(num_visits, values.size());
|
|
|
|
|
BOOST_TEST_EQ(total_count, values.size());
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(
|
|
|
|
|
values, [&x, &const_visitor, &total_count](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-04-10 10:17:05 +02:00
|
|
|
BOOST_TEST(r >= 0);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = x.cvisit(get_key(val), const_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(count, 1u);
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
count = x.cvisit(get_non_present_key(val), const_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(num_visits, values.size());
|
|
|
|
|
BOOST_TEST_EQ(total_count, values.size());
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
2023-05-05 15:41:23 -07:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &total_count](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST(r >= 0);
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = x.count(get_key(val));
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST_EQ(count, 1u);
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
count = x.count(get_non_present_key(val));
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(total_count, values.size());
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST(r >= 0);
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto contains = x.contains(get_key(val));
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST(contains);
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
contains = x.contains(get_non_present_key(val));
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST(!contains);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
2023-04-06 13:42:57 -07:00
|
|
|
}
|
|
|
|
|
} lvalue_visitor;
|
|
|
|
|
|
|
|
|
|
struct transp_visitor_type
|
|
|
|
|
{
|
2023-04-07 12:39:39 -07:00
|
|
|
template <class T, class X, class M>
|
2023-09-10 18:35:51 +02:00
|
|
|
void operator()(std::vector<T>& values, X& x, M const& reference_cont)
|
2023-04-06 13:42:57 -07:00
|
|
|
{
|
|
|
|
|
using value_type = typename X::value_type;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
// 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;
|
|
|
|
|
|
2023-04-06 13:42:57 -07:00
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
std::atomic<std::uint64_t> total_count{0};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto mut_visitor = [&num_visits, &reference_cont](arg_type& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-04-07 12:39:39 -07:00
|
|
|
++num_visits;
|
2023-04-06 13:42:57 -07:00
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto const_visitor = [&num_visits, &reference_cont](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-04-07 12:39:39 -07:00
|
|
|
++num_visits;
|
2023-04-06 13:42:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(
|
|
|
|
|
values, [&x, &mut_visitor, &total_count](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-04-10 10:17:05 +02:00
|
|
|
BOOST_TEST(r >= 0);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = x.visit(get_key(val).x_, mut_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(count, 1u);
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
count = x.visit(get_non_present_key(val).x_, mut_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(num_visits, values.size());
|
|
|
|
|
BOOST_TEST_EQ(total_count, values.size());
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(
|
|
|
|
|
values, [&x, &const_visitor, &total_count](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-04-10 10:17:05 +02:00
|
|
|
BOOST_TEST(r >= 0);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
auto const& y = x;
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = y.visit(get_key(val).x_, const_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(count, 1u);
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
count = y.visit(get_non_present_key(val).x_, const_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(num_visits, values.size());
|
|
|
|
|
BOOST_TEST_EQ(total_count, values.size());
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(
|
|
|
|
|
values, [&x, &const_visitor, &total_count](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-04-10 10:17:05 +02:00
|
|
|
BOOST_TEST(r >= 0);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = x.cvisit(get_key(val).x_, const_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(count, 1u);
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
count = x.cvisit(get_non_present_key(val).x_, const_visitor);
|
2023-04-06 13:42:57 -07:00
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(num_visits, values.size());
|
|
|
|
|
BOOST_TEST_EQ(total_count, values.size());
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
2023-05-05 15:41:23 -07:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &total_count](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST(r >= 0);
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = x.count(get_key(val).x_);
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST_EQ(count, 1u);
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
count = x.count(get_non_present_key(val).x_);
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(total_count, values.size());
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x](boost::span<T> s) {
|
|
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto r = get_key(val).x_;
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST(r >= 0);
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto contains = x.contains(get_key(val).x_);
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST(contains);
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
contains = x.contains(get_non_present_key(val).x_);
|
2023-05-05 15:41:23 -07:00
|
|
|
BOOST_TEST(!contains);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
num_visits = 0;
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
2023-04-06 13:42:57 -07:00
|
|
|
}
|
|
|
|
|
} transp_visitor;
|
|
|
|
|
|
2023-04-07 12:39:39 -07:00
|
|
|
struct visit_all_type
|
|
|
|
|
{
|
|
|
|
|
template <class T, class X, class M>
|
2023-09-10 18:35:51 +02:00
|
|
|
void operator()(std::vector<T>& values, X& x, M const& reference_cont)
|
2023-04-07 12:39:39 -07:00
|
|
|
{
|
|
|
|
|
using value_type = typename X::value_type;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
// 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;
|
|
|
|
|
|
2023-04-07 12:39:39 -07:00
|
|
|
std::atomic<std::uint64_t> total_count{0};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto mut_visitor = [&reference_cont](std::atomic<uint64_t>& num_visits) {
|
|
|
|
|
return [&reference_cont, &num_visits](arg_type& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-04-07 12:39:39 -07:00
|
|
|
++num_visits;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto const_visitor = [&reference_cont](std::atomic<uint64_t>& num_visits) {
|
|
|
|
|
return [&reference_cont, &num_visits](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-04-07 12:39:39 -07:00
|
|
|
++num_visits;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &total_count, &mut_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
total_count += x.visit_all(mut_visitor(num_visits));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(total_count, num_threads * x.size());
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(
|
|
|
|
|
values, [&x, &total_count, &const_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
auto const& y = x;
|
|
|
|
|
total_count += y.visit_all(const_visitor(num_visits));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(total_count, num_threads * x.size());
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(
|
|
|
|
|
values, [&x, &total_count, &const_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
total_count += x.cvisit_all(const_visitor(num_visits));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(total_count, num_threads * x.size());
|
|
|
|
|
total_count = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} visit_all;
|
|
|
|
|
|
2023-07-26 10:14:11 -07:00
|
|
|
struct visit_while_type
|
|
|
|
|
{
|
|
|
|
|
template <class T, class X, class M>
|
2023-09-10 18:35:51 +02:00
|
|
|
void operator()(std::vector<T>& values, X& x, M const& reference_cont)
|
2023-07-26 10:14:11 -07:00
|
|
|
{
|
|
|
|
|
using value_type = typename X::value_type;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
auto mut_truthy_visitor = [&reference_cont](
|
2023-07-26 10:14:11 -07:00
|
|
|
std::atomic<uint64_t>& num_visits) {
|
2023-09-10 18:35:51 +02:00
|
|
|
return [&reference_cont, &num_visits](arg_type& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-07-26 10:14:11 -07:00
|
|
|
++num_visits;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto const_truthy_visitor = [&reference_cont](
|
2023-07-26 10:14:11 -07:00
|
|
|
std::atomic<uint64_t>& num_visits) {
|
2023-09-10 18:35:51 +02:00
|
|
|
return [&reference_cont, &num_visits](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-07-26 10:14:11 -07:00
|
|
|
++num_visits;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto mut_falsey_visitor = [&reference_cont](
|
2023-07-26 10:14:11 -07:00
|
|
|
std::atomic<uint64_t>& num_visits) {
|
2023-09-10 18:35:51 +02:00
|
|
|
return [&reference_cont, &num_visits](arg_type& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
2023-07-26 10:14:11 -07:00
|
|
|
++num_visits;
|
2023-09-10 18:35:51 +02:00
|
|
|
return (get_value(v).x_ % 100) == 0;
|
2023-07-26 10:14:11 -07:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto const_falsey_visitor = [&reference_cont](
|
2023-07-26 10:14:11 -07:00
|
|
|
std::atomic<uint64_t>& num_visits) {
|
2023-09-10 18:35:51 +02:00
|
|
|
return [&reference_cont, &num_visits](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
2023-07-26 10:14:11 -07:00
|
|
|
++num_visits;
|
2023-09-10 18:35:51 +02:00
|
|
|
return (get_value(v).x_ % 100) == 0;
|
2023-07-26 10:14:11 -07:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &mut_truthy_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
BOOST_TEST(x.visit_while(mut_truthy_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_truthy_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
auto const& y = x;
|
|
|
|
|
BOOST_TEST(y.visit_while(const_truthy_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_truthy_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
BOOST_TEST(x.cvisit_while(const_truthy_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &mut_falsey_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
BOOST_TEST_NOT(x.visit_while(mut_falsey_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_LT(num_visits, x.size());
|
|
|
|
|
BOOST_TEST_GT(num_visits, 0u);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_falsey_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
auto const& y = x;
|
|
|
|
|
BOOST_TEST_NOT(y.visit_while(const_falsey_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_LT(num_visits, x.size());
|
|
|
|
|
BOOST_TEST_GT(num_visits, 0u);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_falsey_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
BOOST_TEST_NOT(x.cvisit_while(const_falsey_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_LT(num_visits, x.size());
|
|
|
|
|
BOOST_TEST_GT(num_visits, 0u);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} visit_while;
|
|
|
|
|
|
2023-04-07 12:39:39 -07:00
|
|
|
struct exec_policy_visit_all_type
|
|
|
|
|
{
|
|
|
|
|
template <class T, class X, class M>
|
2023-09-10 18:35:51 +02:00
|
|
|
void operator()(std::vector<T>& values, X& x, M const& reference_cont)
|
2023-04-07 12:39:39 -07:00
|
|
|
{
|
|
|
|
|
#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
|
|
|
|
|
using value_type = typename X::value_type;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
auto mut_visitor = [&reference_cont](std::atomic<uint64_t>& num_visits) {
|
|
|
|
|
return [&reference_cont, &num_visits](arg_type& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-04-07 12:39:39 -07:00
|
|
|
++num_visits;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto const_visitor = [&reference_cont](std::atomic<uint64_t>& num_visits) {
|
|
|
|
|
return [&reference_cont, &num_visits](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-04-07 12:39:39 -07:00
|
|
|
++num_visits;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &mut_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
|
2023-05-01 11:04:50 -07:00
|
|
|
x.visit_all(std::execution::par, mut_visitor(num_visits));
|
2023-04-07 12:39:39 -07:00
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
auto const& y = x;
|
|
|
|
|
|
2023-05-01 11:04:50 -07:00
|
|
|
y.visit_all(std::execution::par, const_visitor(num_visits));
|
2023-04-07 12:39:39 -07:00
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
2023-05-01 11:04:50 -07:00
|
|
|
x.cvisit_all(std::execution::par, const_visitor(num_visits));
|
2023-04-07 12:39:39 -07:00
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
(void)values;
|
|
|
|
|
(void)x;
|
2023-09-10 18:35:51 +02:00
|
|
|
(void)reference_cont;
|
2023-04-07 12:39:39 -07:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
} exec_policy_visit_all;
|
|
|
|
|
|
2023-07-26 10:14:11 -07:00
|
|
|
struct exec_policy_visit_while_type
|
|
|
|
|
{
|
|
|
|
|
template <class T, class X, class M>
|
2023-09-10 18:35:51 +02:00
|
|
|
void operator()(std::vector<T>& values, X& x, M const& reference_cont)
|
2023-07-26 10:14:11 -07:00
|
|
|
{
|
|
|
|
|
#if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS)
|
|
|
|
|
using value_type = typename X::value_type;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
auto mut_truthy_visitor = [&reference_cont](
|
2023-07-26 10:14:11 -07:00
|
|
|
std::atomic<uint64_t>& num_visits) {
|
2023-09-10 18:35:51 +02:00
|
|
|
return [&reference_cont, &num_visits](arg_type& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-07-26 10:14:11 -07:00
|
|
|
++num_visits;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto const_truthy_visitor = [&reference_cont](
|
2023-07-26 10:14:11 -07:00
|
|
|
std::atomic<uint64_t>& num_visits) {
|
2023-09-10 18:35:51 +02:00
|
|
|
return [&reference_cont, &num_visits](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-07-26 10:14:11 -07:00
|
|
|
++num_visits;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto mut_falsey_visitor = [&reference_cont](
|
2023-07-26 10:14:11 -07:00
|
|
|
std::atomic<uint64_t>& num_visits) {
|
2023-09-10 18:35:51 +02:00
|
|
|
return [&reference_cont, &num_visits](arg_type& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-07-26 10:14:11 -07:00
|
|
|
++num_visits;
|
2023-09-10 18:35:51 +02:00
|
|
|
return (get_value(v).x_ % 100) == 0;
|
2023-07-26 10:14:11 -07:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto const_falsey_visitor = [&reference_cont](
|
2023-07-26 10:14:11 -07:00
|
|
|
std::atomic<uint64_t>& num_visits) {
|
2023-09-10 18:35:51 +02:00
|
|
|
return [&reference_cont, &num_visits](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
2023-07-26 10:14:11 -07:00
|
|
|
++num_visits;
|
2023-09-10 18:35:51 +02:00
|
|
|
return (get_value(v).x_ % 100) == 0;
|
2023-07-26 10:14:11 -07:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &mut_truthy_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
BOOST_TEST(
|
|
|
|
|
x.visit_while(std::execution::par, mut_truthy_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_truthy_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
auto const& y = x;
|
|
|
|
|
BOOST_TEST(y.visit_while(
|
|
|
|
|
std::execution::par, const_truthy_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_truthy_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
BOOST_TEST(x.cvisit_while(
|
|
|
|
|
std::execution::par, const_truthy_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_EQ(x.size(), num_visits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &mut_falsey_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
BOOST_TEST_NOT(
|
|
|
|
|
x.visit_while(std::execution::par, mut_falsey_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_LT(num_visits, x.size());
|
|
|
|
|
BOOST_TEST_GT(num_visits, 0u);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_falsey_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
auto const& y = x;
|
|
|
|
|
BOOST_TEST_NOT(y.visit_while(
|
|
|
|
|
std::execution::par, const_falsey_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_LT(num_visits, x.size());
|
|
|
|
|
BOOST_TEST_GT(num_visits, 0u);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
thread_runner(values, [&x, &const_falsey_visitor](boost::span<T>) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
|
|
|
|
BOOST_TEST_NOT(x.cvisit_while(
|
|
|
|
|
std::execution::par, const_falsey_visitor(num_visits)));
|
|
|
|
|
BOOST_TEST_LT(num_visits, x.size());
|
|
|
|
|
BOOST_TEST_GT(num_visits, 0u);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
(void)values;
|
|
|
|
|
(void)x;
|
2023-09-10 18:35:51 +02:00
|
|
|
(void)reference_cont;
|
2023-07-26 10:14:11 -07:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
} exec_policy_visit_while;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <class X, class GF, class F>
|
|
|
|
|
void visit(X*, GF gen_factory, F visitor, test::random_generator rg)
|
2023-04-06 13:42:57 -07:00
|
|
|
{
|
2023-09-10 18:35:51 +02:00
|
|
|
auto gen = gen_factory.template get<X>();
|
2023-04-06 13:42:57 -07:00
|
|
|
auto values = make_random_values(1024 * 16, [&] { return gen(rg); });
|
2023-09-10 18:35:51 +02:00
|
|
|
auto reference_cont = reference_container<X>(values.begin(), values.end());
|
2023-05-05 15:41:23 -07:00
|
|
|
|
2023-04-06 13:42:57 -07:00
|
|
|
raii::reset_counts();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
X x;
|
|
|
|
|
for (auto const& v : values) {
|
|
|
|
|
x.insert(v);
|
|
|
|
|
}
|
2023-09-10 18:35:51 +02:00
|
|
|
BOOST_TEST_EQ(x.size(), reference_cont.size());
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
std::uint64_t old_default_constructor = raii::default_constructor;
|
|
|
|
|
std::uint64_t old_copy_constructor = raii::copy_constructor;
|
|
|
|
|
std::uint64_t old_move_constructor = raii::move_constructor;
|
|
|
|
|
std::uint64_t old_copy_assignment = raii::copy_assignment;
|
|
|
|
|
std::uint64_t old_move_assignment = raii::move_assignment;
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
visitor(values, x, reference_cont);
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(old_default_constructor, raii::default_constructor);
|
|
|
|
|
BOOST_TEST_EQ(old_copy_constructor, raii::copy_constructor);
|
|
|
|
|
BOOST_TEST_EQ(old_move_constructor, raii::move_constructor);
|
|
|
|
|
BOOST_TEST_EQ(old_copy_assignment, raii::copy_assignment);
|
|
|
|
|
BOOST_TEST_EQ(old_move_assignment, raii::move_assignment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_GE(raii::default_constructor, 0u);
|
|
|
|
|
BOOST_TEST_GE(raii::copy_constructor, 0u);
|
|
|
|
|
BOOST_TEST_GE(raii::move_constructor, 0u);
|
|
|
|
|
BOOST_TEST_GT(raii::destructor, 0u);
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(raii::default_constructor + raii::copy_constructor +
|
|
|
|
|
raii::move_constructor,
|
|
|
|
|
raii::destructor);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <class X, class GF>
|
|
|
|
|
void empty_visit(X*, GF gen_factory, test::random_generator rg)
|
2023-04-12 12:23:16 -07:00
|
|
|
{
|
2023-09-10 18:35:51 +02:00
|
|
|
auto gen = gen_factory.template get<X>();
|
2023-04-12 12:23:16 -07:00
|
|
|
auto values = make_random_values(1024 * 16, [&] { return gen(rg); });
|
2023-04-18 12:30:34 -07:00
|
|
|
using values_type = decltype(values);
|
|
|
|
|
using span_value_type = typename values_type::value_type;
|
|
|
|
|
|
2023-04-12 12:23:16 -07:00
|
|
|
raii::reset_counts();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
X x;
|
|
|
|
|
|
|
|
|
|
std::uint64_t old_default_constructor = raii::default_constructor;
|
|
|
|
|
std::uint64_t old_copy_constructor = raii::copy_constructor;
|
|
|
|
|
std::uint64_t old_move_constructor = raii::move_constructor;
|
|
|
|
|
std::uint64_t old_copy_assignment = raii::copy_assignment;
|
|
|
|
|
std::uint64_t old_move_assignment = raii::move_assignment;
|
|
|
|
|
|
|
|
|
|
{
|
2023-04-18 12:30:34 -07:00
|
|
|
thread_runner(values, [&x](boost::span<span_value_type> s) {
|
|
|
|
|
std::atomic<std::uint64_t> num_visits{0};
|
2023-04-12 12:23:16 -07:00
|
|
|
|
2023-04-18 12:30:34 -07:00
|
|
|
x.visit_all(
|
|
|
|
|
[&num_visits](typename X::value_type const&) { ++num_visits; });
|
|
|
|
|
BOOST_TEST_EQ(num_visits, 0u);
|
2023-04-12 12:23:16 -07:00
|
|
|
|
2023-04-18 12:30:34 -07:00
|
|
|
for (auto const& val : s) {
|
2023-09-10 18:35:51 +02:00
|
|
|
auto count = x.visit(get_key(val),
|
2023-04-18 12:30:34 -07:00
|
|
|
[&num_visits](typename X::value_type const&) { ++num_visits; });
|
|
|
|
|
BOOST_TEST_EQ(count, 0u);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-04-12 12:23:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(old_default_constructor, raii::default_constructor);
|
|
|
|
|
BOOST_TEST_EQ(old_copy_constructor, raii::copy_constructor);
|
|
|
|
|
BOOST_TEST_EQ(old_move_constructor, raii::move_constructor);
|
|
|
|
|
BOOST_TEST_EQ(old_copy_assignment, raii::copy_assignment);
|
|
|
|
|
BOOST_TEST_EQ(old_move_assignment, raii::move_assignment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_TEST_EQ(raii::default_constructor, 0u);
|
|
|
|
|
BOOST_TEST_EQ(raii::copy_constructor, 0u);
|
|
|
|
|
BOOST_TEST_EQ(raii::move_constructor, 0u);
|
|
|
|
|
BOOST_TEST_EQ(raii::destructor, 0u);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <class X, class GF>
|
|
|
|
|
void insert_and_visit(X*, GF gen_factory, test::random_generator rg)
|
2023-05-03 10:28:19 -07:00
|
|
|
{
|
|
|
|
|
// here we attempt to ensure happens-before and synchronizes-with
|
|
|
|
|
// the visitation thread essentially chases the insertion one
|
|
|
|
|
// we double-check unreloated loads/stores to ensure that a store is visible
|
|
|
|
|
// in the visitation thread
|
|
|
|
|
|
|
|
|
|
BOOST_TEST(rg == test::sequential);
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
auto gen = gen_factory.template get<X>();
|
2023-05-03 10:28:19 -07:00
|
|
|
auto const values = make_random_values(1024 * 16, [&] { return gen(rg); });
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
raii::reset_counts();
|
|
|
|
|
|
|
|
|
|
X x;
|
|
|
|
|
|
|
|
|
|
std::thread t1, t2;
|
2023-06-26 10:32:52 +03:00
|
|
|
boost::compat::latch l(2);
|
2023-05-03 10:28:19 -07:00
|
|
|
std::vector<std::string> strs(values.size());
|
|
|
|
|
|
|
|
|
|
t1 = std::thread([&l, &values, &x, &strs] {
|
|
|
|
|
l.arrive_and_wait();
|
|
|
|
|
for (std::size_t idx = 0; idx < values.size(); ++idx) {
|
|
|
|
|
strs[idx] = "rawr";
|
|
|
|
|
auto const& val = values[idx];
|
|
|
|
|
x.insert(val);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
t2 = std::thread([&l, &values, &x, &strs] {
|
|
|
|
|
l.arrive_and_wait();
|
|
|
|
|
|
|
|
|
|
for (std::size_t idx = 0; idx < values.size(); ++idx) {
|
|
|
|
|
std::atomic_bool b{false};
|
|
|
|
|
while (!b) {
|
2023-09-10 18:35:51 +02:00
|
|
|
x.cvisit(get_key(values[idx]),
|
2023-05-03 10:28:19 -07:00
|
|
|
[&b, &strs, idx, &values](typename X::value_type const& v) {
|
2023-09-10 18:35:51 +02:00
|
|
|
BOOST_TEST_EQ(get_value(v), get_value(values[idx]));
|
2023-05-03 10:28:19 -07:00
|
|
|
BOOST_TEST_EQ(strs[idx], "rawr");
|
|
|
|
|
b = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
t1.join();
|
|
|
|
|
t2.join();
|
|
|
|
|
}
|
|
|
|
|
check_raii_counts();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-06 13:42:57 -07:00
|
|
|
boost::unordered::concurrent_flat_map<raii, raii>* map;
|
|
|
|
|
boost::unordered::concurrent_flat_map<raii, raii, transp_hash,
|
|
|
|
|
transp_key_equal>* transp_map;
|
2023-09-10 18:35:51 +02:00
|
|
|
boost::unordered::concurrent_flat_set<raii>* set;
|
|
|
|
|
boost::unordered::concurrent_flat_set<raii, transp_hash,
|
|
|
|
|
transp_key_equal>* transp_set;
|
2023-04-06 13:42:57 -07:00
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
using test::default_generator;
|
|
|
|
|
using test::limited_range;
|
|
|
|
|
using test::sequential;
|
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
|
|
|
|
|
UNORDERED_TEST(
|
|
|
|
|
visit,
|
2023-09-10 18:35:51 +02:00
|
|
|
((map)(set))
|
|
|
|
|
((value_type_generator_factory)(init_type_generator_factory))
|
|
|
|
|
((lvalue_visitor)(visit_all)(visit_while)(exec_policy_visit_all)
|
|
|
|
|
(exec_policy_visit_while))
|
2023-04-06 13:42:57 -07:00
|
|
|
((default_generator)(sequential)(limited_range)))
|
|
|
|
|
|
|
|
|
|
UNORDERED_TEST(
|
|
|
|
|
visit,
|
2023-09-10 18:35:51 +02:00
|
|
|
((transp_map)(transp_set))
|
|
|
|
|
((value_type_generator_factory)(init_type_generator_factory))
|
2023-04-06 13:42:57 -07:00
|
|
|
((transp_visitor))
|
|
|
|
|
((default_generator)(sequential)(limited_range)))
|
|
|
|
|
|
2023-04-12 12:23:16 -07:00
|
|
|
UNORDERED_TEST(
|
|
|
|
|
empty_visit,
|
2023-09-10 18:35:51 +02:00
|
|
|
((map)(transp_map)(set)(transp_set))
|
|
|
|
|
((value_type_generator_factory)(init_type_generator_factory))
|
2023-04-12 12:23:16 -07:00
|
|
|
((default_generator)(sequential)(limited_range))
|
|
|
|
|
)
|
|
|
|
|
|
2023-05-03 10:28:19 -07:00
|
|
|
UNORDERED_TEST(
|
|
|
|
|
insert_and_visit,
|
2023-09-10 18:35:51 +02:00
|
|
|
((map)(set))
|
|
|
|
|
((value_type_generator_factory))
|
2023-05-03 10:28:19 -07:00
|
|
|
((sequential))
|
|
|
|
|
)
|
|
|
|
|
|
2023-04-06 13:42:57 -07:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
RUN_TESTS()
|