2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
// Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard.
|
|
|
|
// Copyright (C) 2005-2016 Daniel James
|
2017-04-04 22:04:07 +01: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)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#ifndef BOOST_UNORDERED_DETAIL_IMPLEMENTATION_HPP
|
|
|
|
#define BOOST_UNORDERED_DETAIL_IMPLEMENTATION_HPP
|
|
|
|
|
|
|
|
#include <boost/config.hpp>
|
|
|
|
#if defined(BOOST_HAS_PRAGMA_ONCE)
|
|
|
|
#pragma once
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/assert.hpp>
|
|
|
|
#include <boost/detail/no_exceptions_support.hpp>
|
|
|
|
#include <boost/detail/select_type.hpp>
|
|
|
|
#include <boost/iterator/iterator_categories.hpp>
|
|
|
|
#include <boost/limits.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/move/move.hpp>
|
|
|
|
#include <boost/preprocessor/cat.hpp>
|
|
|
|
#include <boost/preprocessor/repetition/enum.hpp>
|
|
|
|
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/preprocessor/seq/enum.hpp>
|
|
|
|
#include <boost/preprocessor/seq/size.hpp>
|
|
|
|
#include <boost/swap.hpp>
|
|
|
|
#include <boost/throw_exception.hpp>
|
|
|
|
#include <boost/tuple/tuple.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/type_traits/add_lvalue_reference.hpp>
|
|
|
|
#include <boost/type_traits/aligned_storage.hpp>
|
|
|
|
#include <boost/type_traits/alignment_of.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/type_traits/is_class.hpp>
|
|
|
|
#include <boost/type_traits/is_convertible.hpp>
|
|
|
|
#include <boost/type_traits/is_empty.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/type_traits/is_nothrow_move_assignable.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
|
2017-02-27 03:59:02 +00:00
|
|
|
#include <boost/type_traits/is_same.hpp>
|
|
|
|
#include <boost/type_traits/remove_const.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/unordered/detail/fwd.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/utility/addressof.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/utility/enable_if.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <cmath>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <iterator>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <stdexcept>
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <utility>
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
|
2017-02-23 20:14:26 +00:00
|
|
|
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
|
|
|
#include <type_traits>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Configuration
|
|
|
|
//
|
|
|
|
// Unless documented elsewhere these configuration macros should be considered
|
|
|
|
// an implementation detail, I'll try not to break them, but you never know.
|
|
|
|
|
2017-04-19 09:46:15 +01:00
|
|
|
// BOOST_UNORDERED_EMPLACE_LIMIT = The maximum number of parameters + 1 in
|
|
|
|
// emplace (not including things like hints). Don't set it to a lower value, as
|
|
|
|
// that might break something.
|
2017-02-23 20:14:26 +00:00
|
|
|
|
|
|
|
#if !defined BOOST_UNORDERED_EMPLACE_LIMIT
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_LIMIT 11
|
|
|
|
#endif
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
// BOOST_UNORDERED_INTEROPERABLE_NODES - Use the same node type for
|
|
|
|
// containers with unique and equivalent keys.
|
|
|
|
//
|
|
|
|
// 0 = Use different nodes
|
|
|
|
// 1 = Use ungrouped nodes everywhere
|
|
|
|
//
|
|
|
|
// Might add an extra value to use grouped nodes everywhere later.
|
|
|
|
|
|
|
|
#if !defined(BOOST_UNORDERED_INTEROPERABLE_NODES)
|
|
|
|
#define BOOST_UNORDERED_INTEROPERABLE_NODES 0
|
|
|
|
#endif
|
|
|
|
|
2017-02-23 20:14:26 +00:00
|
|
|
// BOOST_UNORDERED_USE_ALLOCATOR_TRAITS - Pick which version of
|
|
|
|
// allocator_traits to use.
|
|
|
|
//
|
|
|
|
// 0 = Own partial implementation
|
|
|
|
// 1 = std::allocator_traits
|
|
|
|
// 2 = boost::container::allocator_traits
|
|
|
|
|
|
|
|
#if !defined(BOOST_UNORDERED_USE_ALLOCATOR_TRAITS)
|
|
|
|
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
|
|
|
#define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 1
|
|
|
|
#elif defined(BOOST_MSVC)
|
|
|
|
#if BOOST_MSVC < 1400
|
|
|
|
// Use container's allocator_traits for older versions of Visual
|
|
|
|
// C++ as I don't test with them.
|
|
|
|
#define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 2
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(BOOST_UNORDERED_USE_ALLOCATOR_TRAITS)
|
|
|
|
#define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 0
|
|
|
|
#endif
|
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
// BOOST_UNORDERED_CXX11_CONSTRUCTION
|
|
|
|
//
|
|
|
|
// Use C++11 construction, requires variadic arguments, good construct support
|
|
|
|
// in allocator_traits and piecewise construction of std::pair
|
|
|
|
// Otherwise allocators aren't used for construction/destruction
|
|
|
|
|
|
|
|
#if BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT && \
|
|
|
|
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
#if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 0 && !defined(BOOST_NO_SFINAE_EXPR)
|
|
|
|
#define BOOST_UNORDERED_CXX11_CONSTRUCTION 1
|
|
|
|
#elif BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 1
|
|
|
|
#define BOOST_UNORDERED_CXX11_CONSTRUCTION 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(BOOST_UNORDERED_CXX11_CONSTRUCTION)
|
|
|
|
#define BOOST_UNORDERED_CXX11_CONSTRUCTION 0
|
|
|
|
#endif
|
|
|
|
|
2017-04-15 17:35:09 +01:00
|
|
|
//
|
|
|
|
// Other configuration macros
|
|
|
|
//
|
|
|
|
|
More consistent std::tuple configuration
Was getting a weird test failure for Visual C++ 11,
BOOST_NO_CXX11_HDR_TUPLE is defined, so the code doesn't support
std::tuple, but BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT was also
true, and so there are functions for constructing using
std::piecewise_construct/std::tuple, which don't work.
So, I'm assuming that if BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT is true,
then there must be a std::tuple. I guess it doesn't have full C++11 support,
which is why BOOST_NO_CXX11_HDR_TUPLE is defined, but it appears to be
good enough for us. If not, this will break things.
2017-04-21 20:26:32 +01:00
|
|
|
#if BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT || \
|
|
|
|
(!defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(__SUNPRO_CC))
|
|
|
|
#define BOOST_UNORDERED_HAS_STD_TUPLE 1
|
|
|
|
#else
|
|
|
|
#define BOOST_UNORDERED_HAS_STD_TUPLE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BOOST_UNORDERED_HAS_STD_TUPLE
|
|
|
|
#include <tuple>
|
|
|
|
#endif
|
|
|
|
|
2017-04-15 17:35:09 +01:00
|
|
|
#if defined(BOOST_UNORDERED_SUPPRESS_DEPRECATED)
|
|
|
|
#define BOOST_UNORDERED_DEPRECATED(msg)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__has_cpp_attribute) && \
|
2017-04-16 16:34:22 +01:00
|
|
|
(!defined(__cplusplus) || __cplusplus >= 201402)
|
2017-04-15 17:35:09 +01:00
|
|
|
#if __has_cpp_attribute(deprecated) && !defined(BOOST_UNORDERED_DEPRECATED)
|
|
|
|
#define BOOST_UNORDERED_DEPRECATED(msg) [[deprecated(msg)]]
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(BOOST_UNORDERED_DEPRECATED)
|
|
|
|
#if defined(__GNUC__) && __GNUC__ >= 4
|
|
|
|
#define BOOST_UNORDERED_DEPRECATED(msg) __attribute__((deprecated))
|
|
|
|
#elif defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
#define BOOST_UNORDERED_DEPRECATED(msg) __declspec(deprecated(msg))
|
|
|
|
#elif defined(_MSC_VER) && _MSC_VER >= 1310
|
|
|
|
#define BOOST_UNORDERED_DEPRECATED(msg) __declspec(deprecated)
|
|
|
|
#else
|
|
|
|
#define BOOST_UNORDERED_DEPRECATED(msg)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-02-23 20:14:26 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace iterator_detail {
|
|
|
|
template <typename Node> struct iterator;
|
|
|
|
template <typename Node> struct c_iterator;
|
|
|
|
template <typename Node, typename Policy> struct l_iterator;
|
|
|
|
template <typename Node, typename Policy> struct cl_iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace detail {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:26 +00:00
|
|
|
template <typename Types> struct table;
|
|
|
|
template <typename NodePointer> struct bucket;
|
|
|
|
struct ptr_bucket;
|
2017-04-20 22:59:00 +01:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
template <typename Types> struct table_unique;
|
|
|
|
template <typename Types> struct table_equiv;
|
2017-02-23 20:14:26 +00:00
|
|
|
|
|
|
|
template <typename A, typename T> struct unique_node;
|
|
|
|
template <typename T> struct ptr_node;
|
2017-04-20 22:59:00 +01:00
|
|
|
template <typename N> struct node_algo;
|
2017-02-23 20:14:26 +00:00
|
|
|
|
|
|
|
template <typename A, typename T> struct grouped_node;
|
|
|
|
template <typename T> struct grouped_ptr_node;
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename N> struct grouped_node_algo;
|
2017-02-23 20:14:26 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static const float minimum_max_load_factor = 1e-3f;
|
|
|
|
static const std::size_t default_bucket_count = 11;
|
|
|
|
struct move_tag
|
|
|
|
{
|
|
|
|
};
|
|
|
|
struct empty_emplace
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace func {
|
|
|
|
template <class T> inline void ignore_unused_variable_warning(T const&) {}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// iterator SFINAE
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename I>
|
|
|
|
struct is_forward
|
|
|
|
: boost::is_convertible<typename boost::iterator_traversal<I>::type,
|
|
|
|
boost::forward_traversal_tag>
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename I, typename ReturnType>
|
|
|
|
struct enable_if_forward
|
|
|
|
: boost::enable_if_c<boost::unordered::detail::is_forward<I>::value,
|
|
|
|
ReturnType>
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename I, typename ReturnType>
|
|
|
|
struct disable_if_forward
|
|
|
|
: boost::disable_if_c<boost::unordered::detail::is_forward<I>::value,
|
|
|
|
ReturnType>
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// primes
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// clang-format off
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_PRIMES \
|
|
|
|
(17ul)(29ul)(37ul)(53ul)(67ul)(79ul) \
|
|
|
|
(97ul)(131ul)(193ul)(257ul)(389ul)(521ul)(769ul) \
|
|
|
|
(1031ul)(1543ul)(2053ul)(3079ul)(6151ul)(12289ul)(24593ul) \
|
|
|
|
(49157ul)(98317ul)(196613ul)(393241ul)(786433ul) \
|
|
|
|
(1572869ul)(3145739ul)(6291469ul)(12582917ul)(25165843ul) \
|
|
|
|
(50331653ul)(100663319ul)(201326611ul)(402653189ul)(805306457ul) \
|
|
|
|
(1610612741ul)(3221225473ul)(4294967291ul)
|
2017-02-19 13:05:17 +00:00
|
|
|
// clang-format on
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T> struct prime_list_template
|
|
|
|
{
|
|
|
|
static std::size_t const value[];
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(SUNPRO_CC)
|
2017-02-19 13:05:17 +00:00
|
|
|
static std::ptrdiff_t const length;
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
static std::ptrdiff_t const length =
|
|
|
|
BOOST_PP_SEQ_SIZE(BOOST_UNORDERED_PRIMES);
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T>
|
|
|
|
std::size_t const prime_list_template<T>::value[] = {
|
|
|
|
BOOST_PP_SEQ_ENUM(BOOST_UNORDERED_PRIMES)};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(SUNPRO_CC)
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class T>
|
|
|
|
std::ptrdiff_t const prime_list_template<T>::length = BOOST_PP_SEQ_SIZE(
|
|
|
|
BOOST_UNORDERED_PRIMES);
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef BOOST_UNORDERED_PRIMES
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef prime_list_template<std::size_t> prime_list;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// no throw
|
|
|
|
inline std::size_t next_prime(std::size_t num)
|
|
|
|
{
|
|
|
|
std::size_t const* const prime_list_begin = prime_list::value;
|
|
|
|
std::size_t const* const prime_list_end =
|
|
|
|
prime_list_begin + prime_list::length;
|
|
|
|
std::size_t const* bound =
|
|
|
|
std::lower_bound(prime_list_begin, prime_list_end, num);
|
|
|
|
if (bound == prime_list_end)
|
|
|
|
bound--;
|
|
|
|
return *bound;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// no throw
|
|
|
|
inline std::size_t prev_prime(std::size_t num)
|
|
|
|
{
|
|
|
|
std::size_t const* const prime_list_begin = prime_list::value;
|
|
|
|
std::size_t const* const prime_list_end =
|
|
|
|
prime_list_begin + prime_list::length;
|
|
|
|
std::size_t const* bound =
|
|
|
|
std::upper_bound(prime_list_begin, prime_list_end, num);
|
|
|
|
if (bound != prime_list_begin)
|
|
|
|
bound--;
|
|
|
|
return *bound;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// insert_size/initial_size
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class I>
|
|
|
|
inline std::size_t insert_size(I i, I j,
|
|
|
|
typename boost::unordered::detail::enable_if_forward<I, void*>::type = 0)
|
|
|
|
{
|
|
|
|
return static_cast<std::size_t>(std::distance(i, j));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class I>
|
|
|
|
inline std::size_t insert_size(I, I,
|
|
|
|
typename boost::unordered::detail::disable_if_forward<I, void*>::type = 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class I>
|
|
|
|
inline std::size_t initial_size(I i, I j,
|
|
|
|
std::size_t num_buckets = boost::unordered::detail::default_bucket_count)
|
|
|
|
{
|
|
|
|
// TODO: Why +1?
|
|
|
|
return (std::max)(
|
|
|
|
boost::unordered::detail::insert_size(i, j) + 1, num_buckets);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// compressed
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, int Index> struct compressed_base : private T
|
|
|
|
{
|
|
|
|
compressed_base(T const& x) : T(x) {}
|
|
|
|
compressed_base(T& x, move_tag) : T(boost::move(x)) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
T& get() { return *this; }
|
|
|
|
T const& get() const { return *this; }
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, int Index> struct uncompressed_base
|
|
|
|
{
|
|
|
|
uncompressed_base(T const& x) : value_(x) {}
|
|
|
|
uncompressed_base(T& x, move_tag) : value_(boost::move(x)) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
T& get() { return value_; }
|
|
|
|
T const& get() const { return value_; }
|
|
|
|
private:
|
|
|
|
T value_;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, int Index>
|
|
|
|
struct generate_base
|
|
|
|
: boost::detail::if_true<boost::is_empty<T>::value>::BOOST_NESTED_TEMPLATE
|
|
|
|
then<boost::unordered::detail::compressed_base<T, Index>,
|
|
|
|
boost::unordered::detail::uncompressed_base<T, Index> >
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T1, typename T2>
|
|
|
|
struct compressed
|
|
|
|
: private boost::unordered::detail::generate_base<T1, 1>::type,
|
|
|
|
private boost::unordered::detail::generate_base<T2, 2>::type
|
|
|
|
{
|
|
|
|
typedef typename generate_base<T1, 1>::type base1;
|
|
|
|
typedef typename generate_base<T2, 2>::type base2;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef T1 first_type;
|
|
|
|
typedef T2 second_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
first_type& first() { return static_cast<base1*>(this)->get(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
first_type const& first() const
|
|
|
|
{
|
|
|
|
return static_cast<base1 const*>(this)->get();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
second_type& second() { return static_cast<base2*>(this)->get(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
second_type const& second() const
|
|
|
|
{
|
|
|
|
return static_cast<base2 const*>(this)->get();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename First, typename Second>
|
|
|
|
compressed(First const& x1, Second const& x2) : base1(x1), base2(x2)
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
compressed(compressed const& x) : base1(x.first()), base2(x.second()) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
compressed(compressed& x, move_tag m)
|
|
|
|
: base1(x.first(), m), base2(x.second(), m)
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void assign(compressed const& x)
|
|
|
|
{
|
|
|
|
first() = x.first();
|
|
|
|
second() = x.second();
|
|
|
|
}
|
|
|
|
|
|
|
|
void move_assign(compressed& x)
|
|
|
|
{
|
|
|
|
first() = boost::move(x.first());
|
|
|
|
second() = boost::move(x.second());
|
|
|
|
}
|
|
|
|
|
|
|
|
void swap(compressed& x)
|
|
|
|
{
|
|
|
|
boost::swap(first(), x.first());
|
|
|
|
boost::swap(second(), x.second());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Prevent assignment just to make use of assign or
|
|
|
|
// move_assign explicit.
|
|
|
|
compressed& operator=(compressed const&);
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// pair_traits
|
|
|
|
//
|
|
|
|
// Used to get the types from a pair without instantiating it.
|
|
|
|
|
|
|
|
template <typename Pair> struct pair_traits
|
|
|
|
{
|
|
|
|
typedef typename Pair::first_type first_type;
|
|
|
|
typedef typename Pair::second_type second_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T1, typename T2> struct pair_traits<std::pair<T1, T2> >
|
|
|
|
{
|
|
|
|
typedef T1 first_type;
|
|
|
|
typedef T2 second_type;
|
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
#pragma warning(push)
|
2017-02-19 13:05:17 +00:00
|
|
|
#pragma warning(disable : 4512) // assignment operator could not be generated.
|
|
|
|
#pragma warning(disable : 4345) // behavior change: an object of POD type
|
|
|
|
// constructed with an initializer of the form ()
|
|
|
|
// will be default-initialized.
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Bits and pieces for implementing traits
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> typename boost::add_lvalue_reference<T>::type make();
|
|
|
|
struct choice9
|
|
|
|
{
|
|
|
|
typedef char (&type)[9];
|
|
|
|
};
|
|
|
|
struct choice8 : choice9
|
|
|
|
{
|
|
|
|
typedef char (&type)[8];
|
|
|
|
};
|
|
|
|
struct choice7 : choice8
|
|
|
|
{
|
|
|
|
typedef char (&type)[7];
|
|
|
|
};
|
|
|
|
struct choice6 : choice7
|
|
|
|
{
|
|
|
|
typedef char (&type)[6];
|
|
|
|
};
|
|
|
|
struct choice5 : choice6
|
|
|
|
{
|
|
|
|
typedef char (&type)[5];
|
|
|
|
};
|
|
|
|
struct choice4 : choice5
|
|
|
|
{
|
|
|
|
typedef char (&type)[4];
|
|
|
|
};
|
|
|
|
struct choice3 : choice4
|
|
|
|
{
|
|
|
|
typedef char (&type)[3];
|
|
|
|
};
|
|
|
|
struct choice2 : choice3
|
|
|
|
{
|
|
|
|
typedef char (&type)[2];
|
|
|
|
};
|
|
|
|
struct choice1 : choice2
|
|
|
|
{
|
|
|
|
typedef char (&type)[1];
|
|
|
|
};
|
|
|
|
choice1 choose();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef choice1::type yes_type;
|
|
|
|
typedef choice2::type no_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
struct private_type
|
|
|
|
{
|
|
|
|
private_type const& operator,(int) const;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> no_type is_private_type(T const&);
|
|
|
|
yes_type is_private_type(private_type const&);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
struct convert_from_anything
|
|
|
|
{
|
|
|
|
template <typename T> convert_from_anything(T const&);
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// emplace_args
|
|
|
|
//
|
|
|
|
// Either forwarding variadic arguments, or storing the arguments in
|
|
|
|
// emplace_args##n
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_ARGS1(a0) a0
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_ARGS2(a0, a1) a0, a1
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_ARGS3(a0, a1, a2) a0, a1, a2
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_TEMPLATE typename... Args
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_ARGS BOOST_FWD_REF(Args)... args
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_FORWARD boost::forward<Args>(args)...
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_ARGS1 create_emplace_args
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_ARGS2 create_emplace_args
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_ARGS3 create_emplace_args
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_TEMPLATE typename Args
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_ARGS Args const& args
|
|
|
|
#define BOOST_UNORDERED_EMPLACE_FORWARD args
|
|
|
|
|
|
|
|
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \
|
|
|
|
typedef BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(Arg, n); \
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \
|
|
|
|
typedef typename boost::add_lvalue_reference<BOOST_PP_CAT(A, n)>::type \
|
|
|
|
BOOST_PP_CAT(Arg, n); \
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A0> struct emplace_args1
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
BOOST_UNORDERED_EARGS_MEMBER(1, 0, _)
|
|
|
|
|
2017-03-01 16:46:18 +00:00
|
|
|
explicit emplace_args1(Arg0 b0) : a0(b0) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename A0>
|
2017-02-19 13:05:17 +00:00
|
|
|
inline emplace_args1<A0> create_emplace_args(BOOST_FWD_REF(A0) b0)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
emplace_args1<A0> e(b0);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A0, typename A1> struct emplace_args2
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
BOOST_UNORDERED_EARGS_MEMBER(1, 0, _)
|
|
|
|
BOOST_UNORDERED_EARGS_MEMBER(1, 1, _)
|
|
|
|
|
|
|
|
emplace_args2(Arg0 b0, Arg1 b1) : a0(b0), a1(b1) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename A0, typename A1>
|
|
|
|
inline emplace_args2<A0, A1> create_emplace_args(
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_FWD_REF(A0) b0, BOOST_FWD_REF(A1) b1)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
emplace_args2<A0, A1> e(b0, b1);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A0, typename A1, typename A2> struct emplace_args3
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
BOOST_UNORDERED_EARGS_MEMBER(1, 0, _)
|
|
|
|
BOOST_UNORDERED_EARGS_MEMBER(1, 1, _)
|
|
|
|
BOOST_UNORDERED_EARGS_MEMBER(1, 2, _)
|
|
|
|
|
|
|
|
emplace_args3(Arg0 b0, Arg1 b1, Arg2 b2) : a0(b0), a1(b1), a2(b2) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename A0, typename A1, typename A2>
|
|
|
|
inline emplace_args3<A0, A1, A2> create_emplace_args(
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_FWD_REF(A0) b0, BOOST_FWD_REF(A1) b1, BOOST_FWD_REF(A2) b2)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
emplace_args3<A0, A1, A2> e(b0, b1, b2);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_FWD_PARAM(z, n, a) \
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(a, n)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_CALL_FORWARD(z, i, a) \
|
|
|
|
boost::forward<BOOST_PP_CAT(A, i)>(BOOST_PP_CAT(a, i))
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_EARGS_INIT(z, n, _) \
|
|
|
|
BOOST_PP_CAT(a, n)(BOOST_PP_CAT(b, n))
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_EARGS(z, n, _) \
|
|
|
|
template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
|
|
|
struct BOOST_PP_CAT(emplace_args, n) \
|
|
|
|
{ \
|
|
|
|
BOOST_PP_REPEAT_##z(n, BOOST_UNORDERED_EARGS_MEMBER, _) BOOST_PP_CAT( \
|
|
|
|
emplace_args, n)(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, Arg, b)) \
|
|
|
|
: BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_EARGS_INIT, _) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
|
|
|
inline BOOST_PP_CAT(emplace_args, n)<BOOST_PP_ENUM_PARAMS_Z(z, n, A)> \
|
|
|
|
create_emplace_args( \
|
|
|
|
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, b)) \
|
|
|
|
{ \
|
|
|
|
BOOST_PP_CAT(emplace_args, n)<BOOST_PP_ENUM_PARAMS_Z(z, n, A)> e( \
|
|
|
|
BOOST_PP_ENUM_PARAMS_Z(z, n, b)); \
|
|
|
|
return e; \
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_PP_REPEAT_FROM_TO(
|
|
|
|
4, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EARGS, _)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#undef BOOST_UNORDERED_DEFINE_EMPLACE_ARGS
|
|
|
|
#undef BOOST_UNORDERED_EARGS_MEMBER
|
|
|
|
#undef BOOST_UNORDERED_EARGS_INIT
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Some utilities for implementing allocator_traits, but useful elsewhere so
|
|
|
|
// they're always defined.
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Integral_constrant, true_type, false_type
|
|
|
|
//
|
|
|
|
// Uses the standard versions if available.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
using std::integral_constant;
|
|
|
|
using std::true_type;
|
|
|
|
using std::false_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, T Value> struct integral_constant
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
value = Value
|
|
|
|
};
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef boost::unordered::detail::integral_constant<bool, true> true_type;
|
|
|
|
typedef boost::unordered::detail::integral_constant<bool, false> false_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Explicitly call a destructor
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
#pragma warning(push)
|
2017-02-19 13:05:17 +00:00
|
|
|
#pragma warning(disable : 4100) // unreferenced formal parameter
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace func {
|
|
|
|
template <class T> inline void destroy(T* x) { x->~T(); }
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Expression test mechanism
|
|
|
|
//
|
|
|
|
// When SFINAE expressions are available, define
|
|
|
|
// BOOST_UNORDERED_HAS_FUNCTION which can check if a function call is
|
|
|
|
// supported by a class, otherwise define BOOST_UNORDERED_HAS_MEMBER which
|
|
|
|
// can detect if a class has the specified member, but not that it has the
|
|
|
|
// correct type, this is good enough for a passable impression of
|
|
|
|
// allocator_traits.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_SFINAE_EXPR)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, long unsigned int> struct expr_test;
|
|
|
|
template <typename T> struct expr_test<T, sizeof(char)> : T
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_CHECK_EXPRESSION(count, result, expression) \
|
|
|
|
template <typename U> \
|
|
|
|
static typename boost::unordered::detail::expr_test<BOOST_PP_CAT( \
|
|
|
|
choice, result), \
|
|
|
|
sizeof(for_expr_test(((expression), 0)))>::type \
|
|
|
|
test(BOOST_PP_CAT(choice, count))
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_DEFAULT_EXPRESSION(count, result) \
|
|
|
|
template <typename U> \
|
|
|
|
static BOOST_PP_CAT(choice, result)::type test( \
|
|
|
|
BOOST_PP_CAT(choice, count))
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_HAS_FUNCTION(name, thing, args, _) \
|
|
|
|
struct BOOST_PP_CAT(has_, name) \
|
|
|
|
{ \
|
|
|
|
template <typename U> static char for_expr_test(U const&); \
|
|
|
|
BOOST_UNORDERED_CHECK_EXPRESSION( \
|
|
|
|
1, 1, boost::unordered::detail::make<thing>().name args); \
|
|
|
|
BOOST_UNORDERED_DEFAULT_EXPRESSION(2, 2); \
|
|
|
|
\
|
|
|
|
enum \
|
|
|
|
{ \
|
|
|
|
value = sizeof(test<T>(choose())) == sizeof(choice1::type) \
|
|
|
|
}; \
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> struct identity
|
|
|
|
{
|
|
|
|
typedef T type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_CHECK_MEMBER(count, result, name, member) \
|
|
|
|
\
|
|
|
|
typedef typename boost::unordered::detail::identity<member>::type \
|
|
|
|
BOOST_PP_CAT(check, count); \
|
|
|
|
\
|
|
|
|
template <BOOST_PP_CAT(check, count) e> struct BOOST_PP_CAT(test, count) \
|
|
|
|
{ \
|
|
|
|
typedef BOOST_PP_CAT(choice, result) type; \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
template <class U> \
|
|
|
|
static typename BOOST_PP_CAT(test, count)<&U::name>::type test( \
|
|
|
|
BOOST_PP_CAT(choice, count))
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_DEFAULT_MEMBER(count, result) \
|
|
|
|
template <class U> \
|
|
|
|
static BOOST_PP_CAT(choice, result)::type test( \
|
|
|
|
BOOST_PP_CAT(choice, count))
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_HAS_MEMBER(name) \
|
|
|
|
struct BOOST_PP_CAT(has_, name) \
|
|
|
|
{ \
|
|
|
|
struct impl \
|
|
|
|
{ \
|
|
|
|
struct base_mixin \
|
|
|
|
{ \
|
|
|
|
int name; \
|
|
|
|
}; \
|
|
|
|
struct base : public T, public base_mixin \
|
|
|
|
{ \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
BOOST_UNORDERED_CHECK_MEMBER(1, 1, name, int base_mixin::*); \
|
|
|
|
BOOST_UNORDERED_DEFAULT_MEMBER(2, 2); \
|
|
|
|
\
|
|
|
|
enum \
|
|
|
|
{ \
|
|
|
|
value = sizeof(choice2::type) == sizeof(test<base>(choose())) \
|
|
|
|
}; \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
enum \
|
|
|
|
{ \
|
|
|
|
value = impl::value \
|
|
|
|
}; \
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Allocator traits
|
|
|
|
//
|
|
|
|
// First our implementation, then later light wrappers around the alternatives
|
|
|
|
|
|
|
|
#if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 0
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/limits.hpp>
|
|
|
|
#include <boost/pointer_to_other.hpp>
|
2017-02-27 03:59:02 +00:00
|
|
|
#include <boost/utility/enable_if.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace detail {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T> struct rebind_alloc;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <template <typename, typename...> class Alloc, typename U, typename T,
|
|
|
|
typename... Args>
|
|
|
|
struct rebind_alloc<Alloc<U, Args...>, T>
|
|
|
|
{
|
|
|
|
typedef Alloc<T, Args...> type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <template <typename> class Alloc, typename U, typename T>
|
|
|
|
struct rebind_alloc<Alloc<U>, T>
|
|
|
|
{
|
|
|
|
typedef Alloc<T> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <template <typename, typename> class Alloc, typename U, typename T,
|
|
|
|
typename A0>
|
|
|
|
struct rebind_alloc<Alloc<U, A0>, T>
|
|
|
|
{
|
|
|
|
typedef Alloc<T, A0> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <template <typename, typename, typename> class Alloc, typename U,
|
|
|
|
typename T, typename A0, typename A1>
|
|
|
|
struct rebind_alloc<Alloc<U, A0, A1>, T>
|
|
|
|
{
|
|
|
|
typedef Alloc<T, A0, A1> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T> struct rebind_wrap
|
|
|
|
{
|
|
|
|
template <typename X>
|
|
|
|
static choice1::type test(
|
|
|
|
choice1, typename X::BOOST_NESTED_TEMPLATE rebind<T>::other* = 0);
|
|
|
|
template <typename X> static choice2::type test(choice2, void* = 0);
|
|
|
|
|
|
|
|
enum
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
value = (1 == sizeof(test<Alloc>(choose())))
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
struct fallback
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename U> struct rebind
|
|
|
|
{
|
|
|
|
typedef typename rebind_alloc<Alloc, T>::type other;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename boost::detail::if_true<value>::BOOST_NESTED_TEMPLATE then<
|
|
|
|
Alloc, fallback>::type::BOOST_NESTED_TEMPLATE rebind<T>::other type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1400
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(tname) \
|
|
|
|
template <typename Tp, typename Default> struct default_type_##tname \
|
|
|
|
{ \
|
|
|
|
\
|
|
|
|
template <typename X> \
|
|
|
|
static choice1::type test(choice1, typename X::tname* = 0); \
|
|
|
|
\
|
|
|
|
template <typename X> static choice2::type test(choice2, void* = 0); \
|
|
|
|
\
|
|
|
|
struct DefaultWrap \
|
|
|
|
{ \
|
|
|
|
typedef Default tname; \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
enum \
|
|
|
|
{ \
|
|
|
|
value = (1 == sizeof(test<Tp>(choose()))) \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
typedef typename boost::detail::if_true<value>::BOOST_NESTED_TEMPLATE \
|
|
|
|
then<Tp, DefaultWrap>::type::tname type; \
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, typename T2> struct sfinae : T2
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(tname) \
|
|
|
|
template <typename Tp, typename Default> struct default_type_##tname \
|
|
|
|
{ \
|
|
|
|
\
|
|
|
|
template <typename X> \
|
|
|
|
static typename boost::unordered::detail::sfinae<typename X::tname, \
|
|
|
|
choice1>::type test(choice1); \
|
|
|
|
\
|
|
|
|
template <typename X> static choice2::type test(choice2); \
|
|
|
|
\
|
|
|
|
struct DefaultWrap \
|
|
|
|
{ \
|
|
|
|
typedef Default tname; \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
enum \
|
|
|
|
{ \
|
|
|
|
value = (1 == sizeof(test<Tp>(choose()))) \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
typedef typename boost::detail::if_true<value>::BOOST_NESTED_TEMPLATE \
|
|
|
|
then<Tp, DefaultWrap>::type::tname type; \
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_DEFAULT_TYPE(T, tname, arg) \
|
|
|
|
typename default_type_##tname<T, arg>::type
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(pointer);
|
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(const_pointer);
|
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(void_pointer);
|
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(const_void_pointer);
|
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(difference_type);
|
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(size_type);
|
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(propagate_on_container_copy_assignment);
|
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(propagate_on_container_move_assignment);
|
|
|
|
BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(propagate_on_container_swap);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#if !defined(BOOST_NO_SFINAE_EXPR)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
BOOST_UNORDERED_HAS_FUNCTION(
|
|
|
|
select_on_container_copy_construction, U const, (), 0);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> BOOST_UNORDERED_HAS_FUNCTION(max_size, U const, (), 0);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, typename ValueType, typename... Args>
|
|
|
|
BOOST_UNORDERED_HAS_FUNCTION(
|
|
|
|
construct, U, (boost::unordered::detail::make<ValueType*>(),
|
|
|
|
boost::unordered::detail::make<Args const>()...),
|
|
|
|
2);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, typename ValueType>
|
|
|
|
BOOST_UNORDERED_HAS_FUNCTION(
|
|
|
|
construct, U, (boost::unordered::detail::make<ValueType*>(),
|
|
|
|
boost::unordered::detail::make<ValueType const>()),
|
|
|
|
2);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, typename ValueType>
|
|
|
|
BOOST_UNORDERED_HAS_FUNCTION(
|
|
|
|
destroy, U, (boost::unordered::detail::make<ValueType*>()), 1);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
BOOST_UNORDERED_HAS_MEMBER(select_on_container_copy_construction);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> BOOST_UNORDERED_HAS_MEMBER(max_size);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, typename ValueType> BOOST_UNORDERED_HAS_MEMBER(construct);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, typename ValueType> BOOST_UNORDERED_HAS_MEMBER(destroy);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace func {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc>
|
|
|
|
inline Alloc call_select_on_container_copy_construction(const Alloc& rhs,
|
|
|
|
typename boost::enable_if_c<
|
|
|
|
boost::unordered::detail::has_select_on_container_copy_construction<
|
|
|
|
Alloc>::value,
|
|
|
|
void*>::type = 0)
|
|
|
|
{
|
|
|
|
return rhs.select_on_container_copy_construction();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc>
|
|
|
|
inline Alloc call_select_on_container_copy_construction(const Alloc& rhs,
|
|
|
|
typename boost::disable_if_c<
|
|
|
|
boost::unordered::detail::has_select_on_container_copy_construction<
|
|
|
|
Alloc>::value,
|
|
|
|
void*>::type = 0)
|
|
|
|
{
|
|
|
|
return rhs;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename SizeType, typename Alloc>
|
|
|
|
inline SizeType call_max_size(const Alloc& a,
|
|
|
|
typename boost::enable_if_c<
|
|
|
|
boost::unordered::detail::has_max_size<Alloc>::value, void*>::type = 0)
|
|
|
|
{
|
|
|
|
return a.max_size();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename SizeType, typename Alloc>
|
|
|
|
inline SizeType call_max_size(const Alloc&,
|
|
|
|
typename boost::disable_if_c<
|
|
|
|
boost::unordered::detail::has_max_size<Alloc>::value, void*>::type = 0)
|
|
|
|
{
|
|
|
|
return (std::numeric_limits<SizeType>::max)();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
} // namespace func.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc> struct allocator_traits
|
|
|
|
{
|
|
|
|
typedef Alloc allocator_type;
|
|
|
|
typedef typename Alloc::value_type value_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, pointer, value_type*) pointer;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct pointer_to_other : boost::pointer_to_other<pointer, T>
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, const_pointer,
|
|
|
|
typename pointer_to_other<const value_type>::type) const_pointer;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, void_pointer,
|
|
|
|
// typename pointer_to_other<void>::type)
|
|
|
|
// void_pointer;
|
|
|
|
//
|
|
|
|
// typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, const_void_pointer,
|
|
|
|
// typename pointer_to_other<const void>::type)
|
|
|
|
// const_void_pointer;
|
|
|
|
|
|
|
|
typedef BOOST_UNORDERED_DEFAULT_TYPE(
|
|
|
|
Alloc, difference_type, std::ptrdiff_t) difference_type;
|
|
|
|
|
|
|
|
typedef BOOST_UNORDERED_DEFAULT_TYPE(
|
|
|
|
Alloc, size_type, std::size_t) size_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
using rebind_alloc = typename rebind_wrap<Alloc, T>::type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
using rebind_traits =
|
|
|
|
boost::unordered::detail::allocator_traits<rebind_alloc<T> >;
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static pointer allocate(Alloc& a, size_type n) { return a.allocate(n); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// I never use this, so I'll just comment it out for now.
|
|
|
|
//
|
|
|
|
// static pointer allocate(Alloc& a, size_type n,
|
|
|
|
// const_void_pointer hint)
|
|
|
|
// { return DEFAULT_FUNC(allocate, pointer)(a, n, hint); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static void deallocate(Alloc& a, pointer p, size_type n)
|
|
|
|
{
|
|
|
|
a.deallocate(p, n);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
public:
|
2017-04-18 10:14:26 +01:00
|
|
|
#if BOOST_UNORDERED_CXX11_CONSTRUCTION
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
static typename boost::enable_if_c<
|
|
|
|
boost::unordered::detail::has_construct<Alloc, T, Args...>::value>::type
|
|
|
|
construct(Alloc& a, T* p, BOOST_FWD_REF(Args)... x)
|
|
|
|
{
|
|
|
|
a.construct(p, boost::forward<Args>(x)...);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
static typename boost::disable_if_c<
|
|
|
|
boost::unordered::detail::has_construct<Alloc, T, Args...>::value>::type
|
|
|
|
construct(Alloc&, T* p, BOOST_FWD_REF(Args)... x)
|
|
|
|
{
|
|
|
|
new (static_cast<void*>(p)) T(boost::forward<Args>(x)...);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static typename boost::enable_if_c<
|
|
|
|
boost::unordered::detail::has_destroy<Alloc, T>::value>::type
|
|
|
|
destroy(Alloc& a, T* p)
|
|
|
|
{
|
|
|
|
a.destroy(p);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static typename boost::disable_if_c<
|
|
|
|
boost::unordered::detail::has_destroy<Alloc, T>::value>::type
|
|
|
|
destroy(Alloc&, T* p)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::destroy(p);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#elif !defined(BOOST_NO_SFINAE_EXPR)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static typename boost::enable_if_c<
|
|
|
|
boost::unordered::detail::has_construct<Alloc, T>::value>::type
|
|
|
|
construct(Alloc& a, T* p, T const& x)
|
|
|
|
{
|
|
|
|
a.construct(p, x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static typename boost::disable_if_c<
|
|
|
|
boost::unordered::detail::has_construct<Alloc, T>::value>::type
|
|
|
|
construct(Alloc&, T* p, T const& x)
|
|
|
|
{
|
|
|
|
new (static_cast<void*>(p)) T(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static typename boost::enable_if_c<
|
|
|
|
boost::unordered::detail::has_destroy<Alloc, T>::value>::type
|
|
|
|
destroy(Alloc& a, T* p)
|
|
|
|
{
|
|
|
|
a.destroy(p);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static typename boost::disable_if_c<
|
|
|
|
boost::unordered::detail::has_destroy<Alloc, T>::value>::type
|
|
|
|
destroy(Alloc&, T* p)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::destroy(p);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// If we don't have SFINAE expressions, only call construct for the
|
|
|
|
// copy constructor for the allocator's value_type - as that's
|
|
|
|
// the only construct method that old fashioned allocators support.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static void construct(Alloc& a, T* p, T const& x,
|
|
|
|
typename boost::enable_if_c<
|
|
|
|
boost::unordered::detail::has_construct<Alloc, T>::value &&
|
|
|
|
boost::is_same<T, value_type>::value,
|
|
|
|
void*>::type = 0)
|
|
|
|
{
|
|
|
|
a.construct(p, x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static void construct(Alloc&, T* p, T const& x,
|
|
|
|
typename boost::disable_if_c<
|
|
|
|
boost::unordered::detail::has_construct<Alloc, T>::value &&
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::is_same<T, value_type>::value,
|
2017-02-19 13:05:17 +00:00
|
|
|
void*>::type = 0)
|
|
|
|
{
|
|
|
|
new (static_cast<void*>(p)) T(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static void destroy(Alloc& a, T* p,
|
|
|
|
typename boost::enable_if_c<
|
|
|
|
boost::unordered::detail::has_destroy<Alloc, T>::value &&
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::is_same<T, value_type>::value,
|
2017-02-19 13:05:17 +00:00
|
|
|
void*>::type = 0)
|
|
|
|
{
|
|
|
|
a.destroy(p);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
static void destroy(Alloc&, T* p,
|
|
|
|
typename boost::disable_if_c<
|
|
|
|
boost::unordered::detail::has_destroy<Alloc, T>::value &&
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::is_same<T, value_type>::value,
|
2017-02-19 13:05:17 +00:00
|
|
|
void*>::type = 0)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::destroy(p);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static size_type max_size(const Alloc& a)
|
|
|
|
{
|
|
|
|
return boost::unordered::detail::func::call_max_size<size_type>(a);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Allocator propagation on construction
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static Alloc select_on_container_copy_construction(Alloc const& rhs)
|
|
|
|
{
|
|
|
|
return boost::unordered::detail::func::
|
|
|
|
call_select_on_container_copy_construction(rhs);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Allocator propagation on assignment and swap.
|
|
|
|
// Return true if lhs is modified.
|
|
|
|
typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc,
|
|
|
|
propagate_on_container_copy_assignment,
|
|
|
|
false_type) propagate_on_container_copy_assignment;
|
|
|
|
typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc,
|
|
|
|
propagate_on_container_move_assignment,
|
|
|
|
false_type) propagate_on_container_move_assignment;
|
|
|
|
typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, propagate_on_container_swap,
|
|
|
|
false_type) propagate_on_container_swap;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#undef BOOST_UNORDERED_DEFAULT_TYPE_TMPLT
|
|
|
|
#undef BOOST_UNORDERED_DEFAULT_TYPE
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// std::allocator_traits
|
|
|
|
|
|
|
|
#elif BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 1
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <memory>
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace detail {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc> struct allocator_traits : std::allocator_traits<Alloc>
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T> struct rebind_wrap
|
|
|
|
{
|
|
|
|
typedef typename std::allocator_traits<Alloc>::template rebind_alloc<T>
|
|
|
|
type;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// boost::container::allocator_traits
|
|
|
|
|
|
|
|
#elif BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 2
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#include <boost/container/allocator_traits.hpp>
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace detail {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc>
|
|
|
|
struct allocator_traits : boost::container::allocator_traits<Alloc>
|
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T>
|
|
|
|
struct rebind_wrap : boost::container::allocator_traits<
|
|
|
|
Alloc>::template portable_rebind_alloc<T>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#error "Invalid BOOST_UNORDERED_USE_ALLOCATOR_TRAITS value."
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-02-23 20:14:26 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Functions used to construct nodes. Emulates variadic construction,
|
|
|
|
// piecewise construction etc.
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace detail {
|
|
|
|
namespace func {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2017-04-18 10:14:26 +01:00
|
|
|
// construct_value
|
2017-04-18 10:14:26 +01:00
|
|
|
//
|
|
|
|
// Only use allocator_traits::construct, allocator_traits::destroy when full
|
|
|
|
// C++11 support is available.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
#if BOOST_UNORDERED_CXX11_CONSTRUCTION
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
#define BOOST_UNORDERED_CALL_CONSTRUCT0(Traits, alloc, address) \
|
|
|
|
Traits::construct(alloc, address)
|
|
|
|
#define BOOST_UNORDERED_CALL_CONSTRUCT1(Traits, alloc, address, a0) \
|
|
|
|
Traits::construct(alloc, address, a0)
|
|
|
|
#define BOOST_UNORDERED_CALL_DESTROY(Traits, alloc, x) Traits::destroy(alloc, x)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
#elif !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
inline void construct_value(T* address, BOOST_FWD_REF(Args)... args)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
new ((void*)address) T(boost::forward<Args>(args)...);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
#define BOOST_UNORDERED_CALL_CONSTRUCT0(Traits, alloc, address) \
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(address)
|
2017-04-18 10:14:26 +01:00
|
|
|
#define BOOST_UNORDERED_CALL_CONSTRUCT1(Traits, alloc, address, a0) \
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(address, a0)
|
2017-04-18 10:14:26 +01:00
|
|
|
#define BOOST_UNORDERED_CALL_DESTROY(Traits, alloc, x) \
|
|
|
|
boost::unordered::detail::func::destroy(x)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#else
|
2017-04-18 10:14:26 +01:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
template <typename T> inline void construct_value(T* address)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
new ((void*)address) T();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
template <typename T, typename A0>
|
|
|
|
inline void construct_value(T* address, BOOST_FWD_REF(A0) a0)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
new ((void*)address) T(boost::forward<A0>(a0));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
#define BOOST_UNORDERED_CALL_CONSTRUCT0(Traits, alloc, address) \
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(address)
|
2017-04-18 10:14:26 +01:00
|
|
|
#define BOOST_UNORDERED_CALL_CONSTRUCT1(Traits, alloc, address, a0) \
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(address, a0)
|
2017-04-18 10:14:26 +01:00
|
|
|
#define BOOST_UNORDERED_CALL_DESTROY(Traits, alloc, x) \
|
|
|
|
boost::unordered::detail::func::destroy(x)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Construct from tuple
|
|
|
|
//
|
2017-04-18 10:14:26 +01:00
|
|
|
// Used to emulate piecewise construction.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \
|
|
|
|
template <typename Alloc, typename T> \
|
2017-04-18 10:14:26 +01:00
|
|
|
void construct_from_tuple(Alloc&, T* ptr, namespace_ tuple<>) \
|
2017-02-19 13:05:17 +00:00
|
|
|
{ \
|
2017-04-18 10:14:26 +01:00
|
|
|
new ((void*)ptr) T(); \
|
2017-02-19 13:05:17 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
BOOST_PP_REPEAT_FROM_TO( \
|
|
|
|
1, n, BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_)
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \
|
|
|
|
template <typename Alloc, typename T, \
|
|
|
|
BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
2017-04-18 10:14:26 +01:00
|
|
|
void construct_from_tuple(Alloc&, T* ptr, \
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace_ tuple<BOOST_PP_ENUM_PARAMS_Z(z, n, A)> const& x) \
|
|
|
|
{ \
|
2017-04-18 10:14:26 +01:00
|
|
|
new ((void*)ptr) T( \
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) namespace_ get<n>(x)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#elif !defined(__SUNPRO_CC)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \
|
|
|
|
template <typename Alloc, typename T> \
|
|
|
|
void construct_from_tuple(Alloc&, T* ptr, namespace_ tuple<>) \
|
|
|
|
{ \
|
|
|
|
new ((void*)ptr) T(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
BOOST_PP_REPEAT_FROM_TO( \
|
|
|
|
1, n, BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_)
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \
|
|
|
|
template <typename Alloc, typename T, \
|
|
|
|
BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
|
|
|
void construct_from_tuple(Alloc&, T* ptr, \
|
|
|
|
namespace_ tuple<BOOST_PP_ENUM_PARAMS_Z(z, n, A)> const& x) \
|
|
|
|
{ \
|
|
|
|
new ((void*)ptr) T( \
|
|
|
|
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) namespace_ get<n>(x)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <int N> struct length
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \
|
|
|
|
template <typename Alloc, typename T> \
|
|
|
|
void construct_from_tuple_impl(boost::unordered::detail::func::length<0>, \
|
|
|
|
Alloc&, T* ptr, namespace_ tuple<>) \
|
|
|
|
{ \
|
|
|
|
new ((void*)ptr) T(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
BOOST_PP_REPEAT_FROM_TO( \
|
|
|
|
1, n, BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_)
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \
|
|
|
|
template <typename Alloc, typename T, \
|
|
|
|
BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
|
|
|
void construct_from_tuple_impl(boost::unordered::detail::func::length<n>, \
|
|
|
|
Alloc&, T* ptr, \
|
|
|
|
namespace_ tuple<BOOST_PP_ENUM_PARAMS_Z(z, n, A)> const& x) \
|
|
|
|
{ \
|
|
|
|
new ((void*)ptr) T( \
|
|
|
|
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) namespace_ get<n>(x)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
|
|
|
|
|
More consistent std::tuple configuration
Was getting a weird test failure for Visual C++ 11,
BOOST_NO_CXX11_HDR_TUPLE is defined, so the code doesn't support
std::tuple, but BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT was also
true, and so there are functions for constructing using
std::piecewise_construct/std::tuple, which don't work.
So, I'm assuming that if BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT is true,
then there must be a std::tuple. I guess it doesn't have full C++11 support,
which is why BOOST_NO_CXX11_HDR_TUPLE is defined, but it appears to be
good enough for us. If not, this will break things.
2017-04-21 20:26:32 +01:00
|
|
|
#if !BOOST_UNORDERED_CXX11_CONSTRUCTION && BOOST_UNORDERED_HAS_STD_TUPLE
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, std::)
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE
|
|
|
|
#undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL
|
|
|
|
#undef BOOST_UNORDERED_GET_TUPLE_ARG
|
|
|
|
|
|
|
|
#if defined(__SUNPRO_CC)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T, typename Tuple>
|
|
|
|
void construct_from_tuple(Alloc& alloc, T* ptr, Tuple const& x)
|
|
|
|
{
|
|
|
|
construct_from_tuple_impl(boost::unordered::detail::func::length<
|
|
|
|
boost::tuples::length<Tuple>::value>(),
|
|
|
|
alloc, ptr, x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Trait to check for piecewise construction.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A0> struct use_piecewise
|
|
|
|
{
|
|
|
|
static choice1::type test(choice1, boost::unordered::piecewise_construct_t);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static choice2::type test(choice2, ...);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
value = sizeof(choice1::type) ==
|
|
|
|
sizeof(test(choose(), boost::unordered::detail::make<A0>()))
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
#if BOOST_UNORDERED_CXX11_CONSTRUCTION
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Construct from variadic parameters
|
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
template <typename Alloc, typename T, typename... Args>
|
|
|
|
inline void construct_from_args(
|
|
|
|
Alloc& alloc, T* address, BOOST_FWD_REF(Args)... args)
|
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::allocator_traits<Alloc>::construct(
|
2017-04-18 10:14:26 +01:00
|
|
|
alloc, address, boost::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For backwards compatibility, implement a special case for
|
|
|
|
// piecewise_construct with boost::tuple
|
|
|
|
|
|
|
|
template <typename A0> struct detect_boost_tuple
|
|
|
|
{
|
|
|
|
template <typename... T0>
|
|
|
|
static choice1::type test(choice1, boost::tuple<T0...> const&);
|
|
|
|
|
|
|
|
static choice2::type test(choice2, ...);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
value = sizeof(choice1::type) ==
|
|
|
|
sizeof(test(choose(), boost::unordered::detail::make<A0>()))
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Special case for piecewise_construct
|
|
|
|
|
|
|
|
template <typename Alloc, typename A, typename B, typename A0, typename A1,
|
|
|
|
typename A2>
|
|
|
|
inline typename boost::enable_if_c<use_piecewise<A0>::value &&
|
|
|
|
detect_boost_tuple<A1>::value &&
|
|
|
|
detect_boost_tuple<A2>::value,
|
|
|
|
void>::type
|
|
|
|
construct_from_args(Alloc& alloc, std::pair<A, B>* address, BOOST_FWD_REF(A0),
|
|
|
|
BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::construct_from_tuple(
|
|
|
|
alloc, boost::addressof(address->first), boost::forward<A1>(a1));
|
|
|
|
BOOST_TRY
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::construct_from_tuple(
|
|
|
|
alloc, boost::addressof(address->second), boost::forward<A2>(a2));
|
|
|
|
}
|
|
|
|
BOOST_CATCH(...)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::destroy(
|
|
|
|
boost::addressof(address->first));
|
|
|
|
BOOST_RETHROW;
|
|
|
|
}
|
|
|
|
BOOST_CATCH_END
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Construct from variadic parameters
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T, typename... Args>
|
2017-04-19 09:20:31 +01:00
|
|
|
inline void construct_from_args(Alloc&, T* address, BOOST_FWD_REF(Args)... args)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
new ((void*)address) T(boost::forward<Args>(args)...);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
// Special case for piecewise_construct
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
template <typename Alloc, typename A, typename B, typename A0, typename A1,
|
|
|
|
typename A2>
|
|
|
|
inline typename enable_if<use_piecewise<A0>, void>::type construct_from_args(
|
|
|
|
Alloc& alloc, std::pair<A, B>* address, BOOST_FWD_REF(A0),
|
|
|
|
BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::construct_from_tuple(
|
2017-04-18 10:14:26 +01:00
|
|
|
alloc, boost::addressof(address->first), boost::forward<A1>(a1));
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_TRY
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::unordered::detail::func::construct_from_tuple(
|
2017-04-18 10:14:26 +01:00
|
|
|
alloc, boost::addressof(address->second), boost::forward<A2>(a2));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_CATCH(...)
|
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::destroy(
|
|
|
|
boost::addressof(address->first));
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_RETHROW;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_CATCH_END
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#else // BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Construct from emplace_args
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Explicitly write out first three overloads for the sake of sane
|
|
|
|
// error messages.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T, typename A0>
|
|
|
|
inline void construct_from_args(
|
|
|
|
Alloc&, T* address, emplace_args1<A0> const& args)
|
|
|
|
{
|
|
|
|
new ((void*)address) T(boost::forward<A0>(args.a0));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T, typename A0, typename A1>
|
|
|
|
inline void construct_from_args(
|
|
|
|
Alloc&, T* address, emplace_args2<A0, A1> const& args)
|
|
|
|
{
|
|
|
|
new ((void*)address)
|
|
|
|
T(boost::forward<A0>(args.a0), boost::forward<A1>(args.a1));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename T, typename A0, typename A1, typename A2>
|
|
|
|
inline void construct_from_args(
|
|
|
|
Alloc&, T* address, emplace_args3<A0, A1, A2> const& args)
|
|
|
|
{
|
|
|
|
new ((void*)address) T(boost::forward<A0>(args.a0),
|
|
|
|
boost::forward<A1>(args.a1), boost::forward<A2>(args.a2));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Use a macro for the rest.
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_CONSTRUCT_IMPL(z, num_params, _) \
|
|
|
|
template <typename Alloc, typename T, \
|
|
|
|
BOOST_PP_ENUM_PARAMS_Z(z, num_params, typename A)> \
|
|
|
|
inline void construct_from_args(Alloc&, T* address, \
|
|
|
|
boost::unordered::detail::BOOST_PP_CAT(emplace_args, num_params) < \
|
|
|
|
BOOST_PP_ENUM_PARAMS_Z(z, num_params, A) > const& args) \
|
|
|
|
{ \
|
|
|
|
new ((void*)address) T(BOOST_PP_ENUM_##z( \
|
|
|
|
num_params, BOOST_UNORDERED_CALL_FORWARD, args.a)); \
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_PP_REPEAT_FROM_TO(
|
|
|
|
4, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_CONSTRUCT_IMPL, _)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#undef BOOST_UNORDERED_CONSTRUCT_IMPL
|
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
// Construct with piecewise_construct
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
template <typename Alloc, typename A, typename B, typename A0, typename A1,
|
|
|
|
typename A2>
|
|
|
|
inline void construct_from_args(Alloc& alloc, std::pair<A, B>* address,
|
|
|
|
boost::unordered::detail::emplace_args3<A0, A1, A2> const& args,
|
|
|
|
typename enable_if<use_piecewise<A0>, void*>::type = 0)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::construct_from_tuple(
|
2017-04-18 10:14:26 +01:00
|
|
|
alloc, boost::addressof(address->first), args.a1);
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_TRY
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::construct_from_tuple(
|
2017-04-18 10:14:26 +01:00
|
|
|
alloc, boost::addressof(address->second), args.a2);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_CATCH(...)
|
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::destroy(
|
|
|
|
boost::addressof(address->first));
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_RETHROW;
|
|
|
|
}
|
|
|
|
BOOST_CATCH_END
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace detail {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Node construction
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename NodeAlloc> struct node_constructor
|
|
|
|
{
|
|
|
|
typedef NodeAlloc node_allocator;
|
|
|
|
typedef boost::unordered::detail::allocator_traits<NodeAlloc>
|
|
|
|
node_allocator_traits;
|
|
|
|
typedef typename node_allocator_traits::value_type node;
|
|
|
|
typedef typename node_allocator_traits::pointer node_pointer;
|
|
|
|
typedef typename node::value_type value_type;
|
|
|
|
|
|
|
|
node_allocator& alloc_;
|
|
|
|
node_pointer node_;
|
|
|
|
bool node_constructed_;
|
|
|
|
|
|
|
|
node_constructor(node_allocator& n)
|
|
|
|
: alloc_(n), node_(), node_constructed_(false)
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
~node_constructor();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void create_node();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// no throw
|
|
|
|
node_pointer release()
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_ASSERT(node_ && node_constructed_);
|
|
|
|
node_pointer p = node_;
|
|
|
|
node_ = node_pointer();
|
|
|
|
return p;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void reclaim(node_pointer p)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
BOOST_ASSERT(!node_);
|
2017-02-19 13:05:17 +00:00
|
|
|
node_ = p;
|
2017-02-19 13:05:17 +00:00
|
|
|
node_constructed_ = true;
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, alloc_, node_->value_ptr());
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
node_constructor(node_constructor const&);
|
|
|
|
node_constructor& operator=(node_constructor const&);
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc> node_constructor<Alloc>::~node_constructor()
|
|
|
|
{
|
|
|
|
if (node_) {
|
|
|
|
if (node_constructed_) {
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, alloc_, boost::addressof(*node_));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator_traits::deallocate(alloc_, node_, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Alloc> void node_constructor<Alloc>::create_node()
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(!node_);
|
|
|
|
node_constructed_ = false;
|
|
|
|
|
|
|
|
node_ = node_allocator_traits::allocate(alloc_, 1);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT0(
|
|
|
|
node_allocator_traits, alloc_, boost::addressof(*node_));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_->init(node_);
|
|
|
|
node_constructed_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename NodeAlloc> struct node_tmp
|
|
|
|
{
|
|
|
|
typedef boost::unordered::detail::allocator_traits<NodeAlloc>
|
|
|
|
node_allocator_traits;
|
|
|
|
typedef typename node_allocator_traits::pointer node_pointer;
|
|
|
|
|
|
|
|
NodeAlloc& alloc_;
|
|
|
|
node_pointer node_;
|
|
|
|
|
|
|
|
explicit node_tmp(node_pointer n, NodeAlloc& a) : alloc_(a), node_(n) {}
|
|
|
|
|
|
|
|
~node_tmp();
|
|
|
|
|
|
|
|
// no throw
|
|
|
|
node_pointer release()
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer p = node_;
|
|
|
|
node_ = node_pointer();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Alloc> node_tmp<Alloc>::~node_tmp()
|
|
|
|
{
|
|
|
|
if (node_) {
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, alloc_, node_->value_ptr());
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, alloc_, boost::addressof(*node_));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator_traits::deallocate(alloc_, node_, 1);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace detail {
|
|
|
|
namespace func {
|
|
|
|
|
|
|
|
// Some nicer construct_node functions, might try to
|
|
|
|
// improve implementation later.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
inline typename boost::unordered::detail::allocator_traits<Alloc>::pointer
|
|
|
|
construct_node_from_args(Alloc& alloc, BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
|
|
|
node_constructor<Alloc> a(alloc);
|
|
|
|
a.create_node();
|
|
|
|
construct_from_args(
|
|
|
|
alloc, a.node_->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD);
|
|
|
|
return a.release();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename U>
|
|
|
|
inline typename boost::unordered::detail::allocator_traits<Alloc>::pointer
|
|
|
|
construct_node(Alloc& alloc, BOOST_FWD_REF(U) x)
|
|
|
|
{
|
|
|
|
node_constructor<Alloc> a(alloc);
|
|
|
|
a.create_node();
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT1(
|
|
|
|
boost::unordered::detail::allocator_traits<Alloc>, alloc,
|
|
|
|
a.node_->value_ptr(), boost::forward<U>(x));
|
2017-02-19 13:05:17 +00:00
|
|
|
return a.release();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
#if BOOST_UNORDERED_CXX11_CONSTRUCTION
|
|
|
|
|
|
|
|
template <typename Alloc, typename Key>
|
|
|
|
inline typename boost::unordered::detail::allocator_traits<Alloc>::pointer
|
|
|
|
construct_node_pair(Alloc& alloc, BOOST_FWD_REF(Key) k)
|
|
|
|
{
|
|
|
|
node_constructor<Alloc> a(alloc);
|
|
|
|
a.create_node();
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::allocator_traits<Alloc>::construct(alloc,
|
|
|
|
a.node_->value_ptr(), std::piecewise_construct,
|
|
|
|
std::forward_as_tuple(boost::forward<Key>(k)), std::forward_as_tuple());
|
2017-04-18 10:14:26 +01:00
|
|
|
return a.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Alloc, typename Key, typename Mapped>
|
|
|
|
inline typename boost::unordered::detail::allocator_traits<Alloc>::pointer
|
|
|
|
construct_node_pair(Alloc& alloc, BOOST_FWD_REF(Key) k, BOOST_FWD_REF(Mapped) m)
|
|
|
|
{
|
|
|
|
node_constructor<Alloc> a(alloc);
|
|
|
|
a.create_node();
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::allocator_traits<Alloc>::construct(alloc,
|
|
|
|
a.node_->value_ptr(), std::piecewise_construct,
|
|
|
|
std::forward_as_tuple(boost::forward<Key>(k)),
|
2017-04-18 10:14:26 +01:00
|
|
|
std::forward_as_tuple(boost::forward<Mapped>(m)));
|
|
|
|
return a.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Alloc, typename Key, typename... Args>
|
|
|
|
inline typename boost::unordered::detail::allocator_traits<Alloc>::pointer
|
|
|
|
construct_node_pair_from_args(
|
|
|
|
Alloc& alloc, BOOST_FWD_REF(Key) k, BOOST_FWD_REF(Args)... args)
|
|
|
|
{
|
|
|
|
node_constructor<Alloc> a(alloc);
|
|
|
|
a.create_node();
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::allocator_traits<Alloc>::construct(alloc,
|
|
|
|
a.node_->value_ptr(), std::piecewise_construct,
|
|
|
|
std::forward_as_tuple(boost::forward<Key>(k)),
|
2017-04-18 10:14:26 +01:00
|
|
|
std::forward_as_tuple(boost::forward<Args>(args)...));
|
|
|
|
return a.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename Key>
|
|
|
|
inline typename boost::unordered::detail::allocator_traits<Alloc>::pointer
|
|
|
|
construct_node_pair(Alloc& alloc, BOOST_FWD_REF(Key) k)
|
|
|
|
{
|
|
|
|
node_constructor<Alloc> a(alloc);
|
|
|
|
a.create_node();
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::addressof(a.node_->value_ptr()->first), boost::forward<Key>(k));
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_TRY
|
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::addressof(a.node_->value_ptr()->second));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
BOOST_CATCH(...)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::destroy(
|
|
|
|
boost::addressof(a.node_->value_ptr()->first));
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_RETHROW;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_CATCH_END
|
|
|
|
return a.release();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Alloc, typename Key, typename Mapped>
|
|
|
|
inline typename boost::unordered::detail::allocator_traits<Alloc>::pointer
|
|
|
|
construct_node_pair(Alloc& alloc, BOOST_FWD_REF(Key) k, BOOST_FWD_REF(Mapped) m)
|
|
|
|
{
|
|
|
|
node_constructor<Alloc> a(alloc);
|
|
|
|
a.create_node();
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::addressof(a.node_->value_ptr()->first), boost::forward<Key>(k));
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_TRY
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::addressof(a.node_->value_ptr()->second),
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::forward<Mapped>(m));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_CATCH(...)
|
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::destroy(
|
|
|
|
boost::addressof(a.node_->value_ptr()->first));
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_RETHROW;
|
|
|
|
}
|
|
|
|
BOOST_CATCH_END
|
|
|
|
return a.release();
|
|
|
|
}
|
2017-02-27 03:59:02 +00:00
|
|
|
|
|
|
|
template <typename Alloc, typename Key, BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
inline typename boost::unordered::detail::allocator_traits<Alloc>::pointer
|
|
|
|
construct_node_pair_from_args(
|
|
|
|
Alloc& alloc, BOOST_FWD_REF(Key) k, BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
|
|
|
node_constructor<Alloc> a(alloc);
|
|
|
|
a.create_node();
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_value(
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::addressof(a.node_->value_ptr()->first), boost::forward<Key>(k));
|
2017-02-27 03:59:02 +00:00
|
|
|
BOOST_TRY
|
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::construct_from_args(alloc,
|
|
|
|
boost::addressof(a.node_->value_ptr()->second),
|
2017-02-27 03:59:02 +00:00
|
|
|
BOOST_UNORDERED_EMPLACE_FORWARD);
|
|
|
|
}
|
|
|
|
BOOST_CATCH(...)
|
|
|
|
{
|
2017-04-18 10:14:26 +01:00
|
|
|
boost::unordered::detail::func::destroy(
|
|
|
|
boost::addressof(a.node_->value_ptr()->first));
|
2017-02-27 03:59:02 +00:00
|
|
|
BOOST_RETHROW;
|
|
|
|
}
|
|
|
|
BOOST_CATCH_END
|
|
|
|
return a.release();
|
|
|
|
}
|
2017-04-18 10:14:26 +01:00
|
|
|
|
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// The 'iterator_detail' namespace was a misguided attempt at avoiding ADL
|
|
|
|
// in the detail namespace. It didn't work because the template parameters
|
|
|
|
// were in detail. I'm not changing it at the moment to be safe. I might
|
|
|
|
// do in the future if I change the iterator types.
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace iterator_detail {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Iterators
|
|
|
|
//
|
|
|
|
// all no throw
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Node, typename Policy>
|
|
|
|
struct l_iterator : public std::iterator<std::forward_iterator_tag,
|
|
|
|
typename Node::value_type, std::ptrdiff_t,
|
|
|
|
typename Node::value_type*, typename Node::value_type&>
|
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Node2, typename Policy2>
|
|
|
|
friend struct boost::unordered::iterator_detail::cl_iterator;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
#endif
|
|
|
|
typedef typename Node::node_pointer node_pointer;
|
|
|
|
node_pointer ptr_;
|
|
|
|
std::size_t bucket_;
|
|
|
|
std::size_t bucket_count_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
public:
|
|
|
|
typedef typename Node::value_type value_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
l_iterator() BOOST_NOEXCEPT : ptr_() {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
l_iterator(node_pointer n, std::size_t b, std::size_t c) BOOST_NOEXCEPT
|
|
|
|
: ptr_(n),
|
|
|
|
bucket_(b),
|
|
|
|
bucket_count_(c)
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type& operator*() const { return ptr_->value(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type* operator->() const { return ptr_->value_ptr(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
l_iterator& operator++()
|
|
|
|
{
|
|
|
|
ptr_ = static_cast<node_pointer>(ptr_->next_);
|
|
|
|
if (ptr_ && Policy::to_bucket(bucket_count_, ptr_->hash_) != bucket_)
|
|
|
|
ptr_ = node_pointer();
|
|
|
|
return *this;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
l_iterator operator++(int)
|
|
|
|
{
|
|
|
|
l_iterator tmp(*this);
|
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bool operator==(l_iterator x) const BOOST_NOEXCEPT
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
return ptr_ == x.ptr_;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bool operator!=(l_iterator x) const BOOST_NOEXCEPT
|
|
|
|
{
|
|
|
|
return ptr_ != x.ptr_;
|
|
|
|
}
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Node, typename Policy>
|
|
|
|
struct cl_iterator
|
|
|
|
: public std::iterator<std::forward_iterator_tag, typename Node::value_type,
|
|
|
|
std::ptrdiff_t, typename Node::value_type const*,
|
|
|
|
typename Node::value_type const&>
|
|
|
|
{
|
|
|
|
friend struct boost::unordered::iterator_detail::l_iterator<Node, Policy>;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
typedef typename Node::node_pointer node_pointer;
|
|
|
|
node_pointer ptr_;
|
|
|
|
std::size_t bucket_;
|
|
|
|
std::size_t bucket_count_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
public:
|
|
|
|
typedef typename Node::value_type value_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
cl_iterator() BOOST_NOEXCEPT : ptr_() {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
cl_iterator(node_pointer n, std::size_t b, std::size_t c) BOOST_NOEXCEPT
|
|
|
|
: ptr_(n),
|
|
|
|
bucket_(b),
|
|
|
|
bucket_count_(c)
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
cl_iterator(
|
|
|
|
boost::unordered::iterator_detail::l_iterator<Node, Policy> const& x)
|
|
|
|
BOOST_NOEXCEPT : ptr_(x.ptr_),
|
|
|
|
bucket_(x.bucket_),
|
|
|
|
bucket_count_(x.bucket_count_)
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type const& operator*() const { return ptr_->value(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type const* operator->() const { return ptr_->value_ptr(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
cl_iterator& operator++()
|
|
|
|
{
|
|
|
|
ptr_ = static_cast<node_pointer>(ptr_->next_);
|
|
|
|
if (ptr_ && Policy::to_bucket(bucket_count_, ptr_->hash_) != bucket_)
|
|
|
|
ptr_ = node_pointer();
|
|
|
|
return *this;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
cl_iterator operator++(int)
|
|
|
|
{
|
|
|
|
cl_iterator tmp(*this);
|
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
friend bool operator==(
|
|
|
|
cl_iterator const& x, cl_iterator const& y) BOOST_NOEXCEPT
|
|
|
|
{
|
|
|
|
return x.ptr_ == y.ptr_;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
friend bool operator!=(
|
|
|
|
cl_iterator const& x, cl_iterator const& y) BOOST_NOEXCEPT
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
return x.ptr_ != y.ptr_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Node>
|
|
|
|
struct iterator : public std::iterator<std::forward_iterator_tag,
|
|
|
|
typename Node::value_type, std::ptrdiff_t,
|
|
|
|
typename Node::value_type*, typename Node::value_type&>
|
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename>
|
|
|
|
friend struct boost::unordered::iterator_detail::c_iterator;
|
|
|
|
template <typename> friend struct boost::unordered::detail::table;
|
2017-04-15 17:35:08 +01:00
|
|
|
template <typename> friend struct boost::unordered::detail::table_unique;
|
|
|
|
template <typename> friend struct boost::unordered::detail::table_equiv;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
private:
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename Node::node_pointer node_pointer;
|
|
|
|
node_pointer node_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
public:
|
|
|
|
typedef typename Node::value_type value_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator() BOOST_NOEXCEPT : node_() {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
explicit iterator(typename Node::link_pointer x) BOOST_NOEXCEPT
|
|
|
|
: node_(static_cast<node_pointer>(x))
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type& operator*() const { return node_->value(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type* operator->() const { return node_->value_ptr(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator& operator++()
|
|
|
|
{
|
|
|
|
node_ = static_cast<node_pointer>(node_->next_);
|
|
|
|
return *this;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator operator++(int)
|
|
|
|
{
|
|
|
|
iterator tmp(node_);
|
|
|
|
node_ = static_cast<node_pointer>(node_->next_);
|
|
|
|
return tmp;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bool operator==(iterator const& x) const BOOST_NOEXCEPT
|
|
|
|
{
|
|
|
|
return node_ == x.node_;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bool operator!=(iterator const& x) const BOOST_NOEXCEPT
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
return node_ != x.node_;
|
|
|
|
}
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Node>
|
|
|
|
struct c_iterator
|
|
|
|
: public std::iterator<std::forward_iterator_tag, typename Node::value_type,
|
|
|
|
std::ptrdiff_t, typename Node::value_type const*,
|
|
|
|
typename Node::value_type const&>
|
|
|
|
{
|
|
|
|
friend struct boost::unordered::iterator_detail::iterator<Node>;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
|
|
|
template <typename> friend struct boost::unordered::detail::table;
|
2017-04-15 17:35:08 +01:00
|
|
|
template <typename> friend struct boost::unordered::detail::table_unique;
|
|
|
|
template <typename> friend struct boost::unordered::detail::table_equiv;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
#endif
|
|
|
|
typedef typename Node::node_pointer node_pointer;
|
|
|
|
typedef boost::unordered::iterator_detail::iterator<Node> n_iterator;
|
|
|
|
node_pointer node_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
public:
|
|
|
|
typedef typename Node::value_type value_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
c_iterator() BOOST_NOEXCEPT : node_() {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
explicit c_iterator(typename Node::link_pointer x) BOOST_NOEXCEPT
|
|
|
|
: node_(static_cast<node_pointer>(x))
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
c_iterator(n_iterator const& x) BOOST_NOEXCEPT : node_(x.node_) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type const& operator*() const { return node_->value(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type const* operator->() const { return node_->value_ptr(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
c_iterator& operator++()
|
|
|
|
{
|
|
|
|
node_ = static_cast<node_pointer>(node_->next_);
|
|
|
|
return *this;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
c_iterator operator++(int)
|
|
|
|
{
|
|
|
|
c_iterator tmp(node_);
|
|
|
|
node_ = static_cast<node_pointer>(node_->next_);
|
|
|
|
return tmp;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
friend bool operator==(
|
|
|
|
c_iterator const& x, c_iterator const& y) BOOST_NOEXCEPT
|
|
|
|
{
|
|
|
|
return x.node_ == y.node_;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
friend bool operator!=(
|
|
|
|
c_iterator const& x, c_iterator const& y) BOOST_NOEXCEPT
|
|
|
|
{
|
|
|
|
return x.node_ != y.node_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
namespace boost {
|
|
|
|
namespace unordered {
|
|
|
|
namespace detail {
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Node Holder
|
|
|
|
//
|
|
|
|
// Temporary store for nodes. Deletes any that aren't used.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename NodeAlloc> struct node_holder
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef NodeAlloc node_allocator;
|
|
|
|
typedef boost::unordered::detail::allocator_traits<NodeAlloc>
|
|
|
|
node_allocator_traits;
|
|
|
|
typedef typename node_allocator_traits::value_type node;
|
|
|
|
typedef typename node_allocator_traits::pointer node_pointer;
|
|
|
|
typedef typename node::value_type value_type;
|
|
|
|
typedef typename node::link_pointer link_pointer;
|
|
|
|
typedef boost::unordered::iterator_detail::iterator<node> iterator;
|
|
|
|
|
|
|
|
node_constructor<NodeAlloc> constructor_;
|
|
|
|
node_pointer nodes_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
template <typename Table>
|
|
|
|
explicit node_holder(Table& b) : constructor_(b.node_alloc()), nodes_()
|
|
|
|
{
|
|
|
|
if (b.size_) {
|
|
|
|
typename Table::link_pointer prev = b.get_previous_start();
|
|
|
|
nodes_ = static_cast<node_pointer>(prev->next_);
|
|
|
|
prev->next_ = link_pointer();
|
|
|
|
b.size_ = 0;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
~node_holder();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer pop_node()
|
|
|
|
{
|
|
|
|
node_pointer n = nodes_;
|
|
|
|
nodes_ = static_cast<node_pointer>(nodes_->next_);
|
|
|
|
n->init(n);
|
|
|
|
n->next_ = link_pointer();
|
|
|
|
return n;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> inline node_pointer copy_of(T const& v)
|
|
|
|
{
|
|
|
|
if (nodes_) {
|
|
|
|
constructor_.reclaim(pop_node());
|
|
|
|
} else {
|
|
|
|
constructor_.create_node();
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT1(node_allocator_traits,
|
2017-02-19 13:05:17 +00:00
|
|
|
constructor_.alloc_, constructor_.node_->value_ptr(), v);
|
|
|
|
return constructor_.release();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> inline node_pointer move_copy_of(T& v)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
if (nodes_) {
|
|
|
|
constructor_.reclaim(pop_node());
|
|
|
|
} else {
|
|
|
|
constructor_.create_node();
|
|
|
|
}
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT1(node_allocator_traits,
|
|
|
|
constructor_.alloc_, constructor_.node_->value_ptr(),
|
|
|
|
boost::move(v));
|
2017-02-19 13:05:17 +00:00
|
|
|
return constructor_.release();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator begin() const { return iterator(nodes_); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Alloc> node_holder<Alloc>::~node_holder()
|
|
|
|
{
|
|
|
|
while (nodes_) {
|
|
|
|
node_pointer p = nodes_;
|
|
|
|
nodes_ = static_cast<node_pointer>(p->next_);
|
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, constructor_.alloc_, p->value_ptr());
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, constructor_.alloc_, boost::addressof(*p));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator_traits::deallocate(constructor_.alloc_, p, 1);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Bucket
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename NodePointer> struct bucket
|
|
|
|
{
|
|
|
|
typedef NodePointer link_pointer;
|
|
|
|
link_pointer next_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket() : next_() {}
|
2017-04-18 10:14:26 +01:00
|
|
|
bucket(link_pointer n) : next_(n) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
link_pointer first_from_start() { return next_; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
extra_node = true
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
struct ptr_bucket
|
|
|
|
{
|
|
|
|
typedef ptr_bucket* link_pointer;
|
|
|
|
link_pointer next_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
ptr_bucket() : next_(0) {}
|
2017-04-18 10:14:26 +01:00
|
|
|
ptr_bucket(link_pointer n) : next_(n) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
link_pointer first_from_start() { return this; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
extra_node = false
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Hash Policy
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename SizeT> struct prime_policy
|
|
|
|
{
|
|
|
|
template <typename Hash, typename T>
|
|
|
|
static inline SizeT apply_hash(Hash const& hf, T const& x)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
return hf(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static inline SizeT to_bucket(SizeT bucket_count, SizeT hash)
|
|
|
|
{
|
|
|
|
return hash % bucket_count;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static inline SizeT new_bucket_count(SizeT min)
|
|
|
|
{
|
|
|
|
return boost::unordered::detail::next_prime(min);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static inline SizeT prev_bucket_count(SizeT max)
|
|
|
|
{
|
|
|
|
return boost::unordered::detail::prev_prime(max);
|
|
|
|
}
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename SizeT> struct mix64_policy
|
|
|
|
{
|
|
|
|
template <typename Hash, typename T>
|
|
|
|
static inline SizeT apply_hash(Hash const& hf, T const& x)
|
|
|
|
{
|
|
|
|
SizeT key = hf(x);
|
|
|
|
key = (~key) + (key << 21); // key = (key << 21) - key - 1;
|
|
|
|
key = key ^ (key >> 24);
|
|
|
|
key = (key + (key << 3)) + (key << 8); // key * 265
|
|
|
|
key = key ^ (key >> 14);
|
|
|
|
key = (key + (key << 2)) + (key << 4); // key * 21
|
|
|
|
key = key ^ (key >> 28);
|
|
|
|
key = key + (key << 31);
|
|
|
|
return key;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static inline SizeT to_bucket(SizeT bucket_count, SizeT hash)
|
|
|
|
{
|
|
|
|
return hash & (bucket_count - 1);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static inline SizeT new_bucket_count(SizeT min)
|
|
|
|
{
|
|
|
|
if (min <= 4)
|
|
|
|
return 4;
|
|
|
|
--min;
|
|
|
|
min |= min >> 1;
|
|
|
|
min |= min >> 2;
|
|
|
|
min |= min >> 4;
|
|
|
|
min |= min >> 8;
|
|
|
|
min |= min >> 16;
|
|
|
|
min |= min >> 32;
|
|
|
|
return min + 1;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static inline SizeT prev_bucket_count(SizeT max)
|
|
|
|
{
|
|
|
|
max |= max >> 1;
|
|
|
|
max |= max >> 2;
|
|
|
|
max |= max >> 4;
|
|
|
|
max |= max >> 8;
|
|
|
|
max |= max >> 16;
|
|
|
|
max |= max >> 32;
|
|
|
|
return (max >> 1) + 1;
|
|
|
|
}
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <int digits, int radix> struct pick_policy_impl
|
|
|
|
{
|
|
|
|
typedef prime_policy<std::size_t> type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <> struct pick_policy_impl<64, 2>
|
|
|
|
{
|
|
|
|
typedef mix64_policy<std::size_t> type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
2017-02-23 20:14:27 +00:00
|
|
|
struct pick_policy2 : pick_policy_impl<std::numeric_limits<std::size_t>::digits,
|
|
|
|
std::numeric_limits<std::size_t>::radix>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// While the mix policy is generally faster, the prime policy is a lot
|
|
|
|
// faster when a large number consecutive integers are used, because
|
|
|
|
// there are no collisions. Since that is probably quite common, use
|
|
|
|
// prime policy for integeral types. But not the smaller ones, as they
|
|
|
|
// don't have enough unique values for this to be an issue.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
template <> struct pick_policy2<int>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef prime_policy<std::size_t> type;
|
|
|
|
};
|
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
template <> struct pick_policy2<unsigned int>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef prime_policy<std::size_t> type;
|
|
|
|
};
|
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
template <> struct pick_policy2<long>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef prime_policy<std::size_t> type;
|
|
|
|
};
|
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
template <> struct pick_policy2<unsigned long>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef prime_policy<std::size_t> type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// TODO: Maybe not if std::size_t is smaller than long long.
|
2017-02-19 13:05:17 +00:00
|
|
|
#if !defined(BOOST_NO_LONG_LONG)
|
2017-02-23 20:14:27 +00:00
|
|
|
template <> struct pick_policy2<boost::long_long_type>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef prime_policy<std::size_t> type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
template <> struct pick_policy2<boost::ulong_long_type>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef prime_policy<std::size_t> type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
template <typename T>
|
|
|
|
struct pick_policy : pick_policy2<typename boost::remove_cv<T>::type>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Functions
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Assigning and swapping the equality and hash function objects
|
|
|
|
// needs strong exception safety. To implement that normally we'd
|
|
|
|
// require one of them to be known to not throw and the other to
|
|
|
|
// guarantee strong exception safety. Unfortunately they both only
|
|
|
|
// have basic exception safety. So to acheive strong exception
|
|
|
|
// safety we have storage space for two copies, and assign the new
|
|
|
|
// copies to the unused space. Then switch to using that to use
|
|
|
|
// them. This is implemented in 'set_hash_functions' which
|
|
|
|
// atomically assigns the new function objects in a strongly
|
|
|
|
// exception safe manner.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class H, class P, bool NoThrowMoveAssign> class set_hash_functions;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class H, class P> class functions
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const bool nothrow_move_assignable =
|
|
|
|
boost::is_nothrow_move_assignable<H>::value &&
|
|
|
|
boost::is_nothrow_move_assignable<P>::value;
|
|
|
|
static const bool nothrow_move_constructible =
|
|
|
|
boost::is_nothrow_move_constructible<H>::value &&
|
|
|
|
boost::is_nothrow_move_constructible<P>::value;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
friend class boost::unordered::detail::set_hash_functions<H, P,
|
|
|
|
nothrow_move_assignable>;
|
|
|
|
functions& operator=(functions const&);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef compressed<H, P> function_pair;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename boost::aligned_storage<sizeof(function_pair),
|
|
|
|
boost::alignment_of<function_pair>::value>::type aligned_function;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bool current_; // The currently active functions.
|
|
|
|
aligned_function funcs_[2];
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
function_pair const& current() const
|
|
|
|
{
|
|
|
|
return *static_cast<function_pair const*>(
|
2017-04-16 10:37:10 +01:00
|
|
|
static_cast<void const*>(funcs_[current_].address()));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
function_pair& current()
|
|
|
|
{
|
|
|
|
return *static_cast<function_pair*>(
|
2017-04-16 10:37:10 +01:00
|
|
|
static_cast<void*>(funcs_[current_].address()));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void construct(bool which, H const& hf, P const& eq)
|
|
|
|
{
|
|
|
|
new ((void*)&funcs_[which]) function_pair(hf, eq);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void construct(bool which, function_pair const& f,
|
|
|
|
boost::unordered::detail::false_type =
|
|
|
|
boost::unordered::detail::false_type())
|
|
|
|
{
|
|
|
|
new ((void*)&funcs_[which]) function_pair(f);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void construct(
|
|
|
|
bool which, function_pair& f, boost::unordered::detail::true_type)
|
|
|
|
{
|
|
|
|
new ((void*)&funcs_[which])
|
|
|
|
function_pair(f, boost::unordered::detail::move_tag());
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void destroy(bool which)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::destroy(
|
|
|
|
(function_pair*)(&funcs_[which]));
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef boost::unordered::detail::set_hash_functions<H, P,
|
|
|
|
nothrow_move_assignable>
|
|
|
|
set_hash_functions;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
functions(H const& hf, P const& eq) : current_(false)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
construct(current_, hf, eq);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
functions(functions const& bf) : current_(false)
|
|
|
|
{
|
|
|
|
construct(current_, bf.current());
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
functions(functions& bf, boost::unordered::detail::move_tag)
|
|
|
|
: current_(false)
|
|
|
|
{
|
|
|
|
construct(current_, bf.current(),
|
|
|
|
boost::unordered::detail::integral_constant<bool,
|
|
|
|
nothrow_move_constructible>());
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
~functions() { this->destroy(current_); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
H const& hash_function() const { return current().first(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
P const& key_eq() const { return current().second(); }
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class H, class P> class set_hash_functions<H, P, false>
|
|
|
|
{
|
|
|
|
set_hash_functions(set_hash_functions const&);
|
|
|
|
set_hash_functions& operator=(set_hash_functions const&);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef functions<H, P> functions_type;
|
|
|
|
|
|
|
|
functions_type& functions_;
|
|
|
|
bool tmp_functions_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
set_hash_functions(functions_type& f, H const& h, P const& p)
|
|
|
|
: functions_(f), tmp_functions_(!f.current_)
|
|
|
|
{
|
|
|
|
f.construct(tmp_functions_, h, p);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
set_hash_functions(functions_type& f, functions_type const& other)
|
|
|
|
: functions_(f), tmp_functions_(!f.current_)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
f.construct(tmp_functions_, other.current());
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
~set_hash_functions() { functions_.destroy(tmp_functions_); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void commit()
|
|
|
|
{
|
|
|
|
functions_.current_ = tmp_functions_;
|
|
|
|
tmp_functions_ = !tmp_functions_;
|
|
|
|
}
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class H, class P> class set_hash_functions<H, P, true>
|
|
|
|
{
|
|
|
|
set_hash_functions(set_hash_functions const&);
|
|
|
|
set_hash_functions& operator=(set_hash_functions const&);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef functions<H, P> functions_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
functions_type& functions_;
|
|
|
|
H hash_;
|
|
|
|
P pred_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
public:
|
|
|
|
set_hash_functions(functions_type& f, H const& h, P const& p)
|
|
|
|
: functions_(f), hash_(h), pred_(p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
set_hash_functions(functions_type& f, functions_type const& other)
|
|
|
|
: functions_(f), hash_(other.hash_function()), pred_(other.key_eq())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void commit()
|
|
|
|
{
|
|
|
|
functions_.current().first() = boost::move(hash_);
|
|
|
|
functions_.current().second() = boost::move(pred_);
|
|
|
|
}
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rvalue parameters when type can't be a BOOST_RV_REF(T) parameter
|
|
|
|
// e.g. for int
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_RV_REF(T) BOOST_RV_REF(T)
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
struct please_ignore_this_overload
|
|
|
|
{
|
|
|
|
typedef please_ignore_this_overload type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> struct rv_ref_impl
|
|
|
|
{
|
|
|
|
typedef BOOST_RV_REF(T) type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T>
|
|
|
|
struct rv_ref
|
|
|
|
: boost::detail::if_true<boost::is_class<T>::value>::BOOST_NESTED_TEMPLATE
|
|
|
|
then<boost::unordered::detail::rv_ref_impl<T>,
|
|
|
|
please_ignore_this_overload>::type
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BOOST_UNORDERED_RV_REF(T) \
|
|
|
|
typename boost::unordered::detail::rv_ref<T>::type
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
#pragma warning(push)
|
2017-02-19 13:05:17 +00:00
|
|
|
#pragma warning(disable : 4127) // conditional expression is constant
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// convert double to std::size_t
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
inline std::size_t double_to_size(double f)
|
|
|
|
{
|
|
|
|
return f >= static_cast<double>((std::numeric_limits<std::size_t>::max)())
|
|
|
|
? (std::numeric_limits<std::size_t>::max)()
|
|
|
|
: static_cast<std::size_t>(f);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// The space used to store values in a node.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename ValueType> struct value_base
|
|
|
|
{
|
|
|
|
typedef ValueType value_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typename boost::aligned_storage<sizeof(value_type),
|
|
|
|
boost::alignment_of<value_type>::value>::type data_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_base() : data_() {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void* address() { return this; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type& value() { return *(ValueType*)this; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
value_type const& value() const { return *(ValueType const*)this; }
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type* value_ptr() { return (ValueType*)this; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
value_type const* value_ptr() const { return (ValueType const*)this; }
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
value_base& operator=(value_base const&);
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Types>
|
|
|
|
struct table : boost::unordered::detail::functions<typename Types::hasher,
|
|
|
|
typename Types::key_equal>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
table(table const&);
|
|
|
|
table& operator=(table const&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef typename Types::node node;
|
|
|
|
typedef typename Types::bucket bucket;
|
|
|
|
typedef typename Types::hasher hasher;
|
|
|
|
typedef typename Types::key_equal key_equal;
|
2017-02-23 20:14:27 +00:00
|
|
|
typedef typename Types::const_key_type const_key_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename Types::extractor extractor;
|
|
|
|
typedef typename Types::value_type value_type;
|
|
|
|
typedef typename Types::table table_impl;
|
|
|
|
typedef typename Types::link_pointer link_pointer;
|
|
|
|
typedef typename Types::policy policy;
|
|
|
|
typedef typename Types::iterator iterator;
|
|
|
|
typedef typename Types::c_iterator c_iterator;
|
|
|
|
typedef typename Types::l_iterator l_iterator;
|
|
|
|
typedef typename Types::cl_iterator cl_iterator;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef typename Types::node_algo node_algo;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
typedef boost::unordered::detail::functions<typename Types::hasher,
|
|
|
|
typename Types::key_equal>
|
|
|
|
functions;
|
|
|
|
typedef typename functions::set_hash_functions set_hash_functions;
|
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
typedef typename Types::value_allocator value_allocator;
|
|
|
|
typedef typename boost::unordered::detail::rebind_wrap<value_allocator,
|
2017-02-19 13:05:17 +00:00
|
|
|
node>::type node_allocator;
|
2017-02-23 20:14:27 +00:00
|
|
|
typedef typename boost::unordered::detail::rebind_wrap<value_allocator,
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket>::type bucket_allocator;
|
|
|
|
typedef boost::unordered::detail::allocator_traits<node_allocator>
|
|
|
|
node_allocator_traits;
|
|
|
|
typedef boost::unordered::detail::allocator_traits<bucket_allocator>
|
|
|
|
bucket_allocator_traits;
|
|
|
|
typedef typename node_allocator_traits::pointer node_pointer;
|
|
|
|
typedef typename node_allocator_traits::const_pointer const_node_pointer;
|
|
|
|
typedef typename bucket_allocator_traits::pointer bucket_pointer;
|
|
|
|
typedef boost::unordered::detail::node_constructor<node_allocator>
|
|
|
|
node_constructor;
|
|
|
|
typedef boost::unordered::detail::node_tmp<node_allocator> node_tmp;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Members
|
|
|
|
|
|
|
|
boost::unordered::detail::compressed<bucket_allocator, node_allocator>
|
|
|
|
allocators_;
|
|
|
|
std::size_t bucket_count_;
|
|
|
|
std::size_t size_;
|
|
|
|
float mlf_;
|
|
|
|
std::size_t max_load_;
|
|
|
|
bucket_pointer buckets_;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Data access
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket_allocator const& bucket_alloc() const { return allocators_.first(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator const& node_alloc() const { return allocators_.second(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket_allocator& bucket_alloc() { return allocators_.first(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator& node_alloc() { return allocators_.second(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t max_bucket_count() const
|
|
|
|
{
|
|
|
|
// -1 to account for the start bucket.
|
|
|
|
return policy::prev_bucket_count(
|
|
|
|
bucket_allocator_traits::max_size(bucket_alloc()) - 1);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket_pointer get_bucket(std::size_t bucket_index) const
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(buckets_);
|
|
|
|
return buckets_ + static_cast<std::ptrdiff_t>(bucket_index);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
link_pointer get_previous_start() const
|
|
|
|
{
|
|
|
|
return get_bucket(bucket_count_)->first_from_start();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
link_pointer get_previous_start(std::size_t bucket_index) const
|
|
|
|
{
|
|
|
|
return get_bucket(bucket_index)->next_;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer begin() const
|
|
|
|
{
|
2017-02-27 03:59:02 +00:00
|
|
|
return size_ ? node_algo::next_node(get_previous_start())
|
|
|
|
: node_pointer();
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer begin(std::size_t bucket_index) const
|
|
|
|
{
|
|
|
|
if (!size_)
|
|
|
|
return node_pointer();
|
|
|
|
link_pointer prev = get_previous_start(bucket_index);
|
2017-02-27 03:59:02 +00:00
|
|
|
return prev ? node_algo::next_node(prev) : node_pointer();
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t hash_to_bucket(std::size_t hash_value) const
|
|
|
|
{
|
|
|
|
return policy::to_bucket(bucket_count_, hash_value);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
float load_factor() const
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(bucket_count_ != 0);
|
|
|
|
return static_cast<float>(size_) / static_cast<float>(bucket_count_);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t bucket_size(std::size_t index) const
|
|
|
|
{
|
|
|
|
node_pointer n = begin(index);
|
|
|
|
if (!n)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::size_t count = 0;
|
|
|
|
while (n && hash_to_bucket(n->hash_) == index) {
|
|
|
|
++count;
|
2017-02-27 03:59:02 +00:00
|
|
|
n = node_algo::next_node(n);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
return count;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Load methods
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t max_size() const
|
|
|
|
{
|
|
|
|
using namespace std;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// size < mlf_ * count
|
|
|
|
return boost::unordered::detail::double_to_size(
|
|
|
|
ceil(static_cast<double>(mlf_) *
|
|
|
|
static_cast<double>(max_bucket_count()))) -
|
|
|
|
1;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void recalculate_max_load()
|
|
|
|
{
|
|
|
|
using namespace std;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// From 6.3.1/13:
|
|
|
|
// Only resize when size >= mlf_ * count
|
|
|
|
max_load_ = buckets_ ? boost::unordered::detail::double_to_size(
|
|
|
|
ceil(static_cast<double>(mlf_) *
|
|
|
|
static_cast<double>(bucket_count_)))
|
|
|
|
: 0;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void max_load_factor(float z)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(z > 0);
|
|
|
|
mlf_ = (std::max)(z, minimum_max_load_factor);
|
|
|
|
recalculate_max_load();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t min_buckets_for_size(std::size_t size) const
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(mlf_ >= minimum_max_load_factor);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
using namespace std;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
// From insert/emplace requirements:
|
|
|
|
//
|
|
|
|
// size <= mlf_ * count
|
|
|
|
// => count >= size / mlf_
|
2017-02-19 13:05:17 +00:00
|
|
|
//
|
|
|
|
// Or from rehash post-condition:
|
2017-02-23 20:14:27 +00:00
|
|
|
//
|
|
|
|
// count >= size / mlf_
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
return policy::new_bucket_count(
|
|
|
|
boost::unordered::detail::double_to_size(
|
|
|
|
floor(static_cast<double>(size) / static_cast<double>(mlf_)) +
|
|
|
|
1));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constructors
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
table(std::size_t num_buckets, hasher const& hf, key_equal const& eq,
|
|
|
|
node_allocator const& a)
|
|
|
|
: functions(hf, eq), allocators_(a, a),
|
|
|
|
bucket_count_(policy::new_bucket_count(num_buckets)), size_(0),
|
|
|
|
mlf_(1.0f), max_load_(0), buckets_()
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
table(table const& x, node_allocator const& a)
|
|
|
|
: functions(x), allocators_(a, a),
|
|
|
|
bucket_count_(x.min_buckets_for_size(x.size_)), size_(0),
|
|
|
|
mlf_(x.mlf_), max_load_(0), buckets_()
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
table(table& x, boost::unordered::detail::move_tag m)
|
|
|
|
: functions(x, m), allocators_(x.allocators_, m),
|
|
|
|
bucket_count_(x.bucket_count_), size_(x.size_), mlf_(x.mlf_),
|
|
|
|
max_load_(x.max_load_), buckets_(x.buckets_)
|
|
|
|
{
|
|
|
|
x.buckets_ = bucket_pointer();
|
|
|
|
x.size_ = 0;
|
|
|
|
x.max_load_ = 0;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
table(
|
|
|
|
table& x, node_allocator const& a, boost::unordered::detail::move_tag m)
|
|
|
|
: functions(x, m), allocators_(a, a), bucket_count_(x.bucket_count_),
|
|
|
|
size_(0), mlf_(x.mlf_), max_load_(x.max_load_), buckets_()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Initialisation.
|
|
|
|
|
|
|
|
void init(table const& x)
|
|
|
|
{
|
|
|
|
if (x.size_) {
|
|
|
|
static_cast<table_impl*>(this)->copy_buckets(x);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void move_init(table& x)
|
|
|
|
{
|
|
|
|
if (node_alloc() == x.node_alloc()) {
|
|
|
|
move_buckets_from(x);
|
|
|
|
} else if (x.size_) {
|
|
|
|
// TODO: Could pick new bucket size?
|
|
|
|
static_cast<table_impl*>(this)->move_buckets(x);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2017-04-15 17:35:09 +01:00
|
|
|
// Clear buckets and Create buckets
|
|
|
|
//
|
|
|
|
// IMPORTANT: If the container already contains any elements, the
|
|
|
|
// buckets will not contain any links to them. This will
|
|
|
|
// need to be dealt with, for example by:
|
|
|
|
// - deleting them
|
|
|
|
// - putting them in a 'node_holder' for future use
|
|
|
|
// (as in assignment)
|
|
|
|
// - placing them in buckets (see rehash_impl)
|
|
|
|
|
|
|
|
// Clear the bucket pointers.
|
|
|
|
void clear_buckets()
|
|
|
|
{
|
|
|
|
bucket_pointer end = get_bucket(bucket_count_);
|
|
|
|
for (bucket_pointer it = buckets_; it != end; ++it) {
|
|
|
|
it->next_ = node_pointer();
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:09 +01:00
|
|
|
// Create container buckets. If the container already contains any buckets
|
|
|
|
// the linked list will be transferred to the new buckets, but none
|
|
|
|
// of the bucket pointers will be set. See above note.
|
|
|
|
//
|
|
|
|
// Strong exception safety.
|
2017-02-19 13:05:17 +00:00
|
|
|
void create_buckets(std::size_t new_count)
|
|
|
|
{
|
|
|
|
std::size_t length = new_count + 1;
|
|
|
|
bucket_pointer new_buckets =
|
|
|
|
bucket_allocator_traits::allocate(bucket_alloc(), length);
|
|
|
|
bucket_pointer constructed = new_buckets;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_TRY
|
|
|
|
{
|
|
|
|
bucket_pointer end =
|
2017-04-18 10:14:26 +01:00
|
|
|
new_buckets + static_cast<std::ptrdiff_t>(new_count);
|
2017-02-19 13:05:17 +00:00
|
|
|
for (; constructed != end; ++constructed) {
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT0(bucket_allocator_traits,
|
2017-04-18 10:14:26 +01:00
|
|
|
bucket_alloc(), boost::addressof(*constructed));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (buckets_) {
|
|
|
|
// Copy the nodes to the new buckets, including the dummy
|
|
|
|
// node if there is one.
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT1(bucket_allocator_traits,
|
|
|
|
bucket_alloc(), boost::addressof(*constructed),
|
2017-02-19 13:05:17 +00:00
|
|
|
(buckets_ + static_cast<std::ptrdiff_t>(bucket_count_))
|
2017-04-18 10:14:26 +01:00
|
|
|
->next_);
|
|
|
|
++constructed;
|
2017-02-19 13:05:17 +00:00
|
|
|
destroy_buckets();
|
|
|
|
} else if (bucket::extra_node) {
|
|
|
|
node_constructor a(node_alloc());
|
|
|
|
a.create_node();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT1(bucket_allocator_traits,
|
|
|
|
bucket_alloc(), boost::addressof(*constructed),
|
|
|
|
a.release());
|
2017-04-18 10:14:26 +01:00
|
|
|
++constructed;
|
|
|
|
} else {
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT0(bucket_allocator_traits,
|
2017-04-18 10:14:26 +01:00
|
|
|
bucket_alloc(), boost::addressof(*constructed));
|
|
|
|
++constructed;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_CATCH(...)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
for (bucket_pointer p = new_buckets; p != constructed; ++p) {
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(bucket_allocator_traits,
|
2017-04-18 10:14:26 +01:00
|
|
|
bucket_alloc(), boost::addressof(*p));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket_allocator_traits::deallocate(
|
|
|
|
bucket_alloc(), new_buckets, length);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_RETHROW;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_CATCH_END
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket_count_ = new_count;
|
|
|
|
buckets_ = new_buckets;
|
|
|
|
recalculate_max_load();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Swap and Move
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void swap_allocators(table& other, false_type)
|
|
|
|
{
|
|
|
|
boost::unordered::detail::func::ignore_unused_variable_warning(other);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// According to 23.2.1.8, if propagate_on_container_swap is
|
|
|
|
// false the behaviour is undefined unless the allocators
|
|
|
|
// are equal.
|
|
|
|
BOOST_ASSERT(node_alloc() == other.node_alloc());
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void swap_allocators(table& other, true_type)
|
|
|
|
{
|
|
|
|
allocators_.swap(other.allocators_);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Only swaps the allocators if propagate_on_container_swap
|
|
|
|
void swap(table& x)
|
|
|
|
{
|
|
|
|
set_hash_functions op1(*this, x);
|
|
|
|
set_hash_functions op2(x, *this);
|
|
|
|
|
|
|
|
// I think swap can throw if Propagate::value,
|
|
|
|
// since the allocators' swap can throw. Not sure though.
|
|
|
|
swap_allocators(x, boost::unordered::detail::integral_constant<bool,
|
|
|
|
allocator_traits<node_allocator>::
|
|
|
|
propagate_on_container_swap::value>());
|
|
|
|
|
|
|
|
boost::swap(buckets_, x.buckets_);
|
|
|
|
boost::swap(bucket_count_, x.bucket_count_);
|
|
|
|
boost::swap(size_, x.size_);
|
|
|
|
std::swap(mlf_, x.mlf_);
|
|
|
|
std::swap(max_load_, x.max_load_);
|
|
|
|
op1.commit();
|
|
|
|
op2.commit();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Only call with nodes allocated with the currect allocator, or
|
|
|
|
// one that is equal to it. (Can't assert because other's
|
|
|
|
// allocators might have already been moved).
|
|
|
|
void move_buckets_from(table& other)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(!buckets_);
|
|
|
|
buckets_ = other.buckets_;
|
|
|
|
bucket_count_ = other.bucket_count_;
|
|
|
|
size_ = other.size_;
|
|
|
|
other.buckets_ = bucket_pointer();
|
|
|
|
other.size_ = 0;
|
|
|
|
other.max_load_ = 0;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Delete/destruct
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
~table() { delete_buckets(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void delete_node(link_pointer prev)
|
|
|
|
{
|
|
|
|
node_pointer n = static_cast<node_pointer>(prev->next_);
|
|
|
|
prev->next_ = n->next_;
|
|
|
|
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, node_alloc(), n->value_ptr());
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, node_alloc(), boost::addressof(*n));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator_traits::deallocate(node_alloc(), n, 1);
|
|
|
|
--size_;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t delete_nodes(link_pointer prev, link_pointer end)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(prev->next_ != end);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t count = 0;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
do {
|
|
|
|
delete_node(prev);
|
|
|
|
++count;
|
|
|
|
} while (prev->next_ != end);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
return count;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void delete_buckets()
|
|
|
|
{
|
|
|
|
if (buckets_) {
|
|
|
|
if (size_)
|
|
|
|
delete_nodes(get_previous_start(), link_pointer());
|
|
|
|
|
|
|
|
if (bucket::extra_node) {
|
|
|
|
node_pointer n =
|
|
|
|
static_cast<node_pointer>(get_bucket(bucket_count_)->next_);
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
node_allocator_traits, node_alloc(), boost::addressof(*n));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator_traits::deallocate(node_alloc(), n, 1);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
destroy_buckets();
|
|
|
|
buckets_ = bucket_pointer();
|
|
|
|
max_load_ = 0;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_ASSERT(!size_);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
if (!size_)
|
|
|
|
return;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
clear_buckets();
|
2017-04-15 17:35:08 +01:00
|
|
|
delete_nodes(get_previous_start(), link_pointer());
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
BOOST_ASSERT(!size_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_buckets()
|
|
|
|
{
|
|
|
|
bucket_pointer end = get_bucket(bucket_count_ + 1);
|
|
|
|
for (bucket_pointer it = buckets_; it != end; ++it) {
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_DESTROY(
|
|
|
|
bucket_allocator_traits, bucket_alloc(), boost::addressof(*it));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket_allocator_traits::deallocate(
|
|
|
|
bucket_alloc(), buckets_, bucket_count_ + 1);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Fix buckets after delete
|
|
|
|
//
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t fix_bucket(std::size_t bucket_index, link_pointer prev)
|
|
|
|
{
|
|
|
|
link_pointer end = prev->next_;
|
|
|
|
std::size_t bucket_index2 = bucket_index;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (end) {
|
|
|
|
bucket_index2 =
|
|
|
|
hash_to_bucket(static_cast<node_pointer>(end)->hash_);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// If begin and end are in the same bucket, then
|
|
|
|
// there's nothing to do.
|
|
|
|
if (bucket_index == bucket_index2)
|
|
|
|
return bucket_index2;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Update the bucket containing end.
|
|
|
|
get_bucket(bucket_index2)->next_ = prev;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Check if this bucket is now empty.
|
|
|
|
bucket_pointer this_bucket = get_bucket(bucket_index);
|
|
|
|
if (this_bucket->next_ == prev)
|
|
|
|
this_bucket->next_ = link_pointer();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
return bucket_index2;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Assignment
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void assign(table const& x)
|
|
|
|
{
|
|
|
|
if (this != boost::addressof(x)) {
|
|
|
|
assign(x, boost::unordered::detail::integral_constant<bool,
|
|
|
|
allocator_traits<node_allocator>::
|
|
|
|
propagate_on_container_copy_assignment::value>());
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void assign(table const& x, false_type)
|
|
|
|
{
|
|
|
|
// Strong exception safety.
|
|
|
|
set_hash_functions new_func_this(*this, x);
|
|
|
|
mlf_ = x.mlf_;
|
|
|
|
recalculate_max_load();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (!size_ && !x.size_) {
|
2017-02-19 13:05:17 +00:00
|
|
|
new_func_this.commit();
|
2017-02-19 13:05:17 +00:00
|
|
|
return;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (x.size_ >= max_load_) {
|
|
|
|
create_buckets(min_buckets_for_size(x.size_));
|
|
|
|
} else {
|
|
|
|
clear_buckets();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
new_func_this.commit();
|
|
|
|
static_cast<table_impl*>(this)->assign_buckets(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void assign(table const& x, true_type)
|
|
|
|
{
|
|
|
|
if (node_alloc() == x.node_alloc()) {
|
|
|
|
allocators_.assign(x.allocators_);
|
|
|
|
assign(x, false_type());
|
|
|
|
} else {
|
|
|
|
set_hash_functions new_func_this(*this, x);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Delete everything with current allocators before assigning
|
|
|
|
// the new ones.
|
|
|
|
delete_buckets();
|
|
|
|
allocators_.assign(x.allocators_);
|
|
|
|
|
|
|
|
// Copy over other data, all no throw.
|
|
|
|
new_func_this.commit();
|
|
|
|
mlf_ = x.mlf_;
|
|
|
|
bucket_count_ = min_buckets_for_size(x.size_);
|
|
|
|
max_load_ = 0;
|
|
|
|
|
|
|
|
// Finally copy the elements.
|
|
|
|
if (x.size_) {
|
|
|
|
static_cast<table_impl*>(this)->copy_buckets(x);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void move_assign(table& x)
|
|
|
|
{
|
|
|
|
if (this != boost::addressof(x)) {
|
|
|
|
move_assign(
|
|
|
|
x, boost::unordered::detail::integral_constant<bool,
|
|
|
|
allocator_traits<node_allocator>::
|
|
|
|
propagate_on_container_move_assignment::value>());
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void move_assign(table& x, true_type)
|
|
|
|
{
|
|
|
|
delete_buckets();
|
|
|
|
set_hash_functions new_func_this(*this, x);
|
|
|
|
allocators_.move_assign(x.allocators_);
|
|
|
|
// No throw from here.
|
|
|
|
mlf_ = x.mlf_;
|
|
|
|
max_load_ = x.max_load_;
|
|
|
|
move_buckets_from(x);
|
|
|
|
new_func_this.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void move_assign(table& x, false_type)
|
|
|
|
{
|
|
|
|
if (node_alloc() == x.node_alloc()) {
|
2017-02-19 13:05:17 +00:00
|
|
|
delete_buckets();
|
|
|
|
set_hash_functions new_func_this(*this, x);
|
|
|
|
// No throw from here.
|
|
|
|
mlf_ = x.mlf_;
|
|
|
|
max_load_ = x.max_load_;
|
|
|
|
move_buckets_from(x);
|
|
|
|
new_func_this.commit();
|
2017-02-19 13:05:17 +00:00
|
|
|
} else {
|
|
|
|
set_hash_functions new_func_this(*this, x);
|
|
|
|
mlf_ = x.mlf_;
|
|
|
|
recalculate_max_load();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (!size_ && !x.size_) {
|
2017-02-19 13:05:17 +00:00
|
|
|
new_func_this.commit();
|
2017-02-19 13:05:17 +00:00
|
|
|
return;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (x.size_ >= max_load_) {
|
|
|
|
create_buckets(min_buckets_for_size(x.size_));
|
|
|
|
} else {
|
|
|
|
clear_buckets();
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
new_func_this.commit();
|
|
|
|
static_cast<table_impl*>(this)->move_assign_buckets(x);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Accessors
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& get_key(node_pointer n) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-04-15 17:35:08 +01:00
|
|
|
return extractor::extract(n->value());
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
std::size_t hash(const_key_type& k) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
return policy::apply_hash(this->hash_function(), k);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Find Node
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Key, typename Hash, typename Pred>
|
|
|
|
node_pointer generic_find_node(
|
|
|
|
Key const& k, Hash const& hf, Pred const& eq) const
|
|
|
|
{
|
2017-02-27 03:59:02 +00:00
|
|
|
return this->find_node_impl(policy::apply_hash(hf, k), k, eq);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
node_pointer find_node(std::size_t key_hash, const_key_type& k) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-27 03:59:02 +00:00
|
|
|
return this->find_node_impl(key_hash, k, this->key_eq());
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
node_pointer find_node(const_key_type& k) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-27 03:59:02 +00:00
|
|
|
return this->find_node_impl(hash(k), k, this->key_eq());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Key, class Pred>
|
|
|
|
node_pointer find_node_impl(
|
|
|
|
std::size_t key_hash, Key const& k, Pred const& eq) const
|
|
|
|
{
|
|
|
|
std::size_t bucket_index = this->hash_to_bucket(key_hash);
|
|
|
|
node_pointer n = this->begin(bucket_index);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!n)
|
|
|
|
return n;
|
|
|
|
|
|
|
|
std::size_t node_hash = n->hash_;
|
|
|
|
if (key_hash == node_hash) {
|
2017-04-15 17:35:08 +01:00
|
|
|
if (eq(k, this->get_key(n)))
|
2017-02-27 03:59:02 +00:00
|
|
|
return n;
|
|
|
|
} else {
|
|
|
|
if (this->hash_to_bucket(node_hash) != bucket_index)
|
|
|
|
return node_pointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
n = node_algo::next_for_find(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the node before the key, so that it can be erased.
|
|
|
|
link_pointer find_previous_node(
|
|
|
|
const_key_type& k, std::size_t key_hash, std::size_t bucket_index)
|
|
|
|
{
|
|
|
|
link_pointer prev = this->get_previous_start(bucket_index);
|
|
|
|
if (!prev) {
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!prev->next_) {
|
|
|
|
return link_pointer();
|
|
|
|
}
|
|
|
|
std::size_t node_hash = node_algo::next_node(prev)->hash_;
|
|
|
|
if (this->hash_to_bucket(node_hash) != bucket_index) {
|
|
|
|
return link_pointer();
|
|
|
|
}
|
|
|
|
if (node_hash == key_hash &&
|
2017-04-15 17:35:08 +01:00
|
|
|
this->key_eq()(k, this->get_key(node_algo::next_node(prev)))) {
|
2017-02-27 03:59:02 +00:00
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
prev = node_algo::next_for_erase(prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract and erase
|
|
|
|
|
|
|
|
inline node_pointer extract_by_key(const_key_type& k)
|
|
|
|
{
|
|
|
|
if (!this->size_) {
|
|
|
|
return node_pointer();
|
|
|
|
}
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
std::size_t bucket_index = this->hash_to_bucket(key_hash);
|
|
|
|
link_pointer prev = this->find_previous_node(k, key_hash, bucket_index);
|
|
|
|
if (!prev) {
|
|
|
|
return node_pointer();
|
|
|
|
}
|
|
|
|
node_pointer n = node_algo::extract_first_node(prev);
|
|
|
|
--this->size_;
|
|
|
|
this->fix_bucket(bucket_index, prev);
|
|
|
|
n->next_ = link_pointer();
|
|
|
|
|
|
|
|
return n;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Reserve and rehash
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void reserve_for_insert(std::size_t);
|
|
|
|
void rehash(std::size_t);
|
|
|
|
void reserve(std::size_t);
|
2017-02-27 03:59:02 +00:00
|
|
|
void rehash_impl(std::size_t);
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Reserve & Rehash
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// basic exception safety
|
|
|
|
template <typename Types>
|
|
|
|
inline void table<Types>::reserve_for_insert(std::size_t size)
|
|
|
|
{
|
|
|
|
if (!buckets_) {
|
|
|
|
create_buckets((std::max)(bucket_count_, min_buckets_for_size(size)));
|
2017-02-23 20:14:27 +00:00
|
|
|
} else if (size > max_load_) {
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t num_buckets =
|
|
|
|
min_buckets_for_size((std::max)(size, size_ + (size_ >> 1)));
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (num_buckets != bucket_count_)
|
2017-02-27 03:59:02 +00:00
|
|
|
this->rehash_impl(num_buckets);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// if hash function throws, basic exception safety
|
|
|
|
// strong otherwise.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Types>
|
|
|
|
inline void table<Types>::rehash(std::size_t min_buckets)
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
if (!size_) {
|
|
|
|
delete_buckets();
|
|
|
|
bucket_count_ = policy::new_bucket_count(min_buckets);
|
|
|
|
} else {
|
|
|
|
min_buckets = policy::new_bucket_count((std::max)(min_buckets,
|
|
|
|
boost::unordered::detail::double_to_size(
|
|
|
|
floor(static_cast<double>(size_) / static_cast<double>(mlf_))) +
|
|
|
|
1));
|
|
|
|
|
|
|
|
if (min_buckets != bucket_count_)
|
2017-02-27 03:59:02 +00:00
|
|
|
this->rehash_impl(min_buckets);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Types>
|
|
|
|
inline void table<Types>::reserve(std::size_t num_elements)
|
|
|
|
{
|
|
|
|
rehash(static_cast<std::size_t>(
|
|
|
|
std::ceil(static_cast<double>(num_elements) / mlf_)));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename Types>
|
|
|
|
inline void table<Types>::rehash_impl(std::size_t num_buckets)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(this->buckets_);
|
|
|
|
|
|
|
|
this->create_buckets(num_buckets);
|
|
|
|
link_pointer prev = this->get_previous_start();
|
2017-02-27 03:59:02 +00:00
|
|
|
while (prev->next_) {
|
|
|
|
node_pointer group_last = node_algo::last_for_rehash(prev);
|
|
|
|
bucket_pointer b =
|
|
|
|
this->get_bucket(this->hash_to_bucket(group_last->hash_));
|
|
|
|
if (!b->next_) {
|
|
|
|
b->next_ = prev;
|
|
|
|
prev = group_last;
|
|
|
|
} else {
|
|
|
|
link_pointer next = group_last->next_;
|
|
|
|
group_last->next_ = b->next_->next_;
|
|
|
|
b->next_->next_ = prev->next_;
|
|
|
|
prev->next_ = next;
|
|
|
|
}
|
|
|
|
}
|
2017-02-27 03:59:02 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2017-02-23 20:14:26 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2017-02-19 13:05:17 +00:00
|
|
|
// key extractors
|
|
|
|
//
|
|
|
|
// no throw
|
|
|
|
//
|
|
|
|
// 'extract_key' is called with the emplace parameters to return a
|
|
|
|
// key if available or 'no_key' is one isn't and will need to be
|
|
|
|
// constructed. This could be done by overloading the emplace implementation
|
|
|
|
// for the different cases, but that's a bit tricky on compilers without
|
|
|
|
// variadic templates.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
struct no_key
|
|
|
|
{
|
|
|
|
no_key() {}
|
|
|
|
template <class T> no_key(T const&) {}
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Key, typename T> struct is_key
|
|
|
|
{
|
|
|
|
template <typename T2> static choice1::type test(T2 const&);
|
|
|
|
static choice2::type test(Key const&);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
value = sizeof(test(boost::unordered::detail::make<T>())) ==
|
|
|
|
sizeof(choice2::type)
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename boost::detail::if_true<value>::BOOST_NESTED_TEMPLATE
|
|
|
|
then<Key const&, no_key>::type type;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class ValueType> struct set_extractor
|
|
|
|
{
|
|
|
|
typedef ValueType value_type;
|
|
|
|
typedef ValueType key_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static key_type const& extract(value_type const& v) { return v; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static no_key extract() { return no_key(); }
|
|
|
|
|
|
|
|
template <class Arg> static no_key extract(Arg const&) { return no_key(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class Arg1, class Arg2, class... Args>
|
|
|
|
static no_key extract(Arg1 const&, Arg2 const&, Args const&...)
|
|
|
|
{
|
|
|
|
return no_key();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class Arg1, class Arg2>
|
|
|
|
static no_key extract(Arg1 const&, Arg2 const&)
|
|
|
|
{
|
|
|
|
return no_key();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
template <class ValueType> struct map_extractor
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef ValueType value_type;
|
2017-02-23 20:14:27 +00:00
|
|
|
typedef typename boost::remove_const<typename boost::unordered::detail::
|
|
|
|
pair_traits<ValueType>::first_type>::type key_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static key_type const& extract(value_type const& v) { return v.first; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class Second>
|
|
|
|
static key_type const& extract(std::pair<key_type, Second> const& v)
|
|
|
|
{
|
|
|
|
return v.first;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class Second>
|
|
|
|
static key_type const& extract(std::pair<key_type const, Second> const& v)
|
|
|
|
{
|
|
|
|
return v.first;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class Arg1>
|
|
|
|
static key_type const& extract(key_type const& k, Arg1 const&)
|
|
|
|
{
|
|
|
|
return k;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static no_key extract() { return no_key(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class Arg> static no_key extract(Arg const&) { return no_key(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class Arg1, class Arg2>
|
|
|
|
static no_key extract(Arg1 const&, Arg2 const&)
|
|
|
|
{
|
|
|
|
return no_key();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class Arg1, class Arg2, class Arg3, class... Args>
|
|
|
|
static no_key extract(Arg1 const&, Arg2 const&, Arg3 const&, Args const&...)
|
|
|
|
{
|
|
|
|
return no_key();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_KEY_FROM_TUPLE(namespace_) \
|
|
|
|
template <typename T2> \
|
|
|
|
static no_key extract(boost::unordered::piecewise_construct_t, \
|
|
|
|
namespace_ tuple<> const&, T2 const&) \
|
|
|
|
{ \
|
|
|
|
return no_key(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
template <typename T, typename T2> \
|
|
|
|
static typename is_key<key_type, T>::type extract( \
|
|
|
|
boost::unordered::piecewise_construct_t, namespace_ tuple<T> const& k, \
|
|
|
|
T2 const&) \
|
|
|
|
{ \
|
|
|
|
return typename is_key<key_type, T>::type(namespace_ get<0>(k)); \
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#define BOOST_UNORDERED_KEY_FROM_TUPLE(namespace_) \
|
|
|
|
static no_key extract( \
|
|
|
|
boost::unordered::piecewise_construct_t, namespace_ tuple<> const&) \
|
|
|
|
{ \
|
|
|
|
return no_key(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
template <typename T> \
|
|
|
|
static typename is_key<key_type, T>::type extract( \
|
|
|
|
boost::unordered::piecewise_construct_t, namespace_ tuple<T> const& k) \
|
|
|
|
{ \
|
|
|
|
return typename is_key<key_type, T>::type(namespace_ get<0>(k)); \
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_UNORDERED_KEY_FROM_TUPLE(boost::)
|
2017-02-19 13:05:17 +00:00
|
|
|
|
More consistent std::tuple configuration
Was getting a weird test failure for Visual C++ 11,
BOOST_NO_CXX11_HDR_TUPLE is defined, so the code doesn't support
std::tuple, but BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT was also
true, and so there are functions for constructing using
std::piecewise_construct/std::tuple, which don't work.
So, I'm assuming that if BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT is true,
then there must be a std::tuple. I guess it doesn't have full C++11 support,
which is why BOOST_NO_CXX11_HDR_TUPLE is defined, but it appears to be
good enough for us. If not, this will break things.
2017-04-21 20:26:32 +01:00
|
|
|
#if BOOST_UNORDERED_HAS_STD_TUPLE
|
2017-02-19 13:05:17 +00:00
|
|
|
BOOST_UNORDERED_KEY_FROM_TUPLE(std::)
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:26 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Unique nodes
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A, typename T>
|
|
|
|
struct unique_node : boost::unordered::detail::value_base<T>
|
|
|
|
{
|
|
|
|
typedef typename ::boost::unordered::detail::rebind_wrap<A,
|
|
|
|
unique_node<A, T> >::type allocator;
|
|
|
|
typedef typename ::boost::unordered::detail::allocator_traits<
|
|
|
|
allocator>::pointer node_pointer;
|
|
|
|
typedef node_pointer link_pointer;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef typename ::boost::unordered::detail::rebind_wrap<A,
|
|
|
|
bucket<node_pointer> >::type bucket_allocator;
|
|
|
|
typedef typename ::boost::unordered::detail::allocator_traits<
|
|
|
|
bucket_allocator>::pointer bucket_pointer;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
link_pointer next_;
|
|
|
|
std::size_t hash_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
unique_node() : next_(), hash_(0) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void init(node_pointer) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
unique_node& operator=(unique_node const&);
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename T> struct ptr_node : boost::unordered::detail::ptr_bucket
|
|
|
|
{
|
|
|
|
typedef T value_type;
|
|
|
|
typedef boost::unordered::detail::ptr_bucket bucket_base;
|
|
|
|
typedef ptr_node<T>* node_pointer;
|
|
|
|
typedef ptr_bucket* link_pointer;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef ptr_bucket* bucket_pointer;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t hash_;
|
|
|
|
boost::unordered::detail::value_base<T> value_base_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
ptr_node() : bucket_base(), hash_(0) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void init(node_pointer) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void* address() { return value_base_.address(); }
|
|
|
|
value_type& value() { return value_base_.value(); }
|
|
|
|
value_type* value_ptr() { return value_base_.value_ptr(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
ptr_node& operator=(ptr_node const&);
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename N> struct node_algo
|
|
|
|
{
|
|
|
|
typedef typename N::node_pointer node_pointer;
|
|
|
|
typedef typename N::link_pointer link_pointer;
|
|
|
|
typedef typename N::bucket_pointer bucket_pointer;
|
|
|
|
|
|
|
|
static node_pointer next_node(link_pointer n)
|
|
|
|
{
|
|
|
|
return static_cast<node_pointer>(n->next_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static node_pointer next_for_find(node_pointer n)
|
|
|
|
{
|
|
|
|
return static_cast<node_pointer>(n->next_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static link_pointer next_for_erase(link_pointer prev)
|
|
|
|
{
|
|
|
|
return prev->next_;
|
|
|
|
}
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
// Group together all nodes with equal hash value, this may
|
|
|
|
// include nodes with different keys, but that's okay because
|
|
|
|
// they will end up in the same bucket.
|
|
|
|
static node_pointer last_for_rehash(link_pointer prev)
|
|
|
|
{
|
|
|
|
node_pointer n = next_node(prev);
|
|
|
|
std::size_t hash = n->hash_;
|
2017-02-27 12:20:37 +00:00
|
|
|
for (;;) {
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer next = next_node(n);
|
|
|
|
if (!next || next->hash_ != hash) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
n = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Table>
|
|
|
|
static node_pointer next_group(node_pointer n, Table const* t)
|
|
|
|
{
|
|
|
|
node_pointer n1 = n;
|
|
|
|
do {
|
|
|
|
n1 = next_node(n1);
|
2017-04-15 17:35:08 +01:00
|
|
|
} while (n1 && t->key_eq()(t->get_key(n), t->get_key(n1)));
|
2017-02-27 03:59:02 +00:00
|
|
|
return n1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Table>
|
|
|
|
static std::size_t count(node_pointer n, Table const* t)
|
|
|
|
{
|
|
|
|
std::size_t x = 0;
|
|
|
|
node_pointer it = n;
|
|
|
|
do {
|
|
|
|
++x;
|
|
|
|
it = next_node(it);
|
2017-04-15 17:35:08 +01:00
|
|
|
} while (it && t->key_eq()(t->get_key(n), t->get_key(it)));
|
2017-02-27 03:59:02 +00:00
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
// Add node 'n' after 'pos'.
|
|
|
|
// This results in a different order to the grouped implementation.
|
|
|
|
static inline void add_to_node_group(node_pointer n, node_pointer pos)
|
|
|
|
{
|
|
|
|
n->next_ = pos->next_;
|
|
|
|
pos->next_ = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline node_pointer extract_first_node(link_pointer prev)
|
|
|
|
{
|
|
|
|
node_pointer n = next_node(prev);
|
|
|
|
prev->next_ = n->next_;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
static link_pointer split_groups(node_pointer, node_pointer)
|
2017-02-27 03:59:02 +00:00
|
|
|
{
|
2017-02-27 03:59:02 +00:00
|
|
|
return link_pointer();
|
2017-02-27 03:59:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// If the allocator uses raw pointers use ptr_node
|
|
|
|
// Otherwise use node.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A, typename T, typename NodePtr, typename BucketPtr>
|
|
|
|
struct pick_node2
|
|
|
|
{
|
|
|
|
typedef boost::unordered::detail::unique_node<A, T> node;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename boost::unordered::detail::allocator_traits<
|
|
|
|
typename boost::unordered::detail::rebind_wrap<A, node>::type>::pointer
|
|
|
|
node_pointer;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef boost::unordered::detail::bucket<node_pointer> bucket;
|
|
|
|
typedef node_pointer link_pointer;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A, typename T>
|
|
|
|
struct pick_node2<A, T, boost::unordered::detail::ptr_node<T>*,
|
|
|
|
boost::unordered::detail::ptr_bucket*>
|
|
|
|
{
|
|
|
|
typedef boost::unordered::detail::ptr_node<T> node;
|
|
|
|
typedef boost::unordered::detail::ptr_bucket bucket;
|
|
|
|
typedef bucket* link_pointer;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A, typename T> struct pick_node
|
|
|
|
{
|
|
|
|
typedef typename boost::remove_const<T>::type nonconst;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef boost::unordered::detail::allocator_traits<
|
|
|
|
typename boost::unordered::detail::rebind_wrap<A,
|
|
|
|
boost::unordered::detail::ptr_node<nonconst> >::type>
|
|
|
|
tentative_node_traits;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef boost::unordered::detail::allocator_traits<
|
|
|
|
typename boost::unordered::detail::rebind_wrap<A,
|
|
|
|
boost::unordered::detail::ptr_bucket>::type>
|
|
|
|
tentative_bucket_traits;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef pick_node2<A, nonconst, typename tentative_node_traits::pointer,
|
|
|
|
typename tentative_bucket_traits::pointer>
|
|
|
|
pick;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename pick::node node;
|
|
|
|
typedef typename pick::bucket bucket;
|
|
|
|
typedef typename pick::link_pointer link_pointer;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef boost::unordered::detail::node_algo<node> node_algo;
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Types>
|
2017-04-15 17:35:08 +01:00
|
|
|
struct table_unique : boost::unordered::detail::table<Types>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef boost::unordered::detail::table<Types> table;
|
|
|
|
typedef typename table::value_type value_type;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef typename table::node node;
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename table::bucket bucket;
|
|
|
|
typedef typename table::policy policy;
|
|
|
|
typedef typename table::node_pointer node_pointer;
|
|
|
|
typedef typename table::node_allocator node_allocator;
|
|
|
|
typedef typename table::node_allocator_traits node_allocator_traits;
|
|
|
|
typedef typename table::bucket_pointer bucket_pointer;
|
|
|
|
typedef typename table::link_pointer link_pointer;
|
|
|
|
typedef typename table::hasher hasher;
|
|
|
|
typedef typename table::key_equal key_equal;
|
2017-02-23 20:14:27 +00:00
|
|
|
typedef typename table::const_key_type const_key_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename table::node_constructor node_constructor;
|
|
|
|
typedef typename table::node_tmp node_tmp;
|
|
|
|
typedef typename table::extractor extractor;
|
|
|
|
typedef typename table::iterator iterator;
|
|
|
|
typedef typename table::c_iterator c_iterator;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef typename table::node_algo node_algo;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
typedef std::pair<iterator, bool> emplace_return;
|
|
|
|
|
|
|
|
// Constructors
|
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_unique(std::size_t n, hasher const& hf, key_equal const& eq,
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator const& a)
|
|
|
|
: table(n, hf, eq, a)
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_unique(table_unique const& x)
|
2017-02-19 13:05:17 +00:00
|
|
|
: table(x, node_allocator_traits::select_on_container_copy_construction(
|
|
|
|
x.node_alloc()))
|
|
|
|
{
|
|
|
|
this->init(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_unique(table_unique const& x, node_allocator const& a) : table(x, a)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
this->init(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_unique(table_unique& x, boost::unordered::detail::move_tag m)
|
2017-02-19 13:05:17 +00:00
|
|
|
: table(x, m)
|
|
|
|
{
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_unique(table_unique& x, node_allocator const& a,
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::unordered::detail::move_tag m)
|
|
|
|
: table(x, a, m)
|
|
|
|
{
|
|
|
|
this->move_init(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Accessors
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
std::size_t count(const_key_type& k) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
return this->find_node(k) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
value_type& at(const_key_type& k) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
if (this->size_) {
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer n = this->find_node(k);
|
2017-02-19 13:05:17 +00:00
|
|
|
if (n)
|
|
|
|
return n->value();
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::throw_exception(
|
|
|
|
std::out_of_range("Unable to find key in unordered_map."));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
std::pair<iterator, iterator> equal_range(const_key_type& k) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
node_pointer n = this->find_node(k);
|
2017-02-27 03:59:02 +00:00
|
|
|
return std::make_pair(
|
|
|
|
iterator(n), iterator(n ? node_algo::next_node(n) : n));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// equals
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
bool equals(table_unique const& other) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
if (this->size_ != other.size_)
|
|
|
|
return false;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
for (node_pointer n1 = this->begin(); n1;
|
|
|
|
n1 = node_algo::next_node(n1)) {
|
2017-04-15 17:35:08 +01:00
|
|
|
node_pointer n2 = other.find_node(other.get_key(n1));
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
if (!n2 || n1->value() != n2->value())
|
|
|
|
return false;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Emplace/Insert
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
inline node_pointer add_node(node_pointer n, std::size_t key_hash)
|
|
|
|
{
|
|
|
|
n->hash_ = key_hash;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket_pointer b = this->get_bucket(this->hash_to_bucket(key_hash));
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (!b->next_) {
|
|
|
|
link_pointer start_node = this->get_previous_start();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (start_node->next_) {
|
2017-02-27 03:59:02 +00:00
|
|
|
this->get_bucket(this->hash_to_bucket(
|
|
|
|
node_algo::next_node(start_node)->hash_))
|
2017-02-19 13:05:17 +00:00
|
|
|
->next_ = n;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
b->next_ = start_node;
|
|
|
|
n->next_ = start_node->next_;
|
|
|
|
start_node->next_ = n;
|
|
|
|
} else {
|
|
|
|
n->next_ = b->next_->next_;
|
|
|
|
b->next_->next_ = n;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
++this->size_;
|
|
|
|
return n;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
inline node_pointer resize_and_add_node(
|
|
|
|
node_pointer n, std::size_t key_hash)
|
|
|
|
{
|
|
|
|
node_tmp b(n, this->node_alloc());
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
return this->add_node(b.release(), key_hash);
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
2017-02-19 13:05:17 +00:00
|
|
|
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
emplace_return emplace(boost::unordered::detail::emplace_args1<
|
|
|
|
boost::unordered::detail::please_ignore_this_overload> const&)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return emplace_return(iterator(), false);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator emplace_hint(
|
|
|
|
c_iterator,
|
|
|
|
boost::unordered::detail::emplace_args1<
|
|
|
|
boost::unordered::detail::please_ignore_this_overload> const&)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return iterator();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
emplace_return emplace(
|
|
|
|
boost::unordered::detail::please_ignore_this_overload const&)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return emplace_return(iterator(), false);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator emplace_hint(c_iterator,
|
|
|
|
boost::unordered::detail::please_ignore_this_overload const&)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return iterator();
|
|
|
|
}
|
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
emplace_return emplace(BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
2017-02-19 13:05:17 +00:00
|
|
|
return emplace_impl(extractor::extract(BOOST_UNORDERED_EMPLACE_FORWARD),
|
|
|
|
BOOST_UNORDERED_EMPLACE_FORWARD);
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
return emplace_impl(extractor::extract(args.a0, args.a1),
|
|
|
|
BOOST_UNORDERED_EMPLACE_FORWARD);
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
iterator emplace_hint(c_iterator hint, BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
2017-02-19 13:05:17 +00:00
|
|
|
return emplace_hint_impl(hint,
|
|
|
|
extractor::extract(BOOST_UNORDERED_EMPLACE_FORWARD),
|
|
|
|
BOOST_UNORDERED_EMPLACE_FORWARD);
|
2017-02-19 13:05:17 +00:00
|
|
|
#else
|
2017-02-19 13:05:17 +00:00
|
|
|
return emplace_hint_impl(hint, extractor::extract(args.a0, args.a1),
|
|
|
|
BOOST_UNORDERED_EMPLACE_FORWARD);
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A0>
|
|
|
|
emplace_return emplace(
|
|
|
|
boost::unordered::detail::emplace_args1<A0> const& args)
|
|
|
|
{
|
|
|
|
return emplace_impl(extractor::extract(args.a0), args);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A0>
|
|
|
|
iterator emplace_hint(c_iterator hint,
|
|
|
|
boost::unordered::detail::emplace_args1<A0> const& args)
|
|
|
|
{
|
|
|
|
return emplace_hint_impl(hint, extractor::extract(args.a0), args);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
iterator emplace_hint_impl(
|
2017-02-23 20:14:27 +00:00
|
|
|
c_iterator hint, const_key_type& k, BOOST_UNORDERED_EMPLACE_ARGS)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-04-15 17:35:08 +01:00
|
|
|
if (hint.node_ && this->key_eq()(k, this->get_key(hint.node_))) {
|
2017-02-19 13:05:17 +00:00
|
|
|
return iterator(hint.node_);
|
|
|
|
} else {
|
|
|
|
return emplace_impl(k, BOOST_UNORDERED_EMPLACE_FORWARD).first;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
2017-02-23 20:14:27 +00:00
|
|
|
emplace_return emplace_impl(const_key_type& k, BOOST_UNORDERED_EMPLACE_ARGS)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
if (pos) {
|
|
|
|
return emplace_return(iterator(pos), false);
|
|
|
|
} else {
|
|
|
|
return emplace_return(
|
|
|
|
iterator(this->resize_and_add_node(
|
|
|
|
boost::unordered::detail::func::construct_node_from_args(
|
|
|
|
this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD),
|
|
|
|
key_hash)),
|
|
|
|
true);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
iterator emplace_hint_impl(
|
|
|
|
c_iterator hint, no_key, BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
|
|
|
node_tmp b(boost::unordered::detail::func::construct_node_from_args(
|
|
|
|
this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD),
|
|
|
|
this->node_alloc());
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(b.node_);
|
|
|
|
if (hint.node_ && this->key_eq()(k, this->get_key(hint.node_))) {
|
2017-02-19 13:05:17 +00:00
|
|
|
return iterator(hint.node_);
|
|
|
|
}
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
if (pos) {
|
|
|
|
return iterator(pos);
|
|
|
|
} else {
|
|
|
|
return iterator(this->resize_and_add_node(b.release(), key_hash));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
emplace_return emplace_impl(no_key, BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
|
|
|
node_tmp b(boost::unordered::detail::func::construct_node_from_args(
|
|
|
|
this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD),
|
|
|
|
this->node_alloc());
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(b.node_);
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
if (pos) {
|
|
|
|
return emplace_return(iterator(pos), false);
|
|
|
|
} else {
|
|
|
|
return emplace_return(
|
|
|
|
iterator(this->resize_and_add_node(b.release(), key_hash)),
|
|
|
|
true);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename Key>
|
|
|
|
emplace_return try_emplace_impl(BOOST_FWD_REF(Key) k)
|
|
|
|
{
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
if (pos) {
|
|
|
|
return emplace_return(iterator(pos), false);
|
|
|
|
} else {
|
|
|
|
return emplace_return(
|
|
|
|
iterator(this->resize_and_add_node(
|
|
|
|
boost::unordered::detail::func::construct_node_pair(
|
|
|
|
this->node_alloc(), boost::forward<Key>(k)),
|
|
|
|
key_hash)),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Key>
|
|
|
|
iterator try_emplace_hint_impl(c_iterator hint, BOOST_FWD_REF(Key) k)
|
|
|
|
{
|
|
|
|
if (hint.node_ && this->key_eq()(hint->first, k)) {
|
|
|
|
return iterator(hint.node_);
|
|
|
|
} else {
|
|
|
|
return try_emplace_impl(k).first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Key, BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
emplace_return try_emplace_impl(
|
|
|
|
BOOST_FWD_REF(Key) k, BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
if (pos) {
|
|
|
|
return emplace_return(iterator(pos), false);
|
|
|
|
} else {
|
|
|
|
return emplace_return(
|
|
|
|
iterator(this->resize_and_add_node(
|
|
|
|
boost::unordered::detail::func::
|
|
|
|
construct_node_pair_from_args(this->node_alloc(),
|
|
|
|
boost::forward<Key>(k),
|
|
|
|
BOOST_UNORDERED_EMPLACE_FORWARD),
|
|
|
|
key_hash)),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Key, BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
iterator try_emplace_hint_impl(
|
|
|
|
c_iterator hint, BOOST_FWD_REF(Key) k, BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
|
|
|
if (hint.node_ && this->key_eq()(hint->first, k)) {
|
|
|
|
return iterator(hint.node_);
|
|
|
|
} else {
|
|
|
|
return try_emplace_impl(k, BOOST_UNORDERED_EMPLACE_FORWARD).first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename Key, typename M>
|
|
|
|
emplace_return insert_or_assign_impl(
|
|
|
|
BOOST_FWD_REF(Key) k, BOOST_FWD_REF(M) obj)
|
|
|
|
{
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
|
|
|
|
if (pos) {
|
|
|
|
pos->value().second = boost::forward<M>(obj);
|
|
|
|
return emplace_return(iterator(pos), false);
|
|
|
|
} else {
|
|
|
|
return emplace_return(
|
|
|
|
iterator(this->resize_and_add_node(
|
|
|
|
boost::unordered::detail::func::construct_node_pair(
|
|
|
|
this->node_alloc(), boost::forward<Key>(k),
|
|
|
|
boost::forward<M>(obj)),
|
|
|
|
key_hash)),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename NodeType, typename InsertReturnType>
|
|
|
|
void move_insert_node_type(NodeType& np, InsertReturnType& result)
|
|
|
|
{
|
|
|
|
if (np) {
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(np.ptr_);
|
2017-02-27 03:59:02 +00:00
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
|
|
|
|
if (pos) {
|
|
|
|
result.node = boost::move(np);
|
|
|
|
result.position = iterator(pos);
|
|
|
|
} else {
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
result.position = iterator(this->add_node(np.ptr_, key_hash));
|
|
|
|
result.inserted = true;
|
|
|
|
np.ptr_ = node_pointer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename NodeType>
|
|
|
|
iterator move_insert_node_type_with_hint(c_iterator hint, NodeType& np)
|
|
|
|
{
|
|
|
|
if (!np) {
|
|
|
|
return iterator();
|
|
|
|
}
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(np.ptr_);
|
|
|
|
if (hint.node_ && this->key_eq()(k, this->get_key(hint.node_))) {
|
2017-02-27 03:59:02 +00:00
|
|
|
return iterator(hint.node_);
|
|
|
|
}
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
if (!pos) {
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
pos = this->add_node(np.ptr_, key_hash);
|
|
|
|
np.ptr_ = node_pointer();
|
|
|
|
}
|
|
|
|
return iterator(pos);
|
|
|
|
}
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename Types2>
|
|
|
|
void merge_impl(boost::unordered::detail::table<Types2>& other)
|
2017-02-27 03:59:02 +00:00
|
|
|
{
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef boost::unordered::detail::table<Types2> other_table;
|
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
(boost::is_same<node, typename other_table::node>::value));
|
|
|
|
BOOST_ASSERT(this->node_alloc() == other.node_alloc());
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
if (other.size_) {
|
|
|
|
link_pointer prev = other.get_previous_start();
|
|
|
|
|
|
|
|
while (prev->next_) {
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer n = other_table::node_algo::next_node(prev);
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(n);
|
2017-02-27 03:59:02 +00:00
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
|
|
|
|
if (pos) {
|
|
|
|
prev = n;
|
|
|
|
} else {
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
2017-02-27 03:59:02 +00:00
|
|
|
other_table::node_algo::split_groups(
|
|
|
|
n, other_table::node_algo::next_node(n));
|
2017-02-27 03:59:02 +00:00
|
|
|
prev->next_ = n->next_;
|
|
|
|
--other.size_;
|
|
|
|
other.fix_bucket(other.hash_to_bucket(n->hash_), prev);
|
|
|
|
this->add_node(n, key_hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Insert range methods
|
|
|
|
//
|
|
|
|
// if hash function throws, or inserting > 1 element, basic exception
|
|
|
|
// safety strong otherwise
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class InputIt> void insert_range(InputIt i, InputIt j)
|
|
|
|
{
|
|
|
|
if (i != j)
|
|
|
|
return insert_range_impl(extractor::extract(*i), i, j);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class InputIt>
|
2017-02-23 20:14:27 +00:00
|
|
|
void insert_range_impl(const_key_type& k, InputIt i, InputIt j)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
insert_range_impl2(k, i, j);
|
|
|
|
|
|
|
|
while (++i != j) {
|
|
|
|
// Note: can't use get_key as '*i' might not be value_type - it
|
|
|
|
// could be a pair with first_types as key_type without const or
|
|
|
|
// a different second_type.
|
|
|
|
//
|
|
|
|
// TODO: Might be worth storing the value_type instead of the
|
|
|
|
// key here. Could be more efficient if '*i' is expensive. Could
|
|
|
|
// be less efficient if copying the full value_type is
|
|
|
|
// expensive.
|
|
|
|
insert_range_impl2(extractor::extract(*i), i, j);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class InputIt>
|
2017-02-23 20:14:27 +00:00
|
|
|
void insert_range_impl2(const_key_type& k, InputIt i, InputIt j)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
// No side effects in this initial code
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
|
|
|
|
if (!pos) {
|
|
|
|
node_tmp b(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), *i),
|
|
|
|
this->node_alloc());
|
|
|
|
if (this->size_ + 1 > this->max_load_)
|
|
|
|
this->reserve_for_insert(
|
|
|
|
this->size_ + boost::unordered::detail::insert_size(i, j));
|
|
|
|
this->add_node(b.release(), key_hash);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class InputIt>
|
|
|
|
void insert_range_impl(no_key, InputIt i, InputIt j)
|
|
|
|
{
|
|
|
|
node_constructor a(this->node_alloc());
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (!a.node_) {
|
|
|
|
a.create_node();
|
|
|
|
}
|
2017-04-18 10:14:26 +01:00
|
|
|
BOOST_UNORDERED_CALL_CONSTRUCT1(
|
|
|
|
node_allocator_traits, a.alloc_, a.node_->value_ptr(), *i);
|
2017-02-19 13:05:17 +00:00
|
|
|
node_tmp b(a.release(), a.alloc_);
|
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(b.node_);
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (pos) {
|
|
|
|
a.reclaim(b.release());
|
|
|
|
} else {
|
|
|
|
// reserve has basic exception safety if the hash function
|
|
|
|
// throws, strong otherwise.
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(b.release(), key_hash);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
} while (++i != j);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Extract
|
|
|
|
|
|
|
|
inline node_pointer extract_by_iterator(c_iterator i)
|
|
|
|
{
|
|
|
|
node_pointer n = i.node_;
|
|
|
|
BOOST_ASSERT(n);
|
|
|
|
std::size_t key_hash = n->hash_;
|
|
|
|
std::size_t bucket_index = this->hash_to_bucket(key_hash);
|
|
|
|
link_pointer prev = this->get_previous_start(bucket_index);
|
|
|
|
while (prev->next_ != n) {
|
|
|
|
prev = prev->next_;
|
|
|
|
}
|
|
|
|
prev->next_ = n->next_;
|
|
|
|
--this->size_;
|
|
|
|
this->fix_bucket(bucket_index, prev);
|
|
|
|
n->next_ = link_pointer();
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Erase
|
|
|
|
//
|
|
|
|
// no throw
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
std::size_t erase_key(const_key_type& k)
|
|
|
|
{
|
|
|
|
if (!this->size_)
|
|
|
|
return 0;
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
std::size_t bucket_index = this->hash_to_bucket(key_hash);
|
2017-02-27 03:59:02 +00:00
|
|
|
link_pointer prev = this->find_previous_node(k, key_hash, bucket_index);
|
2017-02-27 03:59:02 +00:00
|
|
|
if (!prev)
|
|
|
|
return 0;
|
2017-02-27 03:59:02 +00:00
|
|
|
link_pointer end = node_algo::next_node(prev)->next_;
|
2017-02-27 03:59:02 +00:00
|
|
|
this->delete_nodes(prev, end);
|
2017-02-19 13:05:17 +00:00
|
|
|
this->fix_bucket(bucket_index, prev);
|
2017-02-27 03:59:02 +00:00
|
|
|
return 1;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator erase(c_iterator r)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(r.node_);
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer next = node_algo::next_node(r.node_);
|
2017-02-19 13:05:17 +00:00
|
|
|
erase_nodes(r.node_, next);
|
|
|
|
return iterator(next);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator erase_range(c_iterator r1, c_iterator r2)
|
|
|
|
{
|
|
|
|
if (r1 == r2)
|
|
|
|
return iterator(r2.node_);
|
|
|
|
erase_nodes(r1.node_, r2.node_);
|
|
|
|
return iterator(r2.node_);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void erase_nodes(node_pointer i, node_pointer j)
|
|
|
|
{
|
|
|
|
std::size_t bucket_index = this->hash_to_bucket(i->hash_);
|
|
|
|
|
|
|
|
// Find the node before i.
|
|
|
|
link_pointer prev = this->get_previous_start(bucket_index);
|
|
|
|
while (prev->next_ != i)
|
|
|
|
prev = prev->next_;
|
|
|
|
|
|
|
|
// Delete the nodes.
|
|
|
|
do {
|
|
|
|
this->delete_node(prev);
|
|
|
|
bucket_index = this->fix_bucket(bucket_index, prev);
|
|
|
|
} while (prev->next_ != j);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// fill_buckets
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void copy_buckets(table const& src)
|
|
|
|
{
|
|
|
|
this->create_buckets(this->bucket_count_);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
for (node_pointer n = src.begin(); n; n = node_algo::next_node(n)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), n->value()),
|
|
|
|
n->hash_);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void move_buckets(table const& src)
|
|
|
|
{
|
|
|
|
this->create_buckets(this->bucket_count_);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
for (node_pointer n = src.begin(); n; n = node_algo::next_node(n)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), boost::move(n->value())),
|
|
|
|
n->hash_);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void assign_buckets(table const& src)
|
|
|
|
{
|
|
|
|
node_holder<node_allocator> holder(*this);
|
2017-02-27 03:59:02 +00:00
|
|
|
for (node_pointer n = src.begin(); n; n = node_algo::next_node(n)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(holder.copy_of(n->value()), n->hash_);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void move_assign_buckets(table& src)
|
|
|
|
{
|
|
|
|
node_holder<node_allocator> holder(*this);
|
2017-02-27 03:59:02 +00:00
|
|
|
for (node_pointer n = src.begin(); n; n = node_algo::next_node(n)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(holder.move_copy_of(n->value()), n->hash_);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:26 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Grouped nodes
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A, typename T>
|
|
|
|
struct grouped_node : boost::unordered::detail::value_base<T>
|
|
|
|
{
|
|
|
|
typedef typename ::boost::unordered::detail::rebind_wrap<A,
|
|
|
|
grouped_node<A, T> >::type allocator;
|
|
|
|
typedef typename ::boost::unordered::detail::allocator_traits<
|
|
|
|
allocator>::pointer node_pointer;
|
|
|
|
typedef node_pointer link_pointer;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef typename ::boost::unordered::detail::rebind_wrap<A,
|
|
|
|
bucket<node_pointer> >::type bucket_allocator;
|
|
|
|
typedef typename ::boost::unordered::detail::allocator_traits<
|
|
|
|
bucket_allocator>::pointer bucket_pointer;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
link_pointer next_;
|
|
|
|
node_pointer group_prev_;
|
|
|
|
std::size_t hash_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
grouped_node() : next_(), group_prev_(), hash_(0) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void init(node_pointer self) { group_prev_ = self; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
grouped_node& operator=(grouped_node const&);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct grouped_ptr_node : boost::unordered::detail::ptr_bucket
|
|
|
|
{
|
|
|
|
typedef T value_type;
|
|
|
|
typedef boost::unordered::detail::ptr_bucket bucket_base;
|
|
|
|
typedef grouped_ptr_node<T>* node_pointer;
|
|
|
|
typedef ptr_bucket* link_pointer;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef ptr_bucket* bucket_pointer;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer group_prev_;
|
|
|
|
std::size_t hash_;
|
|
|
|
boost::unordered::detail::value_base<T> value_base_;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
grouped_ptr_node() : bucket_base(), group_prev_(0), hash_(0) {}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void init(node_pointer self) { group_prev_ = self; }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void* address() { return value_base_.address(); }
|
|
|
|
value_type& value() { return value_base_.value(); }
|
|
|
|
value_type* value_ptr() { return value_base_.value_ptr(); }
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
private:
|
|
|
|
grouped_ptr_node& operator=(grouped_ptr_node const&);
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename N> struct grouped_node_algo
|
|
|
|
{
|
|
|
|
typedef typename N::node_pointer node_pointer;
|
|
|
|
typedef typename N::link_pointer link_pointer;
|
|
|
|
typedef typename N::bucket_pointer bucket_pointer;
|
|
|
|
|
|
|
|
static node_pointer next_node(link_pointer n)
|
|
|
|
{
|
|
|
|
return static_cast<node_pointer>(n->next_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static node_pointer next_for_find(node_pointer n)
|
|
|
|
{
|
|
|
|
return static_cast<node_pointer>(n->group_prev_->next_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static link_pointer next_for_erase(link_pointer prev)
|
|
|
|
{
|
|
|
|
return static_cast<node_pointer>(prev->next_)->group_prev_;
|
|
|
|
}
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
static node_pointer last_for_rehash(link_pointer prev)
|
|
|
|
{
|
|
|
|
return static_cast<node_pointer>(prev->next_)->group_prev_;
|
|
|
|
}
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
// The 'void*' arguments are pointers to the table, which we
|
|
|
|
// will ignore, but without groups they could be used to
|
|
|
|
// access the various functions for dealing with values and keys.
|
2017-02-27 03:59:02 +00:00
|
|
|
static node_pointer next_group(node_pointer n, void const*)
|
2017-02-27 03:59:02 +00:00
|
|
|
{
|
|
|
|
return static_cast<node_pointer>(n->group_prev_->next_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::size_t count(node_pointer n, void const*)
|
|
|
|
{
|
|
|
|
std::size_t x = 0;
|
|
|
|
node_pointer it = n;
|
|
|
|
do {
|
|
|
|
it = it->group_prev_;
|
|
|
|
++x;
|
|
|
|
} while (it != n);
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds node 'n' to the group containing 'pos'.
|
|
|
|
// If 'pos' is the first node in group, add to the end of the group,
|
|
|
|
// otherwise add before 'pos'. Other versions will probably behave
|
|
|
|
// differently.
|
|
|
|
static inline void add_to_node_group(node_pointer n, node_pointer pos)
|
|
|
|
{
|
|
|
|
n->next_ = pos->group_prev_->next_;
|
|
|
|
n->group_prev_ = pos->group_prev_;
|
|
|
|
pos->group_prev_->next_ = n;
|
|
|
|
pos->group_prev_ = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline node_pointer extract_first_node(link_pointer prev)
|
|
|
|
{
|
|
|
|
node_pointer n = next_node(prev);
|
|
|
|
if (n->group_prev_ != n) {
|
|
|
|
node_pointer next = next_node(n);
|
|
|
|
next->group_prev_ = n->group_prev_;
|
|
|
|
n->group_prev_ = n;
|
|
|
|
}
|
|
|
|
prev->next_ = n->next_;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split the groups containing 'i' and 'j' so that they can
|
|
|
|
// be safely erased/extracted.
|
|
|
|
static link_pointer split_groups(node_pointer i, node_pointer j)
|
|
|
|
{
|
|
|
|
node_pointer prev = i->group_prev_;
|
|
|
|
if (prev->next_ != i)
|
|
|
|
prev = node_pointer();
|
|
|
|
|
|
|
|
if (j) {
|
|
|
|
node_pointer first = j;
|
|
|
|
while (first != i && first->group_prev_->next_ == first) {
|
|
|
|
first = first->group_prev_;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::swap(first->group_prev_, j->group_prev_);
|
|
|
|
if (first == i)
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
node_pointer first = prev;
|
|
|
|
while (first->group_prev_->next_ == first) {
|
|
|
|
first = first->group_prev_;
|
|
|
|
}
|
|
|
|
boost::swap(first->group_prev_, i->group_prev_);
|
|
|
|
}
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// If the allocator uses raw pointers use grouped_ptr_node
|
|
|
|
// Otherwise use grouped_node.
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A, typename T, typename NodePtr, typename BucketPtr>
|
|
|
|
struct pick_grouped_node2
|
|
|
|
{
|
|
|
|
typedef boost::unordered::detail::grouped_node<A, T> node;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename boost::unordered::detail::allocator_traits<
|
|
|
|
typename boost::unordered::detail::rebind_wrap<A, node>::type>::pointer
|
|
|
|
node_pointer;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef boost::unordered::detail::bucket<node_pointer> bucket;
|
|
|
|
typedef node_pointer link_pointer;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A, typename T>
|
|
|
|
struct pick_grouped_node2<A, T, boost::unordered::detail::grouped_ptr_node<T>*,
|
|
|
|
boost::unordered::detail::ptr_bucket*>
|
|
|
|
{
|
|
|
|
typedef boost::unordered::detail::grouped_ptr_node<T> node;
|
|
|
|
typedef boost::unordered::detail::ptr_bucket bucket;
|
|
|
|
typedef bucket* link_pointer;
|
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename A, typename T> struct pick_grouped_node
|
|
|
|
{
|
|
|
|
typedef typename boost::remove_const<T>::type nonconst;
|
|
|
|
|
|
|
|
typedef boost::unordered::detail::allocator_traits<
|
|
|
|
typename boost::unordered::detail::rebind_wrap<A,
|
|
|
|
boost::unordered::detail::grouped_ptr_node<nonconst> >::type>
|
|
|
|
tentative_node_traits;
|
|
|
|
|
|
|
|
typedef boost::unordered::detail::allocator_traits<
|
|
|
|
typename boost::unordered::detail::rebind_wrap<A,
|
|
|
|
boost::unordered::detail::ptr_bucket>::type>
|
|
|
|
tentative_bucket_traits;
|
|
|
|
|
|
|
|
typedef pick_grouped_node2<A, nonconst,
|
|
|
|
typename tentative_node_traits::pointer,
|
|
|
|
typename tentative_bucket_traits::pointer>
|
|
|
|
pick;
|
|
|
|
|
|
|
|
typedef typename pick::node node;
|
|
|
|
typedef typename pick::bucket bucket;
|
|
|
|
typedef typename pick::link_pointer link_pointer;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef boost::unordered::detail::grouped_node_algo<node> node_algo;
|
2017-02-19 13:05:17 +00:00
|
|
|
};
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <typename Types>
|
2017-04-15 17:35:08 +01:00
|
|
|
struct table_equiv : boost::unordered::detail::table<Types>
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
typedef boost::unordered::detail::table<Types> table;
|
|
|
|
typedef typename table::value_type value_type;
|
|
|
|
typedef typename table::bucket bucket;
|
|
|
|
typedef typename table::policy policy;
|
|
|
|
typedef typename table::node_pointer node_pointer;
|
|
|
|
typedef typename table::node_allocator node_allocator;
|
|
|
|
typedef typename table::node_allocator_traits node_allocator_traits;
|
|
|
|
typedef typename table::bucket_pointer bucket_pointer;
|
|
|
|
typedef typename table::link_pointer link_pointer;
|
|
|
|
typedef typename table::hasher hasher;
|
|
|
|
typedef typename table::key_equal key_equal;
|
2017-02-23 20:14:27 +00:00
|
|
|
typedef typename table::const_key_type const_key_type;
|
2017-02-19 13:05:17 +00:00
|
|
|
typedef typename table::node_constructor node_constructor;
|
|
|
|
typedef typename table::node_tmp node_tmp;
|
|
|
|
typedef typename table::extractor extractor;
|
|
|
|
typedef typename table::iterator iterator;
|
|
|
|
typedef typename table::c_iterator c_iterator;
|
2017-02-27 03:59:02 +00:00
|
|
|
typedef typename table::node_algo node_algo;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
// Constructors
|
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_equiv(std::size_t n, hasher const& hf, key_equal const& eq,
|
2017-02-19 13:05:17 +00:00
|
|
|
node_allocator const& a)
|
|
|
|
: table(n, hf, eq, a)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_equiv(table_equiv const& x)
|
2017-02-19 13:05:17 +00:00
|
|
|
: table(x, node_allocator_traits::select_on_container_copy_construction(
|
|
|
|
x.node_alloc()))
|
|
|
|
{
|
|
|
|
this->init(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_equiv(table_equiv const& x, node_allocator const& a) : table(x, a)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
this->init(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_equiv(table_equiv& x, boost::unordered::detail::move_tag m)
|
2017-02-19 13:05:17 +00:00
|
|
|
: table(x, m)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
table_equiv(table_equiv& x, node_allocator const& a,
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::unordered::detail::move_tag m)
|
|
|
|
: table(x, a, m)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
2017-02-19 13:05:17 +00:00
|
|
|
this->move_init(x);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Accessors
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
std::size_t count(const_key_type& k) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
node_pointer n = this->find_node(k);
|
2017-02-27 03:59:02 +00:00
|
|
|
return n ? node_algo::count(n, this) : 0;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
std::pair<iterator, iterator> equal_range(const_key_type& k) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
node_pointer n = this->find_node(k);
|
2017-02-27 03:59:02 +00:00
|
|
|
return std::make_pair(
|
|
|
|
iterator(n), iterator(n ? node_algo::next_group(n, this) : n));
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Equality
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
bool equals(table_equiv const& other) const
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
if (this->size_ != other.size_)
|
|
|
|
return false;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
for (node_pointer n1 = this->begin(); n1;) {
|
2017-04-15 17:35:08 +01:00
|
|
|
node_pointer n2 = other.find_node(other.get_key(n1));
|
2017-02-19 13:05:17 +00:00
|
|
|
if (!n2)
|
|
|
|
return false;
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer end1 = node_algo::next_group(n1, this);
|
|
|
|
node_pointer end2 = node_algo::next_group(n2, this);
|
2017-02-19 13:05:17 +00:00
|
|
|
if (!group_equals(n1, end1, n2, end2))
|
|
|
|
return false;
|
|
|
|
n1 = end1;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static bool group_equals(
|
|
|
|
node_pointer n1, node_pointer end1, node_pointer n2, node_pointer end2)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
if (n1->value() != n2->value())
|
|
|
|
break;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
n1 = node_algo::next_node(n1);
|
|
|
|
n2 = node_algo::next_node(n2);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (n1 == end1)
|
|
|
|
return n2 == end2;
|
|
|
|
if (n2 == end2)
|
|
|
|
return false;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
for (node_pointer n1a = n1, n2a = n2;;) {
|
2017-02-27 03:59:02 +00:00
|
|
|
n1a = node_algo::next_node(n1a);
|
|
|
|
n2a = node_algo::next_node(n2a);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (n1a == end1) {
|
|
|
|
if (n2a == end2)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
return false;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (n2a == end2)
|
|
|
|
return false;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer start = n1;
|
2017-02-27 03:59:02 +00:00
|
|
|
for (; n1 != end1; n1 = node_algo::next_node(n1)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
value_type const& v = n1->value();
|
|
|
|
if (!find(start, n1, v)) {
|
|
|
|
std::size_t matches = count_equal(n2, end2, v);
|
|
|
|
if (!matches)
|
|
|
|
return false;
|
2017-02-27 03:59:02 +00:00
|
|
|
if (matches !=
|
|
|
|
1 + count_equal(node_algo::next_node(n1), end1, v))
|
2017-02-19 13:05:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static bool find(node_pointer n, node_pointer end, value_type const& v)
|
|
|
|
{
|
2017-02-27 03:59:02 +00:00
|
|
|
for (; n != end; n = node_algo::next_node(n))
|
2017-02-19 13:05:17 +00:00
|
|
|
if (n->value() == v)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
static std::size_t count_equal(
|
|
|
|
node_pointer n, node_pointer end, value_type const& v)
|
|
|
|
{
|
|
|
|
std::size_t count = 0;
|
2017-02-27 03:59:02 +00:00
|
|
|
for (; n != end; n = node_algo::next_node(n))
|
2017-02-19 13:05:17 +00:00
|
|
|
if (n->value() == v)
|
|
|
|
++count;
|
|
|
|
return count;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// Emplace/Insert
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
inline node_pointer add_node(
|
|
|
|
node_pointer n, std::size_t key_hash, node_pointer pos)
|
|
|
|
{
|
|
|
|
n->hash_ = key_hash;
|
|
|
|
if (pos) {
|
2017-02-27 03:59:02 +00:00
|
|
|
node_algo::add_to_node_group(n, pos);
|
2017-02-19 13:05:17 +00:00
|
|
|
if (n->next_) {
|
|
|
|
std::size_t next_bucket =
|
2017-02-27 03:59:02 +00:00
|
|
|
this->hash_to_bucket(node_algo::next_node(n)->hash_);
|
2017-02-19 13:05:17 +00:00
|
|
|
if (next_bucket != this->hash_to_bucket(key_hash)) {
|
|
|
|
this->get_bucket(next_bucket)->next_ = n;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
} else {
|
|
|
|
bucket_pointer b = this->get_bucket(this->hash_to_bucket(key_hash));
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (!b->next_) {
|
|
|
|
link_pointer start_node = this->get_previous_start();
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
if (start_node->next_) {
|
|
|
|
this->get_bucket(
|
2017-02-27 03:59:02 +00:00
|
|
|
this->hash_to_bucket(
|
|
|
|
node_algo::next_node(start_node)->hash_))
|
2017-02-19 13:05:17 +00:00
|
|
|
->next_ = n;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
b->next_ = start_node;
|
|
|
|
n->next_ = start_node->next_;
|
|
|
|
start_node->next_ = n;
|
|
|
|
} else {
|
|
|
|
n->next_ = b->next_->next_;
|
|
|
|
b->next_->next_ = n;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
++this->size_;
|
|
|
|
return n;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
inline node_pointer add_using_hint(node_pointer n, node_pointer hint)
|
|
|
|
{
|
|
|
|
n->hash_ = hint->hash_;
|
2017-02-27 03:59:02 +00:00
|
|
|
node_algo::add_to_node_group(n, hint);
|
2017-02-19 13:05:17 +00:00
|
|
|
if (n->next_ != hint && n->next_) {
|
2017-02-27 03:59:02 +00:00
|
|
|
std::size_t next_bucket =
|
|
|
|
this->hash_to_bucket(node_algo::next_node(n)->hash_);
|
2017-02-19 13:05:17 +00:00
|
|
|
if (next_bucket != this->hash_to_bucket(n->hash_)) {
|
|
|
|
this->get_bucket(next_bucket)->next_ = n;
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
++this->size_;
|
|
|
|
return n;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
2017-02-19 13:05:17 +00:00
|
|
|
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
iterator emplace(boost::unordered::detail::emplace_args1<
|
|
|
|
boost::unordered::detail::please_ignore_this_overload> const&)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return iterator();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator emplace_hint(
|
|
|
|
c_iterator,
|
|
|
|
boost::unordered::detail::emplace_args1<
|
|
|
|
boost::unordered::detail::please_ignore_this_overload> const&)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return iterator();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
iterator emplace(
|
|
|
|
boost::unordered::detail::please_ignore_this_overload const&)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return iterator();
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator emplace_hint(c_iterator,
|
|
|
|
boost::unordered::detail::please_ignore_this_overload const&)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
return iterator();
|
|
|
|
}
|
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
iterator emplace(BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
|
|
|
return iterator(emplace_impl(
|
|
|
|
boost::unordered::detail::func::construct_node_from_args(
|
|
|
|
this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD)));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
iterator emplace_hint(c_iterator hint, BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
{
|
|
|
|
return iterator(emplace_hint_impl(
|
|
|
|
hint, boost::unordered::detail::func::construct_node_from_args(
|
|
|
|
this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD)));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator emplace_impl(node_pointer n)
|
|
|
|
{
|
|
|
|
node_tmp a(n, this->node_alloc());
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(a.node_);
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer position = this->find_node(key_hash, k);
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
return iterator(this->add_node(a.release(), key_hash, position));
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator emplace_hint_impl(c_iterator hint, node_pointer n)
|
|
|
|
{
|
|
|
|
node_tmp a(n, this->node_alloc());
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(a.node_);
|
|
|
|
if (hint.node_ && this->key_eq()(k, this->get_key(hint.node_))) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
return iterator(this->add_using_hint(a.release(), hint.node_));
|
|
|
|
} else {
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer position = this->find_node(key_hash, k);
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
return iterator(this->add_node(a.release(), key_hash, position));
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void emplace_impl_no_rehash(node_pointer n)
|
|
|
|
{
|
|
|
|
node_tmp a(n, this->node_alloc());
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(a.node_);
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer position = this->find_node(key_hash, k);
|
|
|
|
this->add_node(a.release(), key_hash, position);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
template <typename NodeType> iterator move_insert_node_type(NodeType& np)
|
|
|
|
{
|
|
|
|
iterator result;
|
|
|
|
|
|
|
|
if (np) {
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(np.ptr_);
|
2017-02-27 03:59:02 +00:00
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
result = iterator(this->add_node(np.ptr_, key_hash, pos));
|
|
|
|
np.ptr_ = node_pointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename NodeType>
|
|
|
|
iterator move_insert_node_type_with_hint(c_iterator hint, NodeType& np)
|
|
|
|
{
|
|
|
|
iterator result;
|
|
|
|
|
|
|
|
if (np) {
|
2017-04-15 17:35:08 +01:00
|
|
|
const_key_type& k = this->get_key(np.ptr_);
|
2017-02-27 03:59:02 +00:00
|
|
|
|
2017-04-15 17:35:08 +01:00
|
|
|
if (hint.node_ && this->key_eq()(k, this->get_key(hint.node_))) {
|
2017-02-27 03:59:02 +00:00
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
result = iterator(this->add_using_hint(np.ptr_, hint.node_));
|
|
|
|
} else {
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
node_pointer pos = this->find_node(key_hash, k);
|
|
|
|
this->reserve_for_insert(this->size_ + 1);
|
|
|
|
result = iterator(this->add_node(np.ptr_, key_hash, pos));
|
|
|
|
}
|
|
|
|
np.ptr_ = node_pointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Insert range methods
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// if hash function throws, or inserting > 1 element, basic exception
|
|
|
|
// safety. Strong otherwise
|
|
|
|
template <class I>
|
|
|
|
void insert_range(I i, I j,
|
|
|
|
typename boost::unordered::detail::enable_if_forward<I, void*>::type =
|
|
|
|
0)
|
|
|
|
{
|
|
|
|
if (i == j)
|
|
|
|
return;
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
std::size_t distance = static_cast<std::size_t>(std::distance(i, j));
|
|
|
|
if (distance == 1) {
|
|
|
|
emplace_impl(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), *i));
|
|
|
|
} else {
|
|
|
|
// Only require basic exception safety here
|
|
|
|
this->reserve_for_insert(this->size_ + distance);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
for (; i != j; ++i) {
|
2017-02-19 13:05:17 +00:00
|
|
|
emplace_impl_no_rehash(
|
2017-02-19 13:05:17 +00:00
|
|
|
boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), *i));
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class I>
|
|
|
|
void insert_range(I i, I j,
|
|
|
|
typename boost::unordered::detail::disable_if_forward<I, void*>::type =
|
|
|
|
0)
|
|
|
|
{
|
|
|
|
for (; i != j; ++i) {
|
|
|
|
emplace_impl(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), *i));
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Extract
|
|
|
|
|
|
|
|
inline node_pointer extract_by_iterator(c_iterator n)
|
|
|
|
{
|
|
|
|
node_pointer i = n.node_;
|
|
|
|
BOOST_ASSERT(i);
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer j(node_algo::next_node(i));
|
2017-02-27 03:59:02 +00:00
|
|
|
std::size_t bucket_index = this->hash_to_bucket(i->hash_);
|
|
|
|
// Split the groups containing 'i' and 'j'.
|
|
|
|
// And get the pointer to the node before i while
|
|
|
|
// we're at it.
|
2017-02-27 03:59:02 +00:00
|
|
|
link_pointer prev = node_algo::split_groups(i, j);
|
2017-02-27 03:59:02 +00:00
|
|
|
|
|
|
|
// If we don't have a 'prev' it means that i is at the
|
|
|
|
// beginning of a block, so search through the blocks in the
|
|
|
|
// same bucket.
|
|
|
|
if (!prev) {
|
|
|
|
prev = this->get_previous_start(bucket_index);
|
|
|
|
while (prev->next_ != i) {
|
2017-02-27 03:59:02 +00:00
|
|
|
prev = node_algo::next_for_erase(prev);
|
2017-02-27 03:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prev->next_ = i->next_;
|
|
|
|
--this->size_;
|
|
|
|
this->fix_bucket(bucket_index, prev);
|
|
|
|
i->next_ = link_pointer();
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Erase
|
|
|
|
//
|
|
|
|
// no throw
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-23 20:14:27 +00:00
|
|
|
std::size_t erase_key(const_key_type& k)
|
2017-02-19 13:05:17 +00:00
|
|
|
{
|
|
|
|
if (!this->size_)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::size_t key_hash = this->hash(k);
|
|
|
|
std::size_t bucket_index = this->hash_to_bucket(key_hash);
|
2017-02-27 03:59:02 +00:00
|
|
|
link_pointer prev = this->find_previous_node(k, key_hash, bucket_index);
|
2017-02-19 13:05:17 +00:00
|
|
|
if (!prev)
|
|
|
|
return 0;
|
|
|
|
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer first_node = node_algo::next_node(prev);
|
|
|
|
link_pointer end = node_algo::next_group(first_node, this);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
std::size_t deleted_count = this->delete_nodes(prev, end);
|
|
|
|
this->fix_bucket(bucket_index, prev);
|
|
|
|
return deleted_count;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator erase(c_iterator r)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(r.node_);
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer next = node_algo::next_node(r.node_);
|
2017-02-19 13:05:17 +00:00
|
|
|
erase_nodes(r.node_, next);
|
|
|
|
return iterator(next);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
iterator erase_range(c_iterator r1, c_iterator r2)
|
|
|
|
{
|
|
|
|
if (r1 == r2)
|
2017-02-19 13:05:17 +00:00
|
|
|
return iterator(r2.node_);
|
2017-02-19 13:05:17 +00:00
|
|
|
erase_nodes(r1.node_, r2.node_);
|
|
|
|
return iterator(r2.node_);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
link_pointer erase_nodes(node_pointer i, node_pointer j)
|
|
|
|
{
|
|
|
|
std::size_t bucket_index = this->hash_to_bucket(i->hash_);
|
|
|
|
|
|
|
|
// Split the groups containing 'i' and 'j'.
|
|
|
|
// And get the pointer to the node before i while
|
|
|
|
// we're at it.
|
2017-02-27 03:59:02 +00:00
|
|
|
link_pointer prev = node_algo::split_groups(i, j);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
// If we don't have a 'prev' it means that i is at the
|
|
|
|
// beginning of a block, so search through the blocks in the
|
|
|
|
// same bucket.
|
|
|
|
if (!prev) {
|
|
|
|
prev = this->get_previous_start(bucket_index);
|
2017-02-27 03:59:02 +00:00
|
|
|
while (prev->next_ != i) {
|
|
|
|
prev = node_algo::next_for_erase(prev);
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the nodes.
|
2017-02-27 03:59:02 +00:00
|
|
|
// Is it inefficient to call fix_bucket for every node?
|
2017-02-19 13:05:17 +00:00
|
|
|
do {
|
2017-02-27 03:59:02 +00:00
|
|
|
this->delete_node(prev);
|
2017-02-19 13:05:17 +00:00
|
|
|
bucket_index = this->fix_bucket(bucket_index, prev);
|
|
|
|
} while (prev->next_ != j);
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// fill_buckets
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void copy_buckets(table const& src)
|
|
|
|
{
|
|
|
|
this->create_buckets(this->bucket_count_);
|
|
|
|
|
|
|
|
for (node_pointer n = src.begin(); n;) {
|
|
|
|
std::size_t key_hash = n->hash_;
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer group_end(node_algo::next_group(n, this));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer pos =
|
|
|
|
this->add_node(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), n->value()),
|
|
|
|
key_hash, node_pointer());
|
2017-02-27 03:59:02 +00:00
|
|
|
for (n = node_algo::next_node(n); n != group_end;
|
|
|
|
n = node_algo::next_node(n)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), n->value()),
|
|
|
|
key_hash, pos);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void move_buckets(table const& src)
|
|
|
|
{
|
|
|
|
this->create_buckets(this->bucket_count_);
|
|
|
|
|
|
|
|
for (node_pointer n = src.begin(); n;) {
|
|
|
|
std::size_t key_hash = n->hash_;
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer group_end(node_algo::next_group(n, this));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer pos =
|
|
|
|
this->add_node(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), boost::move(n->value())),
|
|
|
|
key_hash, node_pointer());
|
2017-02-27 03:59:02 +00:00
|
|
|
for (n = node_algo::next_node(n); n != group_end;
|
|
|
|
n = node_algo::next_node(n)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(boost::unordered::detail::func::construct_node(
|
|
|
|
this->node_alloc(), boost::move(n->value())),
|
|
|
|
key_hash, pos);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void assign_buckets(table const& src)
|
|
|
|
{
|
|
|
|
node_holder<node_allocator> holder(*this);
|
|
|
|
for (node_pointer n = src.begin(); n;) {
|
|
|
|
std::size_t key_hash = n->hash_;
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer group_end(node_algo::next_group(n, this));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer pos = this->add_node(
|
|
|
|
holder.copy_of(n->value()), key_hash, node_pointer());
|
2017-02-27 03:59:02 +00:00
|
|
|
for (n = node_algo::next_node(n); n != group_end;
|
|
|
|
n = node_algo::next_node(n)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(holder.copy_of(n->value()), key_hash, pos);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
void move_assign_buckets(table& src)
|
|
|
|
{
|
|
|
|
node_holder<node_allocator> holder(*this);
|
|
|
|
for (node_pointer n = src.begin(); n;) {
|
|
|
|
std::size_t key_hash = n->hash_;
|
2017-02-27 03:59:02 +00:00
|
|
|
node_pointer group_end(node_algo::next_group(n, this));
|
2017-02-19 13:05:17 +00:00
|
|
|
node_pointer pos = this->add_node(
|
|
|
|
holder.move_copy_of(n->value()), key_hash, node_pointer());
|
2017-02-27 03:59:02 +00:00
|
|
|
for (n = node_algo::next_node(n); n != group_end;
|
|
|
|
n = node_algo::next_node(n)) {
|
2017-02-19 13:05:17 +00:00
|
|
|
this->add_node(holder.move_copy_of(n->value()), key_hash, pos);
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 13:05:17 +00:00
|
|
|
|
|
|
|
#endif
|