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

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

No files matched your search

+7 -14
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;
}
@@ -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