Alien-boost-mini
view release on metacpan or search on metacpan
include/boost/container/detail/tree.hpp view on Meta::CPAN
};
//Trait to detect manually rebalanceable tree types
template<boost::container::tree_type_enum tree_type_value>
struct is_manually_balanceable
{ static const bool value = true; };
template<> struct is_manually_balanceable<red_black_tree>
{ static const bool value = false; };
template<> struct is_manually_balanceable<avl_tree>
{ static const bool value = false; };
//Proxy traits to implement different operations depending on the
//is_manually_balanceable<>::value
template< boost::container::tree_type_enum tree_type_value
, bool IsManuallyRebalanceable = is_manually_balanceable<tree_type_value>::value>
struct intrusive_tree_proxy
{
template<class Icont>
BOOST_CONTAINER_FORCEINLINE static void rebalance(Icont &) {}
};
template<boost::container::tree_type_enum tree_type_value>
struct intrusive_tree_proxy<tree_type_value, true>
{
template<class Icont>
BOOST_CONTAINER_FORCEINLINE static void rebalance(Icont &c)
{ c.rebalance(); }
};
} //namespace dtl {
namespace dtl {
//This functor will be used with Intrusive clone functions to obtain
//already allocated nodes from a intrusive container instead of
//allocating new ones. When the intrusive container runs out of nodes
//the node holder is used instead.
template<class AllocHolder, bool DoMove>
class RecyclingCloner
{
typedef typename AllocHolder::intrusive_container intrusive_container;
typedef typename AllocHolder::Node node_t;
typedef typename AllocHolder::NodePtr node_ptr_type;
public:
RecyclingCloner(AllocHolder &holder, intrusive_container &itree)
: m_holder(holder), m_icont(itree)
{}
BOOST_CONTAINER_FORCEINLINE static void do_assign(node_ptr_type &p, const node_t &other, bool_<true>)
{ p->do_move_assign(const_cast<node_t &>(other).m_data); }
BOOST_CONTAINER_FORCEINLINE static void do_assign(node_ptr_type &p, const node_t &other, bool_<false>)
{ p->do_assign(other.m_data); }
node_ptr_type operator()(const node_t &other) const
{
if(node_ptr_type p = m_icont.unlink_leftmost_without_rebalance()){
//First recycle a node (this can't throw)
BOOST_TRY{
//This can throw
this->do_assign(p, other, bool_<DoMove>());
return p;
}
BOOST_CATCH(...){
//If there is an exception destroy the whole source
m_holder.destroy_node(p);
while((p = m_icont.unlink_leftmost_without_rebalance())){
m_holder.destroy_node(p);
}
BOOST_RETHROW
}
BOOST_CATCH_END
}
else{
return m_holder.create_node(other.m_data);
}
}
AllocHolder &m_holder;
intrusive_container &m_icont;
};
template<class KeyCompare, class KeyOfValue>
struct key_node_compare
: public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
{
BOOST_CONTAINER_FORCEINLINE explicit key_node_compare(const KeyCompare &comp)
: base_t(comp)
{}
typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
typedef KeyCompare key_compare;
typedef KeyOfValue key_of_value;
typedef typename KeyOfValue::type key_type;
template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
BOOST_CONTAINER_FORCEINLINE static const key_type &
key_from(const tree_node<T, VoidPointer, tree_type_value, OptimizeSize> &n)
{
return key_of_value()(n.get_data());
}
template <class T>
BOOST_CONTAINER_FORCEINLINE static const T &
key_from(const T &t)
{
return t;
}
BOOST_CONTAINER_FORCEINLINE const key_compare &key_comp() const
{ return static_cast<const key_compare &>(*this); }
BOOST_CONTAINER_FORCEINLINE key_compare &key_comp()
{ return static_cast<key_compare &>(*this); }
BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const
{ return this->key_comp()(key1, key2); }
include/boost/container/detail/tree.hpp view on Meta::CPAN
void tree_construct_non_unique(InputIterator first, InputIterator last
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
, typename dtl::disable_if_or
< void
, dtl::is_same<alloc_version, version_1>
, dtl::is_input_iterator<InputIterator>
>::type * = 0
#endif
)
{
//Optimized allocation and construction
this->allocate_many_and_construct
( first, boost::container::iterator_distance(first, last)
, insert_equal_end_hint_functor<Node, Icont>(this->icont()));
}
template <class InputIterator>
void tree_construct( ordered_range_t, InputIterator first, InputIterator last
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
, typename dtl::disable_if_or
< void
, dtl::is_same<alloc_version, version_1>
, dtl::is_input_iterator<InputIterator>
>::type * = 0
#endif
)
{
//Optimized allocation and construction
this->allocate_many_and_construct
( first, boost::container::iterator_distance(first, last)
, dtl::push_back_functor<Node, Icont>(this->icont()));
//AllocHolder clears in case of exception
}
template <class InputIterator>
void tree_construct( ordered_range_t, InputIterator first, InputIterator last
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
, typename dtl::enable_if_or
< void
, dtl::is_same<alloc_version, version_1>
, dtl::is_input_iterator<InputIterator>
>::type * = 0
#endif
)
{
for ( ; first != last; ++first){
this->push_back_impl(*first);
}
}
public:
BOOST_CONTAINER_FORCEINLINE tree(const tree& x)
: AllocHolder(x, x.value_comp())
{
this->icont().clone_from
(x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc()));
}
BOOST_CONTAINER_FORCEINLINE tree(BOOST_RV_REF(tree) x)
BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
: AllocHolder(BOOST_MOVE_BASE(AllocHolder, x), x.value_comp())
{}
BOOST_CONTAINER_FORCEINLINE tree(const tree& x, const allocator_type &a)
: AllocHolder(x.value_comp(), a)
{
this->icont().clone_from
(x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc()));
//AllocHolder clears in case of exception
}
tree(BOOST_RV_REF(tree) x, const allocator_type &a)
: AllocHolder(x.value_comp(), a)
{
if(this->node_alloc() == x.node_alloc()){
this->icont().swap(x.icont());
}
else{
this->icont().clone_from
(boost::move(x.icont()), typename AllocHolder::move_cloner(*this), Destroyer(this->node_alloc()));
}
//AllocHolder clears in case of exception
}
BOOST_CONTAINER_FORCEINLINE ~tree()
{} //AllocHolder clears the tree
tree& operator=(BOOST_COPY_ASSIGN_REF(tree) x)
{
if (&x != this){
NodeAlloc &this_alloc = this->get_stored_allocator();
const NodeAlloc &x_alloc = x.get_stored_allocator();
dtl::bool_<allocator_traits<NodeAlloc>::
propagate_on_container_copy_assignment::value> flag;
if(flag && this_alloc != x_alloc){
this->clear();
}
this->AllocHolder::copy_assign_alloc(x);
//Transfer all the nodes to a temporary tree
//If anything goes wrong, all the nodes will be destroyed
//automatically
Icont other_tree(::boost::move(this->icont()));
//Now recreate the source tree reusing nodes stored by other_tree
this->icont().clone_from
(x.icont()
, RecyclingCloner<AllocHolder, false>(*this, other_tree)
, Destroyer(this->node_alloc()));
//If there are remaining nodes, destroy them
NodePtr p;
while((p = other_tree.unlink_leftmost_without_rebalance())){
AllocHolder::destroy_node(p);
}
}
return *this;
}
tree& operator=(BOOST_RV_REF(tree) x)
BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
allocator_traits_type::is_always_equal::value) &&
boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
{
BOOST_ASSERT(this != &x);
NodeAlloc &this_alloc = this->node_alloc();
NodeAlloc &x_alloc = x.node_alloc();
const bool propagate_alloc = allocator_traits<NodeAlloc>::
propagate_on_container_move_assignment::value;
const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
//Resources can be transferred if both allocators are
//going to be equal after this function (either propagated or already equal)
if(propagate_alloc || allocators_equal){
//Destroy
this->clear();
//Move allocator if needed
this->AllocHolder::move_assign_alloc(x);
//Obtain resources
this->icont() = boost::move(x.icont());
}
//Else do a one by one move
else{
//Transfer all the nodes to a temporary tree
//If anything goes wrong, all the nodes will be destroyed
//automatically
Icont other_tree(::boost::move(this->icont()));
//Now recreate the source tree reusing nodes stored by other_tree
this->icont().clone_from
(::boost::move(x.icont())
, RecyclingCloner<AllocHolder, true>(*this, other_tree)
, Destroyer(this->node_alloc()));
//If there are remaining nodes, destroy them
NodePtr p;
while((p = other_tree.unlink_leftmost_without_rebalance())){
AllocHolder::destroy_node(p);
}
}
return *this;
}
public:
// accessors:
BOOST_CONTAINER_FORCEINLINE value_compare value_comp() const
{ return this->icont().value_comp().predicate(); }
BOOST_CONTAINER_FORCEINLINE key_compare key_comp() const
{ return this->icont().value_comp().predicate().key_comp(); }
BOOST_CONTAINER_FORCEINLINE allocator_type get_allocator() const
{ return allocator_type(this->node_alloc()); }
BOOST_CONTAINER_FORCEINLINE const stored_allocator_type &get_stored_allocator() const
{ return this->node_alloc(); }
BOOST_CONTAINER_FORCEINLINE stored_allocator_type &get_stored_allocator()
{ return this->node_alloc(); }
BOOST_CONTAINER_FORCEINLINE iterator begin()
{ return iterator(this->icont().begin()); }
BOOST_CONTAINER_FORCEINLINE const_iterator begin() const
include/boost/container/detail/tree.hpp view on Meta::CPAN
BOOST_CONTAINER_FORCEINLINE const_iterator end() const
{ return this->cend(); }
BOOST_CONTAINER_FORCEINLINE reverse_iterator rbegin()
{ return reverse_iterator(end()); }
BOOST_CONTAINER_FORCEINLINE const_reverse_iterator rbegin() const
{ return this->crbegin(); }
BOOST_CONTAINER_FORCEINLINE reverse_iterator rend()
{ return reverse_iterator(begin()); }
BOOST_CONTAINER_FORCEINLINE const_reverse_iterator rend() const
{ return this->crend(); }
//! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE const_iterator cbegin() const
{ return const_iterator(this->non_const_icont().begin()); }
//! <b>Effects</b>: Returns a const_iterator to the end of the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE const_iterator cend() const
{ return const_iterator(this->non_const_icont().end()); }
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
//! of the reversed container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE const_reverse_iterator crbegin() const
{ return const_reverse_iterator(cend()); }
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
//! of the reversed container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE const_reverse_iterator crend() const
{ return const_reverse_iterator(cbegin()); }
BOOST_CONTAINER_FORCEINLINE bool empty() const
{ return !this->size(); }
BOOST_CONTAINER_FORCEINLINE size_type size() const
{ return this->icont().size(); }
BOOST_CONTAINER_FORCEINLINE size_type max_size() const
{ return AllocHolder::max_size(); }
BOOST_CONTAINER_FORCEINLINE void swap(ThisType& x)
BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::dtl::is_nothrow_swappable<Compare>::value )
{ AllocHolder::swap(x); }
public:
typedef typename Icont::insert_commit_data insert_commit_data;
// insert/erase
std::pair<iterator,bool> insert_unique_check
(const key_type& key, insert_commit_data &data)
{
std::pair<iiterator, bool> ret =
this->icont().insert_unique_check(key, KeyNodeCompare(key_comp()), data);
return std::pair<iterator, bool>(iterator(ret.first), ret.second);
}
std::pair<iterator,bool> insert_unique_check
(const_iterator hint, const key_type& key, insert_commit_data &data)
{
BOOST_ASSERT((priv_is_linked)(hint));
std::pair<iiterator, bool> ret =
this->icont().insert_unique_check(hint.get(), key, KeyNodeCompare(key_comp()), data);
return std::pair<iterator, bool>(iterator(ret.first), ret.second);
}
template<class MovableConvertible>
iterator insert_unique_commit
(BOOST_FWD_REF(MovableConvertible) v, insert_commit_data &data)
{
NodePtr tmp = AllocHolder::create_node(boost::forward<MovableConvertible>(v));
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
iterator ret(this->icont().insert_unique_commit(*tmp, data));
destroy_deallocator.release();
return ret;
}
template<class MovableConvertible>
std::pair<iterator,bool> insert_unique(BOOST_FWD_REF(MovableConvertible) v)
{
insert_commit_data data;
std::pair<iterator,bool> ret =
this->insert_unique_check(KeyOfValue()(v), data);
if(ret.second){
ret.first = this->insert_unique_commit(boost::forward<MovableConvertible>(v), data);
}
return ret;
}
private:
template<class KeyConvertible, class M>
iiterator priv_insert_or_assign_commit
(BOOST_FWD_REF(KeyConvertible) key, BOOST_FWD_REF(M) obj, insert_commit_data &data)
{
NodePtr tmp = AllocHolder::create_node(boost::forward<KeyConvertible>(key), boost::forward<M>(obj));
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
iiterator ret(this->icont().insert_unique_commit(*tmp, data));
destroy_deallocator.release();
return ret;
}
bool priv_is_linked(const_iterator const position) const
{
iiterator const cur(position.get());
return cur == this->icont().end() ||
cur == this->icont().root() ||
iiterator(cur).go_parent().go_left() == cur ||
iiterator(cur).go_parent().go_right() == cur;
}
template<class MovableConvertible>
void push_back_impl(BOOST_FWD_REF(MovableConvertible) v)
{
NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
//push_back has no-throw guarantee so avoid any deallocator/destroyer
this->icont().push_back(*tmp);
}
std::pair<iterator, bool> emplace_unique_impl(NodePtr p)
{
value_type &v = p->get_data();
insert_commit_data data;
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(p, this->node_alloc());
std::pair<iterator,bool> ret =
this->insert_unique_check(KeyOfValue()(v), data);
if(!ret.second){
return ret;
}
//No throw insertion part, release rollback
destroy_deallocator.release();
return std::pair<iterator,bool>
( iterator(this->icont().insert_unique_commit(*p, data))
, true );
}
iterator emplace_unique_hint_impl(const_iterator hint, NodePtr p)
{
BOOST_ASSERT((priv_is_linked)(hint));
value_type &v = p->get_data();
insert_commit_data data;
std::pair<iterator,bool> ret =
this->insert_unique_check(hint, KeyOfValue()(v), data);
if(!ret.second){
Destroyer(this->node_alloc())(p);
return ret.first;
}
return iterator(this->icont().insert_unique_commit(*p, data));
}
public:
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args>
BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> emplace_unique(BOOST_FWD_REF(Args)... args)
{ return this->emplace_unique_impl(AllocHolder::create_node(boost::forward<Args>(args)...)); }
template <class... Args>
BOOST_CONTAINER_FORCEINLINE iterator emplace_hint_unique(const_iterator hint, BOOST_FWD_REF(Args)... args)
{ return this->emplace_unique_hint_impl(hint, AllocHolder::create_node(boost::forward<Args>(args)...)); }
template <class... Args>
iterator emplace_equal(BOOST_FWD_REF(Args)... args)
{
NodePtr tmp(AllocHolder::create_node(boost::forward<Args>(args)...));
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));
destroy_deallocator.release();
return ret;
}
template <class... Args>
iterator emplace_hint_equal(const_iterator hint, BOOST_FWD_REF(Args)... args)
{
BOOST_ASSERT((priv_is_linked)(hint));
NodePtr tmp(AllocHolder::create_node(boost::forward<Args>(args)...));
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
iterator ret(this->icont().insert_equal(hint.get(), *tmp));
destroy_deallocator.release();
return ret;
}
template <class KeyType, class... Args>
BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace
(const_iterator hint, BOOST_FWD_REF(KeyType) key, BOOST_FWD_REF(Args)... args)
{
insert_commit_data data;
const key_type & k = key; //Support emulated rvalue references
std::pair<iiterator, bool> ret =
( run in 0.510 second using v1.01-cache-2.11-cpan-63c85eba8c4 )