mirror of
https://github.com/boostorg/unordered.git
synced 2026-04-29 10:13:31 +02:00
Feature/concurrent node containers (#271)
* added concurrent node containers
* removed spurious typename
* added missing includes
* avoided unused param warning
* worked around Clang bug
* s/{}/() to work around GCC4.8 problems with aggregate initialization
* used /bigobj for cfoa/visit_tests.cpp
* suppressed localized maybe-uninitialized warnings
* fixed comments
* added /bigobj to cfoa/insert_tests.cpp
* instrumented double exact comparison to spot a spurious error
* fixed pedantic error
* refactored byte_span machinery
* compromised on sub-epsilon equality for doubles that should be identical
* documented boost::concurrent_node_(map|set)
* added concurrent_node_set
* added missing AlternativeType
* tested empty node insertion
* tested node_handle allocator management
* added nonassignable_allocator and node_handle_allocator_swap_tests
* fixed warning disabling
* silenced spurious GCC warning
* broadened scope of previous pragma
* broadened even more
* worked around spurious constexpr-related msvc-14.0 bug
https://godbolt.org/z/v78545Ebf
* added workaround back
* replaced previous workaround with built-in one
* added workaround back on top of built-in solution (which doesn't work 100% of the time)
This commit is contained in:
+100
-21
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2023 Christian Mazakas
|
||||
// Copyright (C) 2023 Joaquin M Lopez Munoz
|
||||
// Copyright (C) 2023-2024 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)
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||
#include <boost/unordered/concurrent_flat_set.hpp>
|
||||
#include <boost/unordered/concurrent_node_map.hpp>
|
||||
#include <boost/unordered/concurrent_node_set.hpp>
|
||||
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
|
||||
@@ -179,8 +181,15 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor, 0u);
|
||||
BOOST_TEST_EQ(raii::copy_constructor, 2 * x.size());
|
||||
// don't check move construction count here because of rehashing
|
||||
BOOST_TEST_GT(raii::move_constructor, 0u);
|
||||
|
||||
if (is_container_node_based<X>::value) {
|
||||
BOOST_TEST_EQ(raii::move_constructor, 0u);
|
||||
}
|
||||
else{
|
||||
// don't check move construction count here because of rehashing
|
||||
BOOST_TEST_GT(raii::move_constructor, 0u);
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(raii::copy_assignment, values.size() - x.size());
|
||||
BOOST_TEST_EQ(raii::move_assignment, 0u);
|
||||
}
|
||||
@@ -198,7 +207,14 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor, 0u);
|
||||
BOOST_TEST_EQ(raii::copy_constructor, x.size());
|
||||
BOOST_TEST_GT(raii::move_constructor, x.size()); // rehashing
|
||||
|
||||
if (is_container_node_based<X>::value) {
|
||||
BOOST_TEST_EQ(raii::move_constructor, x.size());
|
||||
}
|
||||
else{
|
||||
BOOST_TEST_GT(raii::move_constructor, x.size()); // rehashing
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(raii::copy_assignment, 0u);
|
||||
BOOST_TEST_EQ(raii::move_assignment, values.size() - x.size());
|
||||
}
|
||||
@@ -216,7 +232,14 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor, 0u);
|
||||
BOOST_TEST_EQ(raii::copy_constructor, x.size());
|
||||
BOOST_TEST_GT(raii::move_constructor, x.size()); // rehashing
|
||||
|
||||
if (is_container_node_based<X>::value) {
|
||||
BOOST_TEST_EQ(raii::move_constructor, x.size());
|
||||
}
|
||||
else{
|
||||
BOOST_TEST_GT(raii::move_constructor, x.size()); // rehashing
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(raii::copy_assignment, values.size() - x.size());
|
||||
BOOST_TEST_EQ(raii::move_assignment, 0u);
|
||||
}
|
||||
@@ -234,7 +257,14 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor, 0u);
|
||||
BOOST_TEST_EQ(raii::copy_constructor, 0u);
|
||||
BOOST_TEST_GE(raii::move_constructor, 2 * x.size());
|
||||
|
||||
if (is_container_node_based<X>::value) {
|
||||
BOOST_TEST_EQ(raii::move_constructor, 2 * x.size());
|
||||
}
|
||||
else{
|
||||
BOOST_TEST_GE(raii::move_constructor, 2 * x.size()); // rehashing
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(raii::copy_assignment, 0u);
|
||||
BOOST_TEST_EQ(raii::move_assignment, values.size() - x.size());
|
||||
}
|
||||
@@ -260,7 +290,14 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor, x.size());
|
||||
BOOST_TEST_EQ(raii::copy_constructor, x.size());
|
||||
BOOST_TEST_GT(raii::move_constructor, x.size()); // rehashing
|
||||
|
||||
if (is_container_node_based<X>::value) {
|
||||
BOOST_TEST_EQ(raii::move_constructor, 0u);
|
||||
}
|
||||
else{
|
||||
BOOST_TEST_GT(raii::move_constructor, 0u); // rehashing
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(raii::copy_assignment, values.size() - x.size());
|
||||
BOOST_TEST_EQ(raii::move_assignment, 0u);
|
||||
}
|
||||
@@ -284,7 +321,14 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor, x.size());
|
||||
BOOST_TEST_EQ(raii::copy_constructor, 0u);
|
||||
BOOST_TEST_GT(raii::move_constructor, 2 * x.size()); // rehashing
|
||||
|
||||
if (is_container_node_based<X>::value) {
|
||||
BOOST_TEST_EQ(raii::move_constructor, x.size());
|
||||
}
|
||||
else{
|
||||
BOOST_TEST_GT(raii::move_constructor, x.size()); // rehashing
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(raii::copy_assignment, 0u);
|
||||
BOOST_TEST_EQ(raii::move_assignment, values.size() - x.size());
|
||||
}
|
||||
@@ -319,8 +363,15 @@ namespace {
|
||||
BOOST_TEST_EQ(raii::default_constructor, 0u);
|
||||
BOOST_TEST_EQ(
|
||||
raii::copy_constructor, value_type_cardinality * x.size());
|
||||
// don't check move construction count here because of rehashing
|
||||
BOOST_TEST_GT(raii::move_constructor, 0u);
|
||||
|
||||
if (is_container_node_based<X>::value) {
|
||||
BOOST_TEST_EQ(raii::move_constructor, 0u);
|
||||
}
|
||||
else{
|
||||
// don't check move construction count here because of rehashing
|
||||
BOOST_TEST_GT(raii::move_constructor, 0u);
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(raii::move_assignment, 0u);
|
||||
}
|
||||
} lvalue_insert_or_cvisit;
|
||||
@@ -360,8 +411,15 @@ namespace {
|
||||
|
||||
BOOST_TEST_EQ(raii::default_constructor, 0u);
|
||||
BOOST_TEST_EQ(raii::copy_constructor, value_type_cardinality * x.size());
|
||||
// don't check move construction count here because of rehashing
|
||||
BOOST_TEST_GT(raii::move_constructor, 0u);
|
||||
|
||||
if (is_container_node_based<X>::value) {
|
||||
BOOST_TEST_EQ(raii::move_constructor, 0u);
|
||||
}
|
||||
else{
|
||||
// don't check move construction count here because of rehashing
|
||||
BOOST_TEST_GT(raii::move_constructor, 0u);
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(raii::move_assignment, 0u);
|
||||
}
|
||||
} lvalue_insert_or_visit;
|
||||
@@ -665,12 +723,14 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST (insert_sfinae_test) {
|
||||
|
||||
template <class X>
|
||||
void insert_map_sfinae_test(X*)
|
||||
{
|
||||
// mostly a compile-time tests to ensure that there's no ambiguity when a
|
||||
// user does this
|
||||
using value_type =
|
||||
typename boost::unordered::concurrent_flat_map<raii, raii>::value_type;
|
||||
boost::unordered::concurrent_flat_map<raii, raii> x;
|
||||
using value_type = typename X::value_type;
|
||||
X x;
|
||||
x.insert({1, 2});
|
||||
|
||||
x.insert_or_visit({2, 3}, [](value_type&) {});
|
||||
@@ -684,11 +744,23 @@ namespace {
|
||||
std::equal_to<raii>, fancy_allocator<std::pair<raii const, raii> > >*
|
||||
fancy_map;
|
||||
|
||||
boost::unordered::concurrent_node_map<raii, raii>* node_map;
|
||||
boost::unordered::concurrent_node_map<raii, raii, transp_hash,
|
||||
transp_key_equal>* trans_node_map;
|
||||
boost::unordered::concurrent_node_map<raii, raii, boost::hash<raii>,
|
||||
std::equal_to<raii>, fancy_allocator<std::pair<raii const, raii> > >*
|
||||
fancy_node_map;
|
||||
|
||||
boost::unordered::concurrent_flat_set<raii>* set;
|
||||
boost::unordered::concurrent_flat_set<raii, boost::hash<raii>,
|
||||
std::equal_to<raii>, fancy_allocator<std::pair<raii const, raii> > >*
|
||||
std::equal_to<raii>, fancy_allocator<raii> >*
|
||||
fancy_set;
|
||||
|
||||
boost::unordered::concurrent_node_set<raii>* node_set;
|
||||
boost::unordered::concurrent_node_set<raii, boost::hash<raii>,
|
||||
std::equal_to<raii>, fancy_allocator<raii> >*
|
||||
fancy_node_set;
|
||||
|
||||
std::initializer_list<std::pair<raii const, raii> > map_init_list{
|
||||
{raii{0}, raii{0}},
|
||||
{raii{1}, raii{1}},
|
||||
@@ -740,7 +812,9 @@ namespace {
|
||||
};
|
||||
|
||||
auto map_and_init_list=std::make_pair(map,map_init_list);
|
||||
auto node_map_and_init_list=std::make_pair(node_map,map_init_list);
|
||||
auto set_and_init_list=std::make_pair(set,set_init_list);
|
||||
auto node_set_and_init_list=std::make_pair(node_set,set_init_list);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -751,11 +825,12 @@ using test::sequential;
|
||||
// clang-format off
|
||||
UNORDERED_TEST(
|
||||
insert_initializer_list,
|
||||
((map_and_init_list)(set_and_init_list)))
|
||||
((map_and_init_list)(node_map_and_init_list)(set_and_init_list)))
|
||||
|
||||
UNORDERED_TEST(
|
||||
insert,
|
||||
((map)(fancy_map)(set)(fancy_set))
|
||||
((map)(fancy_map)(node_map)(fancy_node_map)
|
||||
(set)(fancy_set)(node_set)(fancy_node_set))
|
||||
((value_type_generator_factory)(init_type_generator_factory))
|
||||
((lvalue_inserter)(rvalue_inserter)(iterator_range_inserter)
|
||||
(norehash_lvalue_inserter)(norehash_rvalue_inserter)
|
||||
@@ -766,7 +841,7 @@ UNORDERED_TEST(
|
||||
|
||||
UNORDERED_TEST(
|
||||
insert,
|
||||
((map))
|
||||
((map)(node_map))
|
||||
((init_type_generator_factory))
|
||||
((lvalue_insert_or_assign_copy_assign)(lvalue_insert_or_assign_move_assign)
|
||||
(rvalue_insert_or_assign_copy_assign)(rvalue_insert_or_assign_move_assign))
|
||||
@@ -774,10 +849,14 @@ UNORDERED_TEST(
|
||||
|
||||
UNORDERED_TEST(
|
||||
insert,
|
||||
((trans_map))
|
||||
((trans_map)(trans_node_map))
|
||||
((init_type_generator_factory))
|
||||
((trans_insert_or_assign_copy_assign)(trans_insert_or_assign_move_assign))
|
||||
((default_generator)(sequential)(limited_range)))
|
||||
|
||||
UNORDERED_TEST(
|
||||
insert_map_sfinae_test,
|
||||
((map)(node_map)))
|
||||
// clang-format on
|
||||
|
||||
RUN_TESTS()
|
||||
|
||||
Reference in New Issue
Block a user