forked from boostorg/intrusive
* New treap-based containers: treap, treap_set, treap_multiset.
* Corrected compilation bug for Windows-based 64 bit compilers. * Corrected exception-safety bugs in container constructors. * Updated documentation to show rvalue-references funcions instead of emulation functions. [SVN r50259]
This commit is contained in:
1 parent
1dc26850af
commit
4b272cf3c7
66 files changed
+1580
-824
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007
|
||||
// (C) Copyright Ion Gaztanaga 2007-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -47,7 +47,7 @@ struct my_avltree_node_traits
|
||||
|
||||
struct node_ptr_compare
|
||||
{
|
||||
bool operator()(my_node *a, my_node *b)
|
||||
bool operator()(const my_node *a, const my_node *b)
|
||||
{ return a->int_ < b->int_; }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007
|
||||
// (C) Copyright Ion Gaztanaga 2007-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007
|
||||
// (C) Copyright Ion Gaztanaga 2007-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -45,7 +45,7 @@ struct my_rbtree_node_traits
|
||||
|
||||
struct node_ptr_compare
|
||||
{
|
||||
bool operator()(my_node *a, my_node *b)
|
||||
bool operator()(const my_node *a, const my_node *b)
|
||||
{ return a->int_ < b->int_; }
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007
|
||||
// (C) Copyright Ion Gaztanaga 2007-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -41,7 +41,7 @@ struct my_splaytree_node_traits
|
||||
|
||||
struct node_ptr_compare
|
||||
{
|
||||
bool operator()(my_node *a, my_node *b)
|
||||
bool operator()(const my_node *a, const my_node *b)
|
||||
{ return a->int_ < b->int_; }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007
|
||||
// (C) Copyright Ion Gaztanaga 2007-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -40,7 +40,7 @@ struct my_splaytree_node_traits
|
||||
|
||||
struct node_ptr_compare
|
||||
{
|
||||
bool operator()(my_node *a, my_node *b)
|
||||
bool operator()(const my_node *a, const my_node *b)
|
||||
{ return a->int_ < b->int_; }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007
|
||||
// (C) Copyright Ion Gaztanaga 2007-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007-2008
|
||||
//
|
||||
// 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/intrusive for documentation.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//[doc_treap_algorithms_code
|
||||
#include <boost/intrusive/treap_algorithms.hpp>
|
||||
#include <cassert>
|
||||
|
||||
struct my_node
|
||||
{
|
||||
my_node(int i = 0, unsigned int priority = 0)
|
||||
: prio_(priority), int_(i)
|
||||
{}
|
||||
my_node *parent_, *left_, *right_;
|
||||
int prio_;
|
||||
//other members
|
||||
int int_;
|
||||
};
|
||||
|
||||
//Define our own treap_node_traits
|
||||
struct my_treap_node_traits
|
||||
{
|
||||
typedef my_node node;
|
||||
typedef my_node * node_ptr;
|
||||
typedef const my_node * const_node_ptr;
|
||||
|
||||
static node_ptr get_parent(const_node_ptr n) { return n->parent_; }
|
||||
static void set_parent(node_ptr n, node_ptr parent){ n->parent_ = parent; }
|
||||
static node_ptr get_left(const_node_ptr n) { return n->left_; }
|
||||
static void set_left(node_ptr n, node_ptr left) { n->left_ = left; }
|
||||
static node_ptr get_right(const_node_ptr n) { return n->right_; }
|
||||
static void set_right(node_ptr n, node_ptr right) { n->right_ = right; }
|
||||
};
|
||||
|
||||
struct node_ptr_compare
|
||||
{ bool operator()(const my_node *a, const my_node *b) { return a->int_ < b->int_; } };
|
||||
|
||||
struct node_ptr_priority
|
||||
{ bool operator()(const my_node *a, const my_node *b) { return a->prio_ < b->prio_;} };
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::intrusive::treap_algorithms<my_treap_node_traits> algo;
|
||||
my_node header, two(2, 5), three(3, 1);
|
||||
|
||||
//Create an empty treap container:
|
||||
//"header" will be the header node of the tree
|
||||
algo::init_header(&header);
|
||||
|
||||
//Now insert node "two" in the tree using the sorting functor
|
||||
algo::insert_equal_upper_bound(&header, &two, node_ptr_compare(), node_ptr_priority());
|
||||
|
||||
//Now insert node "three" in the tree using the sorting functor
|
||||
algo::insert_equal_lower_bound(&header, &three, node_ptr_compare(), node_ptr_priority());
|
||||
|
||||
//Now take the first node (the left node of the header)
|
||||
my_node *n = header.left_;
|
||||
assert(n == &two);
|
||||
|
||||
//Now go to the next node
|
||||
n = algo::next_node(n);
|
||||
assert(n == &three);
|
||||
|
||||
//Erase a node just using a pointer to it
|
||||
algo::unlink(&two, node_ptr_priority());
|
||||
|
||||
//Erase a node using also the header (faster)
|
||||
algo::erase(&header, &three, node_ptr_priority());
|
||||
return 0;
|
||||
}
|
||||
|
||||
//]
|
||||
@@ -0,0 +1,106 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// 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/intrusive for documentation.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//[doc_treap_set_code
|
||||
#include <boost/intrusive/treap_set.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
using namespace boost::intrusive;
|
||||
|
||||
class MyClass : public bs_set_base_hook<> //This is a base hook
|
||||
{
|
||||
int int_;
|
||||
unsigned int prio_;
|
||||
|
||||
public:
|
||||
//This is a member hook
|
||||
bs_set_member_hook<> member_hook_;
|
||||
|
||||
MyClass(int i, unsigned int prio) : int_(i), prio_(prio)
|
||||
{}
|
||||
|
||||
unsigned int get_priority() const
|
||||
{ return this->prio_; }
|
||||
|
||||
//Less and greater operators
|
||||
friend bool operator< (const MyClass &a, const MyClass &b)
|
||||
{ return a.int_ < b.int_; }
|
||||
friend bool operator> (const MyClass &a, const MyClass &b)
|
||||
{ return a.int_ > b.int_; }
|
||||
//Default priority compare
|
||||
friend bool priority_order (const MyClass &a, const MyClass &b)
|
||||
{ return a.prio_ < b.prio_; } //Lower value means higher priority
|
||||
//Inverse priority compare
|
||||
friend bool priority_inverse_order (const MyClass &a, const MyClass &b)
|
||||
{ return a.prio_ > b.prio_; } //Higher value means higher priority
|
||||
};
|
||||
|
||||
struct inverse_priority
|
||||
{
|
||||
bool operator()(const MyClass &a, const MyClass &b) const
|
||||
{ return priority_inverse_order(a, b); }
|
||||
};
|
||||
|
||||
|
||||
//Define an treap_set using the base hook that will store values in reverse order
|
||||
typedef treap_set< MyClass, compare<std::greater<MyClass> > > BaseSet;
|
||||
|
||||
//Define an multiset using the member hook that will store
|
||||
typedef member_hook<MyClass, bs_set_member_hook<>, &MyClass::member_hook_> MemberOption;
|
||||
typedef treap_multiset
|
||||
< MyClass, MemberOption, priority<inverse_priority> > MemberMultiset;
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::vector<MyClass>::iterator VectIt;
|
||||
|
||||
//Create several MyClass objects, each one with a different value
|
||||
std::vector<MyClass> values;
|
||||
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i, (i % 10)));
|
||||
|
||||
BaseSet baseset;
|
||||
MemberMultiset membermultiset;
|
||||
|
||||
//Now insert them in the sets
|
||||
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
|
||||
baseset.insert(*it);
|
||||
membermultiset.insert(*it);
|
||||
}
|
||||
|
||||
//Now test treap_sets
|
||||
{
|
||||
BaseSet::reverse_iterator rbit(baseset.rbegin()), rbitend(baseset.rend());
|
||||
MemberMultiset::iterator mit(membermultiset.begin()), mitend(membermultiset.end());
|
||||
VectIt it(values.begin()), itend(values.end());
|
||||
|
||||
//Test the objects inserted in the base hook treap_set
|
||||
for(; it != itend; ++it, ++rbit)
|
||||
if(&*rbit != &*it) return 1;
|
||||
|
||||
//Test the objects inserted in the member hook treap_set
|
||||
for(it = values.begin(); it != itend; ++it, ++mit)
|
||||
if(&*mit != &*it) return 1;
|
||||
|
||||
//Test priority order
|
||||
for(int i = 0; i < 100; ++i){
|
||||
if(baseset.top()->get_priority() != static_cast<unsigned int>(i/10))
|
||||
return 1;
|
||||
if(membermultiset.top()->get_priority() != 9u - static_cast<unsigned int>(i/10))
|
||||
return 1;
|
||||
baseset.erase(baseset.top());
|
||||
membermultiset.erase(membermultiset.top());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//]
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007
|
||||
// (C) Copyright Ion Gaztanaga 2006-2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
Reference in new issue
Block a user