forked from boostorg/intrusive
Reverted git mess.
This commit is contained in:
1 parent
27e5ad9183
commit
68fa82e5e8
59 files changed
+1937
-3049
No files matched your search
@@ -24,7 +24,8 @@ class MyClass : public auto_unlink_hook
|
||||
|
||||
public:
|
||||
MyClass(int i = 0) : int_(i) {}
|
||||
void unlink() { auto_unlink_hook::unlink(); }
|
||||
int get_int() { return int_; }
|
||||
void unlink() { auto_unlink_hook::unlink(); }
|
||||
bool is_linked() { return auto_unlink_hook::is_linked(); }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007-2013
|
||||
//
|
||||
// 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_external_value_traits
|
||||
#include <boost/intrusive/list.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace boost::intrusive;
|
||||
|
||||
//This type is not modifiable so we can't store hooks or custom nodes
|
||||
typedef int identifier_t;
|
||||
|
||||
//This value traits will associate elements from an array of identifiers with
|
||||
//elements of an array of nodes. The element i of the value array will use the
|
||||
//node i of the node array:
|
||||
class external_traits
|
||||
{
|
||||
//Non-copyable
|
||||
external_traits(const external_traits &);
|
||||
external_traits& operator=(const external_traits &);
|
||||
|
||||
public:
|
||||
typedef list_node_traits<void*> node_traits;
|
||||
typedef node_traits::node node;
|
||||
typedef node * node_ptr;
|
||||
typedef const node * const_node_ptr;
|
||||
typedef identifier_t value_type;
|
||||
typedef identifier_t * pointer;
|
||||
typedef const identifier_t * const_pointer;
|
||||
static const link_mode_type link_mode = normal_link;
|
||||
|
||||
external_traits(pointer ids, std::size_t NumElements)
|
||||
: ids_(ids), nodes_(NumElements)
|
||||
{}
|
||||
|
||||
///Note: non static functions!
|
||||
node_ptr to_node_ptr (value_type &value)
|
||||
{ return &this->nodes_[0] + (&value - this->ids_); }
|
||||
const_node_ptr to_node_ptr (const value_type &value) const
|
||||
{ return &this->nodes_[0] + (&value - this->ids_); }
|
||||
pointer to_value_ptr(node_ptr n)
|
||||
{ return this->ids_ + (n - &this->nodes_[0]); }
|
||||
const_pointer to_value_ptr(const_node_ptr n) const
|
||||
{ return this->ids_ + (n - &this->nodes_[0]); }
|
||||
|
||||
private:
|
||||
pointer ids_;
|
||||
//This is an array of nodes that is necessary to form the linked list
|
||||
std::vector<list_node_traits<void*>::node> nodes_;
|
||||
};
|
||||
|
||||
//This is the value traits class that will be stored in the container
|
||||
//and that will lead to the external traits using the address
|
||||
//of the container.
|
||||
struct internal_traits
|
||||
{
|
||||
static const bool external_value_traits = true;
|
||||
typedef external_traits value_traits;
|
||||
|
||||
template<class Container>
|
||||
value_traits &get_value_traits(Container &cont);
|
||||
|
||||
template<class Container>
|
||||
const value_traits &get_value_traits(const Container &cont) const;
|
||||
};
|
||||
|
||||
//The intrusive list that will use external value traits
|
||||
typedef list<identifier_t, value_traits<internal_traits> > List;
|
||||
|
||||
class data_holder
|
||||
: public List
|
||||
{
|
||||
public:
|
||||
data_holder(identifier_t *ids, std::size_t NumElements)
|
||||
: List()
|
||||
, external_traits_(ids, NumElements)
|
||||
{}
|
||||
external_traits external_traits_;
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
internal_traits::value_traits &internal_traits::get_value_traits(Container &cont)
|
||||
{ return static_cast<data_holder&>(cont).external_traits_; }
|
||||
|
||||
template<class Container>
|
||||
const internal_traits::value_traits &internal_traits::get_value_traits(const Container &cont) const
|
||||
{ return static_cast<const data_holder&>(cont).external_traits_; }
|
||||
|
||||
int main()
|
||||
{
|
||||
const int NumElements = 100;
|
||||
|
||||
//This is an array of ids that we want to "store"
|
||||
identifier_t ids [NumElements];
|
||||
|
||||
//Initialize id objects, each one with a different number
|
||||
for(int i = 0; i != NumElements; ++i) ids[i] = i;
|
||||
|
||||
//The data holding the list and the external traits
|
||||
data_holder data(ids, NumElements);
|
||||
|
||||
//This list will store ids without modifying identifier_t instances
|
||||
//Stateful value traits must be explicitly passed in the constructor.
|
||||
List &my_list = data;
|
||||
|
||||
//Insert ids in reverse order in the list
|
||||
for(identifier_t * it(&ids[0]), *itend(&ids[NumElements]); it != itend; ++it)
|
||||
my_list.push_front(*it);
|
||||
|
||||
//Now test lists
|
||||
List::const_iterator list_it (my_list.cbegin());
|
||||
identifier_t *it_val(&ids[NumElements]-1), *it_rbeg_val(&ids[0] -1);
|
||||
|
||||
//Test the objects inserted in the base hook list
|
||||
for(; it_val != it_rbeg_val; --it_val, ++list_it){
|
||||
if(&*list_it != &*it_val) return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
//]
|
||||
@@ -11,7 +11,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//[doc_splay_set_code
|
||||
#include <boost/intrusive/splay_set.hpp>
|
||||
#include <boost/intrusive/bs_set_hook.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -20,14 +19,13 @@ using namespace boost::intrusive;
|
||||
class mytag;
|
||||
|
||||
class MyClass
|
||||
: public splay_set_base_hook<> //This is an splay tree base hook
|
||||
, public bs_set_base_hook< tag<mytag> > //This is a binary search tree base hook
|
||||
: public bs_set_base_hook<>
|
||||
{
|
||||
int int_;
|
||||
|
||||
public:
|
||||
//This is a member hook
|
||||
splay_set_member_hook<> member_hook_;
|
||||
bs_set_member_hook<> member_hook_;
|
||||
|
||||
MyClass(int i)
|
||||
: int_(i)
|
||||
@@ -43,11 +41,8 @@ class MyClass
|
||||
//Define a set using the base hook that will store values in reverse order
|
||||
typedef splay_set< MyClass, compare<std::greater<MyClass> > > BaseSplaySet;
|
||||
|
||||
//Define a set using the binary search tree hook
|
||||
typedef splay_set< MyClass, base_hook<bs_set_base_hook< tag<mytag> > > > BaseBsSplaySet;
|
||||
|
||||
//Define an multiset using the member hook
|
||||
typedef member_hook<MyClass, splay_set_member_hook<>, &MyClass::member_hook_> MemberOption;
|
||||
typedef member_hook<MyClass, bs_set_member_hook<>, &MyClass::member_hook_> MemberOption;
|
||||
typedef splay_multiset< MyClass, MemberOption> MemberSplayMultiset;
|
||||
|
||||
int main()
|
||||
@@ -59,21 +54,18 @@ int main()
|
||||
for(int i = 0; i < 100; ++i) values.push_back(MyClass(i));
|
||||
|
||||
BaseSplaySet baseset;
|
||||
BaseBsSplaySet bsbaseset;
|
||||
MemberSplayMultiset membermultiset;
|
||||
|
||||
|
||||
//Insert values in the container
|
||||
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
|
||||
baseset.insert(*it);
|
||||
bsbaseset.insert(*it);
|
||||
membermultiset.insert(*it);
|
||||
}
|
||||
|
||||
//Now test sets
|
||||
{
|
||||
BaseSplaySet::reverse_iterator rbit(baseset.rbegin());
|
||||
BaseBsSplaySet::iterator bsit(bsbaseset.begin());
|
||||
MemberSplayMultiset::iterator mit(membermultiset.begin());
|
||||
VectIt it(values.begin()), itend(values.end());
|
||||
|
||||
@@ -83,8 +75,7 @@ int main()
|
||||
}
|
||||
|
||||
//Test the objects inserted in member and binary search hook sets
|
||||
for(it = values.begin(); it != itend; ++it, ++bsit, ++mit){
|
||||
if(&*bsit != &*it) return 1;
|
||||
for(it = values.begin(); it != itend; ++it, ++mit){
|
||||
if(&*mit != &*it) return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user