Integrate and adapt "devector's", from Thaler Benedek's implementation.

This commit is contained in:
Ion Gaztañaga
2020-08-10 00:16:58 +02:00
parent 844b779a7d
commit ebcd0222b4
20 changed files with 8665 additions and 24 deletions

View File

@@ -26,6 +26,7 @@
//! - boost::container::static_vector
//! - boost::container::small_vector_base
//! - boost::container::small_vector
//! - boost::container::devector
//! - boost::container::slist
//! - boost::container::list
//! - boost::container::set
@@ -122,6 +123,11 @@ template < class T
, class Options = void >
class small_vector;
template <class T
,class Allocator = void
,class Options = void>
class devector;
template <class T
,class Allocator = void
,class Options = void>

View File

@@ -0,0 +1,389 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2014. 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)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_CONTAINER_FWD_HPP
#define BOOST_CONTAINER_CONTAINER_FWD_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
//! \file
//! This header file forward declares the following containers:
//! - boost::container::vector
//! - boost::container::stable_vector
//! - boost::container::static_vector
//! - boost::container::small_vector_base
//! - boost::container::small_vector
//! - boost::container::slist
//! - boost::container::list
//! - boost::container::set
//! - boost::container::multiset
//! - boost::container::map
//! - boost::container::multimap
//! - boost::container::flat_set
//! - boost::container::flat_multiset
//! - boost::container::flat_map
//! - boost::container::flat_multimap
//! - boost::container::basic_string
//! - boost::container::string
//! - boost::container::wstring
//!
//! Forward declares the following allocators:
//! - boost::container::allocator
//! - boost::container::node_allocator
//! - boost::container::adaptive_pool
//!
//! Forward declares the following polymorphic resource classes:
//! - boost::container::pmr::memory_resource
//! - boost::container::pmr::polymorphic_allocator
//! - boost::container::pmr::monotonic_buffer_resource
//! - boost::container::pmr::pool_options
//! - boost::container::pmr::unsynchronized_pool_resource
//! - boost::container::pmr::synchronized_pool_resource
//!
//! And finally it defines the following types
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
//Std forward declarations
#ifndef BOOST_CONTAINER_DETAIL_STD_FWD_HPP
#include <boost/container/detail/std_fwd.hpp>
#endif
namespace boost{
namespace intrusive{
namespace detail{
//Create namespace to avoid compilation errors
}}}
namespace boost{ namespace container{ namespace dtl{
namespace bi = boost::intrusive;
namespace bid = boost::intrusive::detail;
}}}
namespace boost{ namespace container{ namespace pmr{
namespace bi = boost::intrusive;
namespace bid = boost::intrusive::detail;
}}}
#include <cstddef>
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
//////////////////////////////////////////////////////////////////////////////
// Containers
//////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace container {
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
template<class T1, class T2>
struct pair;
template<class T>
class new_allocator;
template <class T
,class Allocator = void
,class Options = void>
class vector;
template <class T
,class Allocator = void >
class stable_vector;
template < class T
, std::size_t Capacity
, class Options = void>
class static_vector;
template < class T
, class Allocator = void
, class Options = void >
class small_vector_base;
template < class T
, std::size_t N
, class Allocator = void
, class Options = void >
class small_vector;
template <class T
,class Allocator = void
,class Options = void>
class devector;
template <class T
,class Allocator = void
,class Options = void>
class deque;
template <class T
,class Allocator = void >
class list;
template <class T
,class Allocator = void >
class slist;
template <class Key
,class Compare = std::less<Key>
,class Allocator = void
,class Options = void>
class set;
template <class Key
,class Compare = std::less<Key>
,class Allocator = void
,class Options = void >
class multiset;
template <class Key
,class T
,class Compare = std::less<Key>
,class Allocator = void
,class Options = void >
class map;
template <class Key
,class T
,class Compare = std::less<Key>
,class Allocator = void
,class Options = void >
class multimap;
template <class Key
,class Compare = std::less<Key>
,class Allocator = void >
class flat_set;
template <class Key
,class Compare = std::less<Key>
,class Allocator = void >
class flat_multiset;
template <class Key
,class T
,class Compare = std::less<Key>
,class Allocator = void >
class flat_map;
template <class Key
,class T
,class Compare = std::less<Key>
,class Allocator = void >
class flat_multimap;
#ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
//! Alias templates for small_flat_[multi]{set|map} using small_vector as container
template < class Key
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
using small_flat_set = flat_set<Key, Compare, small_vector<Key, N, SmallVectorAllocator, SmallVectorOptions>>;
template < class Key
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
using small_flat_multiset = flat_multiset<Key, Compare, small_vector<Key, N, SmallVectorAllocator, SmallVectorOptions>>;
template < class Key
, class T
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
using small_flat_map = flat_map<Key, T, Compare, small_vector<std::pair<Key, T>, N, SmallVectorAllocator, SmallVectorOptions>>;
template < class Key
, class T
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
using small_flat_multimap = flat_multimap<Key, T, Compare, small_vector<std::pair<Key, T>, N, SmallVectorAllocator, SmallVectorOptions>>;
#endif // #ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
//! A portable metafunction to obtain a small_flat_set
template < class Key
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
struct small_flat_set_of
{
typedef flat_set<Key, Compare, small_vector<Key, N, SmallVectorAllocator, SmallVectorOptions> > type;
};
//! A portable metafunction to obtain a small_flat_multiset
template < class Key
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
struct small_flat_multiset_of
{
typedef flat_multiset<Key, Compare, small_vector<Key, N, SmallVectorAllocator, SmallVectorOptions> > type;
};
//! A portable metafunction to obtain a small_flat_map
template < class Key
, class T
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
struct small_flat_map_of
{
typedef flat_map<Key, T, Compare, small_vector<std::pair<Key, T>, N, SmallVectorAllocator, SmallVectorOptions> > type;
};
//! A portable metafunction to obtain a small_flat_multimap
template < class Key
, class T
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
struct small_flat_multimap_of
{
typedef flat_multimap<Key, T, Compare, small_vector<std::pair<Key, T>, N, SmallVectorAllocator, SmallVectorOptions> > type;
};
template <class CharT
,class Traits = std::char_traits<CharT>
,class Allocator = void >
class basic_string;
typedef basic_string <char> string;
typedef basic_string<wchar_t> wstring;
static const std::size_t ADP_nodes_per_block = 256u;
static const std::size_t ADP_max_free_blocks = 2u;
static const std::size_t ADP_overhead_percent = 1u;
static const std::size_t ADP_only_alignment = 0u;
template < class T
, std::size_t NodesPerBlock = ADP_nodes_per_block
, std::size_t MaxFreeBlocks = ADP_max_free_blocks
, std::size_t OverheadPercent = ADP_overhead_percent
, unsigned Version = 2
>
class adaptive_pool;
template < class T
, unsigned Version = 2
, unsigned int AllocationDisableMask = 0>
class allocator;
static const std::size_t NodeAlloc_nodes_per_block = 256u;
template
< class T
, std::size_t NodesPerBlock = NodeAlloc_nodes_per_block
, std::size_t Version = 2>
class node_allocator;
namespace pmr {
class memory_resource;
template<class T>
class polymorphic_allocator;
class monotonic_buffer_resource;
struct pool_options;
template <class Allocator>
class resource_adaptor_imp;
class unsynchronized_pool_resource;
class synchronized_pool_resource;
} //namespace pmr {
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
//! Type used to tag that the input range is
//! guaranteed to be ordered
struct ordered_range_t
{};
//! Value used to tag that the input range is
//! guaranteed to be ordered
static const ordered_range_t ordered_range = ordered_range_t();
//! Type used to tag that the input range is
//! guaranteed to be ordered and unique
struct ordered_unique_range_t
: public ordered_range_t
{};
//! Value used to tag that the input range is
//! guaranteed to be ordered and unique
static const ordered_unique_range_t ordered_unique_range = ordered_unique_range_t();
//! Type used to tag that the inserted values
//! should be default initialized
struct default_init_t
{};
//! Value used to tag that the inserted values
//! should be default initialized
static const default_init_t default_init = default_init_t();
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
//! Type used to tag that the inserted values
//! should be value initialized
struct value_init_t
{};
//! Value used to tag that the inserted values
//! should be value initialized
static const value_init_t value_init = value_init_t();
namespace container_detail_really_deep_namespace {
//Otherwise, gcc issues a warning of previously defined
//anonymous_instance and unique_instance
struct dummy
{
dummy()
{
(void)ordered_range;
(void)ordered_unique_range;
(void)default_init;
}
};
} //detail_really_deep_namespace {
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
}} //namespace boost { namespace container {
#endif //#ifndef BOOST_CONTAINER_CONTAINER_FWD_HPP

