2023-09-10 18:35:51 +02:00
|
|
|
// Copyright (C) 2023 Christian Mazakas
|
2024-08-25 18:34:58 +02:00
|
|
|
// Copyright (C) 2023-2024 Joaquin M Lopez Munoz
|
2023-09-10 18:35:51 +02: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)
|
2024-08-25 18:34:58 +02:00
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
#ifndef BOOST_UNORDERED_TEST_CFOA_COMMON_HELPERS_HPP
|
|
|
|
|
#define BOOST_UNORDERED_TEST_CFOA_COMMON_HELPERS_HPP
|
|
|
|
|
|
|
|
|
|
#include <boost/unordered/concurrent_flat_map_fwd.hpp>
|
|
|
|
|
#include <boost/unordered/concurrent_flat_set_fwd.hpp>
|
2024-08-25 18:34:58 +02:00
|
|
|
#include <boost/unordered/concurrent_node_map_fwd.hpp>
|
|
|
|
|
#include <boost/unordered/concurrent_node_set_fwd.hpp>
|
2023-09-10 18:35:51 +02:00
|
|
|
#include <boost/unordered/unordered_flat_map.hpp>
|
|
|
|
|
#include <boost/unordered/unordered_flat_set.hpp>
|
2024-08-25 18:34:58 +02:00
|
|
|
#include <boost/unordered/unordered_node_map.hpp>
|
|
|
|
|
#include <boost/unordered/unordered_node_set.hpp>
|
2023-09-10 18:35:51 +02:00
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
|
|
template <typename K>
|
|
|
|
|
struct value_cardinality
|
|
|
|
|
{
|
|
|
|
|
static constexpr std::size_t value=1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename K, typename V>
|
|
|
|
|
struct value_cardinality<std::pair<K, V> >
|
|
|
|
|
{
|
|
|
|
|
static constexpr std::size_t value=2;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-25 18:34:58 +02:00
|
|
|
template <typename K>
|
|
|
|
|
struct value_nonconst_cardinality
|
|
|
|
|
{
|
|
|
|
|
static constexpr std::size_t value=1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename K, typename V>
|
|
|
|
|
struct value_nonconst_cardinality<std::pair<K, V> >
|
|
|
|
|
{
|
|
|
|
|
static constexpr std::size_t value=
|
|
|
|
|
1 * !std::is_const<K>::value +
|
|
|
|
|
1 * !std::is_const<V>::value ;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <class Container>
|
|
|
|
|
struct is_container_node_based: std::false_type {};
|
|
|
|
|
|
|
|
|
|
template <typename K, typename V, typename H, typename P, typename A>
|
|
|
|
|
struct is_container_node_based<boost::concurrent_node_map<K, V, H, P, A> >
|
|
|
|
|
: std::true_type {};
|
|
|
|
|
|
|
|
|
|
template <typename K, typename H, typename P, typename A>
|
|
|
|
|
struct is_container_node_based<boost::concurrent_node_set<K, H, P, A> >
|
|
|
|
|
: std::true_type {};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <class Container>
|
|
|
|
|
struct reference_container_impl;
|
|
|
|
|
|
|
|
|
|
template <class Container>
|
|
|
|
|
using reference_container = typename reference_container_impl<Container>::type;
|
|
|
|
|
|
|
|
|
|
template <typename K, typename V, typename H, typename P, typename A>
|
|
|
|
|
struct reference_container_impl<boost::concurrent_flat_map<K, V, H, P, A> >
|
|
|
|
|
{
|
|
|
|
|
using type = boost::unordered_flat_map<K, V>;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-25 18:34:58 +02:00
|
|
|
template <typename K, typename V, typename H, typename P, typename A>
|
|
|
|
|
struct reference_container_impl<boost::concurrent_node_map<K, V, H, P, A> >
|
|
|
|
|
{
|
|
|
|
|
using type = boost::unordered_node_map<K, V>;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <typename K, typename H, typename P, typename A>
|
|
|
|
|
struct reference_container_impl<boost::concurrent_flat_set<K, H, P, A> >
|
|
|
|
|
{
|
|
|
|
|
using type = boost::unordered_flat_set<K>;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-25 18:34:58 +02:00
|
|
|
template <typename K, typename H, typename P, typename A>
|
|
|
|
|
struct reference_container_impl<boost::concurrent_node_set<K, H, P, A> >
|
|
|
|
|
{
|
|
|
|
|
using type = boost::unordered_node_set<K>;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <class Container>
|
2024-08-25 18:34:58 +02:00
|
|
|
struct nonconcurrent_container_impl;
|
2023-09-10 18:35:51 +02:00
|
|
|
|
|
|
|
|
template <class Container>
|
2024-08-25 18:34:58 +02:00
|
|
|
using nonconcurrent_container =
|
|
|
|
|
typename nonconcurrent_container_impl<Container>::type;
|
2023-09-10 18:35:51 +02:00
|
|
|
|
|
|
|
|
template <typename K, typename V, typename H, typename P, typename A>
|
2024-08-25 18:34:58 +02:00
|
|
|
struct nonconcurrent_container_impl<boost::concurrent_flat_map<K, V, H, P, A> >
|
2023-09-10 18:35:51 +02:00
|
|
|
{
|
|
|
|
|
using type = boost::unordered_flat_map<K, V, H, P, A>;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-25 18:34:58 +02:00
|
|
|
template <typename K, typename V, typename H, typename P, typename A>
|
|
|
|
|
struct nonconcurrent_container_impl<boost::concurrent_node_map<K, V, H, P, A> >
|
|
|
|
|
{
|
|
|
|
|
using type = boost::unordered_node_map<K, V, H, P, A>;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <typename K, typename H, typename P, typename A>
|
2024-08-25 18:34:58 +02:00
|
|
|
struct nonconcurrent_container_impl<boost::concurrent_flat_set<K, H, P, A> >
|
2023-09-10 18:35:51 +02:00
|
|
|
{
|
|
|
|
|
using type = boost::unordered_flat_set<K, H, P, A>;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-25 18:34:58 +02:00
|
|
|
template <typename K, typename H, typename P, typename A>
|
|
|
|
|
struct nonconcurrent_container_impl<boost::concurrent_node_set<K, H, P, A> >
|
|
|
|
|
{
|
|
|
|
|
using type = boost::unordered_node_set<K, H, P, A>;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <typename Container, template <typename> class Allocator>
|
|
|
|
|
struct replace_allocator_impl;
|
|
|
|
|
|
|
|
|
|
template <typename Container, template <typename> class Allocator>
|
|
|
|
|
using replace_allocator =
|
|
|
|
|
typename replace_allocator_impl<Container, Allocator>::type;
|
|
|
|
|
|
|
|
|
|
template <
|
|
|
|
|
typename K, typename V, typename H, typename P, typename A,
|
|
|
|
|
template <typename> class Allocator
|
|
|
|
|
>
|
|
|
|
|
struct replace_allocator_impl<
|
|
|
|
|
boost::concurrent_flat_map<K, V, H, P, A>, Allocator>
|
|
|
|
|
{
|
|
|
|
|
using value_type =
|
|
|
|
|
typename boost::concurrent_flat_map<K, V, H, P, A>::value_type;
|
|
|
|
|
using type =
|
|
|
|
|
boost::concurrent_flat_map<K, V, H, P, Allocator<value_type> >;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <
|
|
|
|
|
typename K, typename H, typename P, typename A,
|
|
|
|
|
template <typename> class Allocator
|
|
|
|
|
>
|
|
|
|
|
struct replace_allocator_impl<
|
|
|
|
|
boost::concurrent_flat_set<K, H, P, A>, Allocator>
|
|
|
|
|
{
|
|
|
|
|
using value_type =
|
|
|
|
|
typename boost::concurrent_flat_set<K, H, P, A>::value_type;
|
|
|
|
|
using type =
|
|
|
|
|
boost::concurrent_flat_set<K, H, P, Allocator<value_type> >;
|
|
|
|
|
};
|
2024-08-25 18:34:58 +02:00
|
|
|
|
|
|
|
|
template <
|
|
|
|
|
typename K, typename V, typename H, typename P, typename A,
|
|
|
|
|
template <typename> class Allocator
|
|
|
|
|
>
|
|
|
|
|
struct replace_allocator_impl<
|
|
|
|
|
boost::concurrent_node_map<K, V, H, P, A>, Allocator>
|
|
|
|
|
{
|
|
|
|
|
using value_type =
|
|
|
|
|
typename boost::concurrent_node_map<K, V, H, P, A>::value_type;
|
|
|
|
|
using type =
|
|
|
|
|
boost::concurrent_node_map<K, V, H, P, Allocator<value_type> >;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <
|
|
|
|
|
typename K, typename H, typename P, typename A,
|
|
|
|
|
template <typename> class Allocator
|
|
|
|
|
>
|
|
|
|
|
struct replace_allocator_impl<
|
|
|
|
|
boost::concurrent_node_set<K, H, P, A>, Allocator>
|
|
|
|
|
{
|
|
|
|
|
using value_type =
|
|
|
|
|
typename boost::concurrent_node_set<K, H, P, A>::value_type;
|
|
|
|
|
using type =
|
|
|
|
|
boost::concurrent_node_set<K, H, P, Allocator<value_type> >;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-10 18:35:51 +02:00
|
|
|
template <typename K>
|
|
|
|
|
K const& get_key(K const& x) { return x; }
|
|
|
|
|
|
|
|
|
|
template <typename K,typename V>
|
|
|
|
|
K const& get_key(const std::pair<K, V>& x) { return x.first; }
|
|
|
|
|
|
|
|
|
|
template <typename K>
|
|
|
|
|
K const& get_value(K const& x) { return x; }
|
|
|
|
|
|
|
|
|
|
template <typename K,typename V>
|
|
|
|
|
V const& get_value(const std::pair<K, V>& x) { return x.second; }
|
|
|
|
|
|
|
|
|
|
template <typename K,typename V>
|
|
|
|
|
V& get_value(std::pair<K, V>& x) { return x.second; }
|
|
|
|
|
|
|
|
|
|
template <class X, class Y>
|
|
|
|
|
void test_matches_reference(X const& x, Y const& reference_cont)
|
|
|
|
|
{
|
|
|
|
|
using value_type = typename X::value_type;
|
|
|
|
|
BOOST_TEST_EQ(x.size(), x.visit_all([&](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class X, class Y>
|
|
|
|
|
void test_fuzzy_matches_reference(
|
|
|
|
|
X const& x, Y const& reference_cont, test::random_generator rg)
|
|
|
|
|
{
|
|
|
|
|
using value_type = typename X::value_type;
|
|
|
|
|
BOOST_TEST_EQ(x.size(), x.visit_all([&](value_type const& v) {
|
|
|
|
|
BOOST_TEST(reference_cont.contains(get_key(v)));
|
|
|
|
|
if (rg == test::sequential) {
|
|
|
|
|
BOOST_TEST_EQ(v, *reference_cont.find(get_key(v)));
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // BOOST_UNORDERED_TEST_CFOA_COMMON_HELPERS_HPP
|