* 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:
Ion Gaztañaga
2008-12-13 13:49:31 +00:00
parent 1dc26850af
commit 4b272cf3c7
66 changed files with 1580 additions and 824 deletions

View File

@@ -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
@@ -13,12 +13,22 @@
#include <boost/intrusive/slist.hpp>
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/unordered_set.hpp>
#include <boost/intrusive/avl_set.hpp>
#include <boost/intrusive/sg_set.hpp>
#include <boost/intrusive/splay_set.hpp>
#include <boost/intrusive/treap_set.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include "smart_ptr.hpp"
#include <vector>
using namespace boost::intrusive;
struct my_tag;
typedef make_bs_set_base_hook
< void_pointer<smart_ptr<void> >, link_mode<normal_link>
, tag<my_tag> >::type TreapHook;
class MyClass
: public make_list_base_hook
< void_pointer<smart_ptr<void> >, link_mode<normal_link> >::type
@@ -28,6 +38,13 @@ class MyClass
< void_pointer<smart_ptr<void> >, link_mode<normal_link> >::type
, public make_unordered_set_base_hook
< void_pointer<smart_ptr<void> >, link_mode<normal_link> >::type
, public make_avl_set_base_hook
< void_pointer<smart_ptr<void> >, link_mode<normal_link> >::type
, public make_splay_set_base_hook
< void_pointer<smart_ptr<void> >, link_mode<normal_link> >::type
, public make_bs_set_base_hook
< void_pointer<smart_ptr<void> >, link_mode<normal_link> >::type
, public TreapHook
{
int int_;
@@ -44,6 +61,9 @@ class MyClass
friend std::size_t hash_value(const MyClass &v)
{ return boost::hash_value(v.int_); }
friend bool priority_order(const MyClass &l, const MyClass &r)
{ return l.int_ < r.int_; }
};
//Define a list that will store MyClass using the public base hook
@@ -52,6 +72,12 @@ typedef make_slist<MyClass>::type Slist;
typedef make_set<MyClass>::type Set;
typedef make_unordered_set<MyClass>::type USet;
typedef make_avl_set<MyClass>::type AvlSet;
typedef make_splay_set<MyClass>::type SplaySet;
typedef make_sg_set<MyClass>::type SgSet;
typedef make_treap_set<MyClass
, base_hook<TreapHook> >::type TreapSet;
int main()
{
typedef std::vector<MyClass>::iterator VectIt;
@@ -68,12 +94,21 @@ int main()
Set my_set;
USet my_uset(USet::bucket_traits(buckets, 100));
AvlSet my_avlset;
SplaySet my_splayset;
SgSet my_sgset;
TreapSet my_treapset;
//Now insert them in containers
for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
my_list.push_front(*it);
my_slist.push_front(*it);
my_set.insert(*it);
my_uset.insert(*it);
my_avlset.insert(*it);
my_splayset.insert(*it);
my_sgset.insert(*it);
my_treapset.insert(*it);
}
//Now test lists
@@ -81,14 +116,27 @@ int main()
List::const_iterator list_it(my_list.cbegin());
Slist::const_iterator slist_it(my_slist.cbegin());
Set::const_reverse_iterator set_rit(my_set.crbegin());
AvlSet::const_reverse_iterator avlset_rit(my_avlset.crbegin());
SplaySet::const_reverse_iterator splayset_rit(my_splayset.crbegin());
SgSet::const_reverse_iterator sgset_rit(my_sgset.crbegin());
TreapSet::const_reverse_iterator treapset_rit(my_treapset.crbegin());
VectRit vect_it(values.rbegin()), vect_itend(values.rend());
//Test the objects inserted in the base hook list
for(; vect_it != vect_itend; ++vect_it, ++list_it, ++slist_it, ++set_rit){
for( ; vect_it != vect_itend
; ++vect_it, ++list_it, ++slist_it, ++set_rit
, ++avlset_rit, ++splayset_rit, ++sgset_rit, ++treapset_rit
){
if(&*list_it != &*vect_it) return 1;
if(&*slist_it != &*vect_it) return 1;
if(&*set_rit != &*vect_it) return 1;
if(my_uset.find(*set_rit) == my_uset.cend()) return 1;
if(&*avlset_rit != &*vect_it) return 1;
if(&*splayset_rit != &*vect_it) return 1;
if(&*sgset_rit != &*vect_it) return 1;
if(&*treapset_rit != &*vect_it) return 1;
}
}
@@ -117,6 +165,24 @@ int main()
return 1;
}
if(detail::is_same<make_avl_set_base_hook<void_pointer<void*>, link_mode<safe_link> >::type
,make_avl_set_base_hook<>::type
>::value == false){
return 1;
}
if(detail::is_same<make_bs_set_base_hook<void_pointer<void*>, link_mode<safe_link> >::type
,make_bs_set_base_hook<>::type
>::value == false){
return 1;
}
if(detail::is_same<make_splay_set_base_hook<void_pointer<void*>, link_mode<safe_link> >::type
,make_splay_set_base_hook<>::type
>::value == false){
return 1;
}
//Check defined types and implicitly defined types are unequal
if(detail::is_same<make_list_base_hook<void_pointer<void*>, link_mode<normal_link> >::type
,make_list_base_hook<>::type
@@ -142,6 +208,24 @@ int main()
return 1;
}
if(detail::is_same<make_avl_set_base_hook<void_pointer<void*>, link_mode<normal_link> >::type
,make_avl_set_base_hook<>::type
>::value == true){
return 1;
}
if(detail::is_same<make_splay_set_base_hook<void_pointer<void*>, link_mode<normal_link> >::type
,make_splay_set_base_hook<>::type
>::value == true){
return 1;
}
if(detail::is_same<make_bs_set_base_hook<void_pointer<void*>, link_mode<normal_link> >::type
,make_bs_set_base_hook<>::type
>::value == true){
return 1;
}
return 0;
}