View File

@@ -130,7 +130,8 @@ void flat_tree_container_inplace_merge //is_contiguous_container == true
value_type *const braw = boost::movelib::iterator_to_raw_pointer(dest.begin());
value_type *const iraw = boost::movelib::iterator_to_raw_pointer(it);
value_type *const eraw = boost::movelib::iterator_to_raw_pointer(dest.end());
boost::movelib::adaptive_merge(braw, iraw, eraw, comp, eraw, dest.capacity()- dest.size());
boost::movelib::adaptive_merge
(braw, iraw, eraw, comp, eraw, back_free_capacity<SequenceContainer>::get(dest));
}
template<class SequenceContainer, class Compare>
@@ -152,7 +153,8 @@ void flat_tree_container_inplace_sort_ending //is_contiguous_container == true
typedef typename SequenceContainer::value_type value_type;
value_type *const iraw = boost::movelib::iterator_to_raw_pointer(it);
value_type *const eraw = boost::movelib::iterator_to_raw_pointer(dest.end());
boost::movelib::adaptive_sort(iraw, eraw, comp, eraw, dest.capacity()- dest.size());
boost::movelib::adaptive_sort
(iraw, eraw, comp, eraw, back_free_capacity<SequenceContainer>::get(dest));
}
template<class SequenceContainer, class Compare>
@@ -984,10 +986,7 @@ class flat_tree
ret.first = this->nth(data.position - this->cbegin());
}
else{
typedef typename emplace_functor_type<try_emplace_t, KeyType, Args...>::type func_t;
typedef emplace_iterator<value_type, func_t, difference_type> it_t;
func_t func(try_emplace_t(), ::boost::forward<KeyType>(key), ::boost::forward<Args>(args)...);
ret.first = this->m_data.m_seq.insert(data.position, it_t(func), it_t());
ret.first = this->m_data.m_seq.emplace(data.position, try_emplace_t(), ::boost::forward<KeyType>(key), ::boost::forward<Args>(args)...);
}
return ret;
}
@@ -1053,10 +1052,7 @@ class flat_tree
ret.first = this->nth(data.position - this->cbegin());\
}\
else{\
typedef typename emplace_functor_type<try_emplace_t, KeyType BOOST_MOVE_I##N BOOST_MOVE_TARG##N>::type func_t;\
typedef emplace_iterator<value_type, func_t, difference_type> it_t;\
func_t func(try_emplace_t(), ::boost::forward<KeyType>(key) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
ret.first = this->m_data.m_seq.insert(data.position, it_t(func), it_t());\
ret.first = this->m_data.m_seq.emplace(data.position, try_emplace_t(), ::boost::forward<KeyType>(key) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
}\
return ret;\
}\
@@ -1080,10 +1076,7 @@ class flat_tree
ret.first->second = boost::forward<M>(obj);
}
else{
typedef typename emplace_functor_type<KeyType, M>::type func_t;
typedef emplace_iterator<value_type, func_t, difference_type> it_t;
func_t func(boost::forward<KeyType>(key), boost::forward<M>(obj));
ret.first = this->m_data.m_seq.insert(data.position, it_t(func), it_t());
ret.first = this->m_data.m_seq.emplace(data.position, boost::forward<KeyType>(key), boost::forward<M>(obj));
}
return ret;
}

