Fixed Solaris-gcc errors and added splay trees

[SVN r40428]
This commit is contained in:
Ion Gaztañaga
2007-10-24 18:59:26 +00:00
parent 28befc2384
commit 40835daaba
18 changed files with 6643 additions and 990 deletions

View File

@@ -13,22 +13,23 @@
#define BOOST_INTRUSIVE_RBTREE_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <algorithm>
#include <cstddef>
#include <functional>
#include <iterator>
#include <utility>
#include <boost/intrusive/detail/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/pointer_to_other.hpp>
#include <boost/intrusive/set_hook.hpp>
#include <boost/intrusive/detail/rbtree_node.hpp>
#include <boost/intrusive/detail/tree_node.hpp>
#include <boost/intrusive/detail/ebo_functor_holder.hpp>
#include <boost/intrusive/detail/pointer_to_other.hpp>
#include <boost/intrusive/options.hpp>
#include <boost/intrusive/rbtree_algorithms.hpp>
#include <boost/intrusive/link_mode.hpp>
#include <cstddef>
#include <iterator>
#include <algorithm>
namespace boost {
namespace intrusive {
@@ -78,7 +79,7 @@ struct set_defaults
/// @endcond
//! The class template rbtree is an intrusive red-black tree container, that
//! is used to construct intrusive set and tree containers. The no-throw
//! is used to construct intrusive set and multiset containers. The no-throw
//! guarantee holds only, if the value_compare object
//! doesn't throw.
//!
@@ -118,11 +119,11 @@ class rbtree_impl
typedef typename Config::size_type size_type;
typedef typename Config::compare value_compare;
typedef value_compare key_compare;
typedef rbtree_iterator<rbtree_impl, false> iterator;
typedef rbtree_iterator<rbtree_impl, true> const_iterator;
typedef tree_iterator<rbtree_impl, false> iterator;
typedef tree_iterator<rbtree_impl, true> const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef typename real_value_traits::node_traits node_traits;
typedef typename real_value_traits::node_traits node_traits;
typedef typename node_traits::node node;
typedef typename boost::pointer_to_other
<pointer, node>::type node_ptr;
@@ -235,7 +236,7 @@ class rbtree_impl
//! [b, e).
//!
//! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
//! comp and otherwise N * log N, where N is last <20> first.
//! comp and otherwise N * log N, where N is the distance between first and last.
//!
//! <b>Throws</b>: Nothing unless the copy constructor of the value_compare object throws.
template<class Iterator>
@@ -411,8 +412,12 @@ class rbtree_impl
{
if(constant_time_size)
return this->priv_size_traits().get_size();
else
return empty() ? 0 : node_algorithms::count(node_traits::get_parent(const_node_ptr(&priv_header())));
else{
const_iterator beg(this->cbegin()), end(this->cend());
size_type i = 0;
for(;beg != end; ++beg) ++i;
return i;
}
}
//! <b>Effects</b>: Swaps the contents of two multisets.
@@ -445,7 +450,7 @@ class rbtree_impl
//!
//! <b>Note</b>: Does not affect the validity of iterators and references.
//! No copy-constructors are called.
iterator insert_equal_upper_bound(reference value)
iterator insert_equal(reference value)
{
detail::key_nodeptr_comp<value_compare, rbtree_impl>
key_node_comp(priv_comp(), this);
@@ -457,29 +462,6 @@ class rbtree_impl
(node_ptr(&priv_header()), to_insert, key_node_comp), this);
}
//! <b>Requires</b>: value must be an lvalue
//!
//! <b>Effects</b>: Inserts value into the tree before the lower bound.
//!
//! <b>Complexity</b>: Average complexity for insert element is at
//! most logarithmic.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: Does not affect the validity of iterators and references.
//! No copy-constructors are called.
iterator insert_equal_lower_bound(reference value)
{
detail::key_nodeptr_comp<value_compare, rbtree_impl>
key_node_comp(priv_comp(), this);
node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
if(safemode_or_autounlink)
BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
this->priv_size_traits().increment();
return iterator(node_algorithms::insert_equal_lower_bound
(node_ptr(&priv_header()), to_insert, key_node_comp), this);
}
//! <b>Requires</b>: value must be an lvalue, and "hint" must be
//! a valid iterator.
//!
@@ -523,15 +505,9 @@ class rbtree_impl
template<class Iterator>
void insert_equal(Iterator b, Iterator e)
{
if(this->empty()){
iterator end(this->end());
for (; b != e; ++b)
this->insert_equal(end, *b);
}
else{
for (; b != e; ++b)
this->insert_equal_upper_bound(*b);
}
iterator end(this->end());
for (; b != e; ++b)
this->insert_equal(end, *b);
}
//! <b>Requires</b>: value must be an lvalue
@@ -1059,6 +1035,19 @@ class rbtree_impl
return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this));
}
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
//!
//! <b>Effects</b>: Erases all the elements from *this
//! calling Disposer::operator()(pointer), clones all the
//! elements from src calling Cloner::operator()(const_reference )
//! and inserts them on *this.
//!
//! If cloner throws, all cloned elements are unlinked and disposed
//! calling Disposer::operator()(pointer).
//!
//! <b>Complexity</b>: Linear to erased plus inserted elements.
//!
//! <b>Throws</b>: If cloner throws.
template <class Cloner, class Disposer>
void clone_from(const rbtree_impl &src, Cloner cloner, Disposer disposer)
{
@@ -1073,6 +1062,16 @@ class rbtree_impl
}
}
//! <b>Effects</b>: Unlinks the leftmost node from the tree.
//!
//! <b>Complexity</b>: Average complexity is constant time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Notes</b>: This function breaks the tree and the tree can
//! only be used for more unlink_leftmost_without_rebalance calls.
//! This function is normally used to achieve a step by step
//! controlled destruction of the tree.
pointer unlink_leftmost_without_rebalance()
{
node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance
@@ -1132,7 +1131,7 @@ class rbtree_impl
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Throws</b>: Nothing.<EFBFBD>
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: This static function is available only if the <i>value traits</i>
//! is stateless.
@@ -1266,14 +1265,14 @@ bool operator==
{
typedef rbtree_impl<Config> tree_type;
typedef typename tree_type::const_iterator const_iterator;
const bool CS = tree_type::constant_time_size;
if(CS && x.size() != y.size()){
if(tree_type::constant_time_size && x.size() != y.size()){
return false;
}
const_iterator end1 = x.end();
const_iterator i1 = x.begin();
const_iterator i2 = y.begin();
if(CS){
if(tree_type::constant_time_size){
while (i1 != end1 && *i1 == *i2) {
++i1;
++i2;