View File

@@ -0,0 +1,198 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Benedek Thaler 2015-2016
// (C) Copyright Ion Gaztanaga 2019-2020. 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)
//
// See http://erenon.hu/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_DETAIL_GUARDS_HPP
#define BOOST_CONTAINER_DETAIL_GUARDS_HPP
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
#include <boost/move/core.hpp> // BOOST_MOVABLE_BUT_NOT_COPYABLE
// move/detail
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/move/detail/fwd_macros.hpp>
#endif
#include <boost/container/allocator_traits.hpp>
namespace boost {
namespace container {
namespace detail {
class null_construction_guard
{
public:
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
template <typename... Args>
null_construction_guard(Args&&...) {}
#else
#define NULL_CONSTRUCTION_GUARD_CODE(N) \
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE null_construction_guard(BOOST_MOVE_UREFANON##N)\
{}\
//
BOOST_MOVE_ITERATE_0TO9(NULL_CONSTRUCTION_GUARD_CODE)
#undef NULL_CONSTRUCTION_GUARD_CODE
#endif
void release() {}
void extend() {}
};
template <typename Allocator>
class construction_guard
{
typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
BOOST_MOVABLE_BUT_NOT_COPYABLE(construction_guard)
public:
construction_guard()
: _alloc_ptr()
, _elem_count()
, _allocator()
{}
construction_guard(pointer alloc_ptr, Allocator& allocator)
:_alloc_ptr(alloc_ptr)
, _elem_count(0)
, _allocator(&allocator)
{}
construction_guard(BOOST_RV_REF(construction_guard) rhs)
:_alloc_ptr(rhs._alloc_ptr)
, _elem_count(rhs._elem_count)
, _allocator(rhs._allocator)
{
rhs._elem_count = 0;
}
~construction_guard()
{
while (_elem_count) {
--_elem_count;
boost::container::allocator_traits<Allocator>::destroy(*_allocator, _alloc_ptr++);
}
}
void release()
{
_elem_count = 0;
}
void extend()
{
++_elem_count;
}
private:
pointer _alloc_ptr;
size_type _elem_count;
Allocator* _allocator;
};
/**
* Has two ranges
*
* On success, destroys the first range (src),
* on failure, destroys the second range (dst).
*
* Can be used when copying/moving a range
*/
template <class Allocator>
class nand_construction_guard
{
typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
construction_guard<Allocator> _src;
construction_guard<Allocator> _dst;
bool _dst_released;
public:
nand_construction_guard()
: _src()
, _dst()
, _dst_released(false)
{}
nand_construction_guard( pointer src, Allocator& src_alloc
, pointer dst, Allocator& dst_alloc)
:_src(src, src_alloc),
_dst(dst, dst_alloc),
_dst_released(false)
{}
void extend()
{
_src.extend();
_dst.extend();
}
void release() // on success
{
_dst.release();
_dst_released = true;
}
~nand_construction_guard()
{
if (! _dst_released) { _src.release(); }
}
};
template <typename Allocator>
class allocation_guard
{
typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
BOOST_MOVABLE_BUT_NOT_COPYABLE(allocation_guard)
public:
allocation_guard(pointer alloc_ptr, size_type alloc_size, Allocator& allocator)
:_alloc_ptr(alloc_ptr),
_alloc_size(alloc_size),
_allocator(allocator)
{}
~allocation_guard()
{
if (_alloc_ptr)
{
boost::container::allocator_traits<Allocator>::deallocate(_allocator, _alloc_ptr, _alloc_size);
}
}
void release()
{
_alloc_ptr = 0;
}
private:
pointer _alloc_ptr;
size_type _alloc_size;
Allocator& _allocator;
};
}}} // namespace boost::container::detail
#include <boost/container/detail/config_end.hpp>
#endif // BOOST_CONTAINER_DETAIL_GUARDS_HPP

File diff suppressed because it is too large Load Diff

View File

@@ -215,6 +215,13 @@ class default_next_capacity;
typedef vector_opt<void, void> vector_null_opt;
template<class GrowthType, class StoredSizeType>
struct devector_opt
: vector_opt<GrowthType, StoredSizeType>
{};
typedef devector_opt<void, void> devector_null_opt;
#else //!defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//!This growth factor argument specifies that the container should increase it's
@@ -442,6 +449,40 @@ using static_vector_options_t = typename boost::container::static_vector_options
#endif
//! Helper metafunction to combine options into a single type to be used
//! by \c boost::container::devector.
//! Supported options are: \c boost::container::growth_factor and \c boost::container::stored_size
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) || defined(BOOST_CONTAINER_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
#endif
struct devector_options
{
/// @cond
typedef typename ::boost::intrusive::pack_options
< devector_null_opt,
#if !defined(BOOST_CONTAINER_VARIADIC_TEMPLATES)
O1, O2, O3, O4
#else
Options...
#endif
>::type packed_options;
typedef devector_opt< typename packed_options::growth_factor_type
, typename packed_options::stored_size_type> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
//! Helper alias metafunction to combine options into a single type to be used
//! by \c boost::container::devector.
//! Supported options are: \c boost::container::growth_factor and \c boost::container::stored_size
template<class ...Options>
using devector_options_t = typename boost::container::devector_options<Options...>::type;
#endif
////////////////////////////////////////////////////////////////
//

View File

@@ -0,0 +1,51 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2015-2015. 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)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_PMR_VECTOR_HPP
#define BOOST_CONTAINER_PMR_VECTOR_HPP
#if defined (_MSC_VER)
# pragma once
#endif
#include <boost/container/devector.hpp>
#include <boost/container/pmr/polymorphic_allocator.hpp>
namespace boost {
namespace container {
namespace pmr {
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
template <
typename T,
typename GrowthPolicy = growth_factor_60
>
using devector = boost::container::devector<T, GrowthPolicy, polymorphic_allocator<T> >;
#endif
//! A portable metafunction to obtain a vector
//! that uses a polymorphic allocator
template <
typename T,
typename GrowthPolicy = growth_factor_60
>
struct devector_of
{
typedef boost::container::devector
< T, GrowthPolicy, polymorphic_allocator<T> > type;
};
} //namespace pmr {
} //namespace container {
} //namespace boost {
#endif //BOOST_CONTAINER_PMR_VECTOR_HPP