diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 9cac616..f00fe39 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -38,7 +38,10 @@ doxygen autodoc "sgtree_impl=sgtree" \\ "avl_set_impl=avl_set" \\ "avl_multiset_impl=avl_multiset" \\ - "avltree_impl=avltree"" + "avltree_impl=avltree" \\ + "treap_set_impl=treap_set" \\ + "treap_multiset_impl=treap_multiset" \\ + "treap_impl=treap"" ; xml intrusive : intrusive.qbk ; diff --git a/doc/intrusive.qbk b/doc/intrusive.qbk index b80d17e..eb9df46 100644 --- a/doc/intrusive.qbk +++ b/doc/intrusive.qbk @@ -8,7 +8,7 @@ [library Boost.Intrusive [quickbook 1.3] [authors [Krzikalla, Olaf], [Gaztañaga, Ion]] - [copyright 2005 Olaf Krzikalla, 2006-2007 Ion Gaztañaga] + [copyright 2005 Olaf Krzikalla, 2006-2008 Ion Gaztañaga] [id intrusive] [dirname intrusive] [purpose Intrusive containers] @@ -1693,7 +1693,7 @@ has also the size of 3 pointers, two integers and two floating point values [classref boost::intrusive::sgtree sgtree] don't use their own hooks but plain binary search tree hooks. This has many advantages since binary search tree hooks can also be used to insert values in -splay containers. +splay and treap containers. [c++] @@ -1716,8 +1716,7 @@ splay containers. [classref boost::intrusive::bs_set_base_hook bs_set_base_hook] and [classref boost::intrusive::bs_set_member_hook bs_set_member_hook] receive the same options explained in the section -[link intrusive.usage How to use Boost.Intrusive] plus an option to optimize -the size of the node: +[link intrusive.usage How to use Boost.Intrusive]: * [*`tag`] (for base hooks only): This argument serves as a tag, so you can derive from more than one base hook. @@ -1786,22 +1785,180 @@ containers: [endsect] +[section:treap_set_multiset Intrusive treap based associative containers: treap_set, treap_multiset and treap] +The name ['treap] is a mixture of ['tree] and ['heap] indicating that Treaps exhibit the properties of both +binary search trees and heaps. A treap is a binary search tree that orders the nodes +by a key but also by a priority attribute. The nodes are ordered so that the keys form a binary search tree and +the priorities obey the max heap order property. +* If v is a left descendant of u, then key[v] < key[u]; +* If v is a right descendant of u, then key[v] > key[u]; +* If v is a child of u, then priority[v] <= priority[u]; +If priorities are non-random, the tree will usually be unbalanced; this worse theoretical average-case +behavior may be outweighed by better expected-case behavior, as the most important items will be near the root. +This means most important objects will be retrieved faster than less important items and for items keys with equal keys +most important objects will be found first. These properties are important for some applications. +The priority comparison will be provided just like the key comparison, via a funcion object that will be +stored in the intrusive container. This means that the priority can be stored in the value to be introduced +in the treap or computed on flight (via hashing or similar). +[*Boost.Intrusive] offers 3 containers based on treaps: +[classref boost::intrusive::treap_set treap_set], +[classref boost::intrusive::treap_multiset treap_multiset] and +[classref boost::intrusive::treap treap]. The first two are similar to +[classref boost::intrusive::set set] or +[classref boost::intrusive::multiset multiset] and the latter is a generalization +that offers functions both to insert unique and multiple keys. +The memory overhead of these containers with Boost.Intrusive hooks is 3 +pointers. +An empty, [classref boost::intrusive::treap_set treap_set], +[classref boost::intrusive::treap_multiset treap_multiset] or +[classref boost::intrusive::treap treap] +has also the size of 3 pointers and an integer (supposing empty function objects for key and priority +comparison and constant-time size). +[section:treap_set_multiset_hooks Using binary search tree hooks: bs_set_base_hook and bs_set_member_hook] +[classref boost::intrusive::treap_set treap_set], +[classref boost::intrusive::treap_multiset treap_multiset] and +[classref boost::intrusive::treap treap] don't use their +own hooks but plain binary search tree hooks. This has many advantages +since binary search tree hooks can also be used to insert values in +splay containers and scapegoat trees. +[c++] + template + class bs_set_base_hook; +* [classref boost::intrusive::bs_set_base_hook bs_set_base_hook]: + the user class derives publicly from this class to make + it compatible with scapegoat tree based containers. +[c++] + template + class bs_set_member_hook; +* [classref boost::intrusive::set_member_hook set_member_hook]: + the user class contains a public member of this class to make + it compatible with scapegoat tree based containers. +[classref boost::intrusive::bs_set_base_hook bs_set_base_hook] and +[classref boost::intrusive::bs_set_member_hook bs_set_member_hook] receive +the same options explained in the section +[link intrusive.usage How to use Boost.Intrusive]: + +* [*`tag`] (for base hooks only): This argument serves as a tag, + so you can derive from more than one base hook. + Default: `tag`. + +* [*`link_mode`]: The linking policy. + Default: `link_mode`. + +* [*`void_pointer`]: The pointer type to be used + internally in the hook and propagated to the container. + Default: `void_pointer`. + +[endsect] + +[section:treap_set_multiset_containers treap_set, treap_multiset and treap containers] + +[c++] + + template + class treap_set; + + template + class treap_multiset; + + template + class treap; + +These containers receive the same options explained in the section +[link intrusive.usage How to use Boost.Intrusive]: + +* [*`base_hook`] / [*`member_hook`] / + [*`value_traits`]: To specify the hook type or value traits used + to configure the container. (To learn about value traits go to the section + [link intrusive.value_traits Containers with custom ValueTraits].) + +* [*`constant_time_size`]: To activate the constant-time `size()` operation. + Default: `constant_time_size` + +* [*`size_type`]: To specify the type that will be used to store the size + of the container. Default: `size_type` + +And they also can receive additional options: + +* [*`compare`]: Comparison function for the objects to be inserted + in containers. The comparison functor must induce a strict weak ordering. + Default: `compare< std::less >` + +* [*`priority`]: Priority Comparison function for the objects to be inserted + in containers. The comparison functor must induce a strict weak ordering. + Default: `priority< priority_compare >` + +The default `priority_compare` object function will call an unqualified function `priority_order` +passing two constant `T` references as arguments and should return true if the first argument has +higher priority (it will be searched faster), inducing strict weak ordering. +The function will be found using ADL lookup so that +the user just needs to define a `priority_order` function in the same namespace as his class: + +[c++] + + struct MyType + { + friend bool priority_order(const MyType &a, const MyType &b) + {...} + }; + +or + + namespace mytype { + + struct MyType{ ... }; + + bool priority_order(const MyType &a, const MyType &b) + {...} + + } //namespace mytype { + +[endsect] + +[section:treap_set_exceptions Exception safety of treap-based intrusive containers] + +In general, intrusive containers offer strong safety guarantees, but treap containers must deal +with two possibly throwing functors (one for value ordering, another for priority ordering). +Moreover, treap erasure operations require rotations based on the priority order function and +this issue degrades usual `erase(const_iterator)` no-throw guarantee. However, intrusive offers +the strongest possible behaviour in these situations. In summary: + +* If the priority order functor does not throw, treap-based containers, offer exactly the same + guarantees as other tree-based containers. + +* If the priority order functor throws, treap-based containers offer strong guarantee. + +[endsect] + +[section:treap_set_multiset_example Example] + +Now let's see a small example using both hooks and +[classref boost::intrusive::treap_set treap_set]/ +[classref boost::intrusive::treap_multiset treap_multiset] +containers: + +[import ../example/doc_treap_set.cpp] +[doc_treap_set_code] + +[endsect] + +[endsect] [section:advanced_lookups_insertions Advanced lookup and insertion functions for associative containers] @@ -2643,6 +2800,62 @@ For a complete list of functions see [endsect] + +[section:treap_algorithms Intrusive treap algorithms] + +[classref boost::intrusive::treap_algorithms treap_algorithms] have the same +interface as [classref boost::intrusive::rbtree_algorithms rbtree_algorithms]. + +[c++] + + template + struct treap_algorithms; + +[classref boost::intrusive::treap_algorithms treap_algorithms] +is configured with a NodeTraits class, which encapsulates +the information about the node to be manipulated. NodeTraits must support the +following interface: + +[*Typedefs]: + +* `node`: The type of the node that forms the circular treap + +* `node_ptr`: The type of a pointer to a node (usually node*) + +* `const_node_ptr`: The type of a pointer to a const node (usually const node*) + +[*Static functions]: + +* `static node_ptr get_parent(const_node_ptr n);`: + Returns a pointer to the parent node stored in "n". + +* `static void set_parent(node_ptr n, node_ptr p);`: + Sets the pointer to the parent node stored in "n" to "p". + +* `static node_ptr get_left(const_node_ptr n);`: + Returns a pointer to the left node stored in "n". + +* `static void set_left(node_ptr n, node_ptr l);`: + Sets the pointer to the left node stored in "n" to "l". + +* `static node_ptr get_right(const_node_ptr n);`: + Returns a pointer to the right node stored in "n". + +* `static void set_right(node_ptr n, node_ptr r);`: + Sets the pointer to the right node stored in "n" to "r". + +Once we have a node traits configuration we can use [*Boost.Intrusive] algorithms +with our nodes: + +[import ../example/doc_treap_algorithms.cpp] +[doc_treap_algorithms_code] + +For a complete list of functions see +[classref boost::intrusive::treap_algorithms treap_algorithms reference]. + +[endsect] + + [/ / /[section:sgtree_algorithms Intrusive sg tree algorithms] @@ -3488,6 +3701,15 @@ all the objects to be inserted in intrusive containers in containers like `std:: [section:release_notes Release Notes] +[section:release_notes_boost_1_38_00 Boost 1.38 Release] + +* 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. + +[endsect] + [section:release_notes_boost_1_37_00 Boost 1.37 Release] * Intrusive now takes advantage of compilers with variadic templates. @@ -3577,7 +3799,7 @@ helpful discussions. [endsect] -[xinclude autodoc.xml] +[/xinclude autodoc.xml] [section:license_notices License notices] diff --git a/example/doc_advanced_value_traits.cpp b/example/doc_advanced_value_traits.cpp index f4caafb..dca6585 100644 --- a/example/doc_advanced_value_traits.cpp +++ b/example/doc_advanced_value_traits.cpp @@ -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 diff --git a/example/doc_advanced_value_traits2.cpp b/example/doc_advanced_value_traits2.cpp index 6367af0..ec9214e 100644 --- a/example/doc_advanced_value_traits2.cpp +++ b/example/doc_advanced_value_traits2.cpp @@ -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 diff --git a/example/doc_assoc_optimized_code.cpp b/example/doc_assoc_optimized_code.cpp index 8af780c..7b86a70 100644 --- a/example/doc_assoc_optimized_code.cpp +++ b/example/doc_assoc_optimized_code.cpp @@ -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 diff --git a/example/doc_auto_unlink.cpp b/example/doc_auto_unlink.cpp index 848b973..208fc6f 100644 --- a/example/doc_auto_unlink.cpp +++ b/example/doc_auto_unlink.cpp @@ -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 diff --git a/example/doc_avl_set.cpp b/example/doc_avl_set.cpp index 33a061c..32d339b 100644 --- a/example/doc_avl_set.cpp +++ b/example/doc_avl_set.cpp @@ -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 diff --git a/example/doc_avltree_algorithms.cpp b/example/doc_avltree_algorithms.cpp index 9aa47b2..ee2655c 100644 --- a/example/doc_avltree_algorithms.cpp +++ b/example/doc_avltree_algorithms.cpp @@ -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_; } }; diff --git a/example/doc_bucket_traits.cpp b/example/doc_bucket_traits.cpp index c03c125..7663bf4 100644 --- a/example/doc_bucket_traits.cpp +++ b/example/doc_bucket_traits.cpp @@ -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 diff --git a/example/doc_clone_from.cpp b/example/doc_clone_from.cpp index 94c0668..ae3d8c9 100644 --- a/example/doc_clone_from.cpp +++ b/example/doc_clone_from.cpp @@ -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 diff --git a/example/doc_entity.cpp b/example/doc_entity.cpp index 0e2fc54..70b109f 100644 --- a/example/doc_entity.cpp +++ b/example/doc_entity.cpp @@ -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 diff --git a/example/doc_erasing_and_disposing.cpp b/example/doc_erasing_and_disposing.cpp index 51d737f..cf0062d 100644 --- a/example/doc_erasing_and_disposing.cpp +++ b/example/doc_erasing_and_disposing.cpp @@ -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 diff --git a/example/doc_external_value_traits.cpp b/example/doc_external_value_traits.cpp index 80d366e..b53817c 100644 --- a/example/doc_external_value_traits.cpp +++ b/example/doc_external_value_traits.cpp @@ -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 diff --git a/example/doc_how_to_use.cpp b/example/doc_how_to_use.cpp index 8284bd0..2951096 100644 --- a/example/doc_how_to_use.cpp +++ b/example/doc_how_to_use.cpp @@ -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 diff --git a/example/doc_iterator_from_value.cpp b/example/doc_iterator_from_value.cpp index b212a49..875db31 100644 --- a/example/doc_iterator_from_value.cpp +++ b/example/doc_iterator_from_value.cpp @@ -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 diff --git a/example/doc_list.cpp b/example/doc_list.cpp index 7137fcc..a4ffcee 100644 --- a/example/doc_list.cpp +++ b/example/doc_list.cpp @@ -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 diff --git a/example/doc_list_algorithms.cpp b/example/doc_list_algorithms.cpp index 7b4fc89..c5ef4b4 100644 --- a/example/doc_list_algorithms.cpp +++ b/example/doc_list_algorithms.cpp @@ -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 diff --git a/example/doc_offset_ptr.cpp b/example/doc_offset_ptr.cpp index 1d7e87e..9b88708 100644 --- a/example/doc_offset_ptr.cpp +++ b/example/doc_offset_ptr.cpp @@ -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 diff --git a/example/doc_rbtree_algorithms.cpp b/example/doc_rbtree_algorithms.cpp index 6eb25fb..0843365 100644 --- a/example/doc_rbtree_algorithms.cpp +++ b/example/doc_rbtree_algorithms.cpp @@ -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_; } }; diff --git a/example/doc_set.cpp b/example/doc_set.cpp index d9d5d47..c996038 100644 --- a/example/doc_set.cpp +++ b/example/doc_set.cpp @@ -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 diff --git a/example/doc_sg_set.cpp b/example/doc_sg_set.cpp index 2c6eec5..aa33258 100644 --- a/example/doc_sg_set.cpp +++ b/example/doc_sg_set.cpp @@ -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 diff --git a/example/doc_slist.cpp b/example/doc_slist.cpp index f8164bd..42220b9 100644 --- a/example/doc_slist.cpp +++ b/example/doc_slist.cpp @@ -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 diff --git a/example/doc_slist_algorithms.cpp b/example/doc_slist_algorithms.cpp index d89b678..7e7f155 100644 --- a/example/doc_slist_algorithms.cpp +++ b/example/doc_slist_algorithms.cpp @@ -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 diff --git a/example/doc_splay_algorithms.cpp b/example/doc_splay_algorithms.cpp index 80797db..f90a7e2 100644 --- a/example/doc_splay_algorithms.cpp +++ b/example/doc_splay_algorithms.cpp @@ -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_; } }; diff --git a/example/doc_splay_set.cpp b/example/doc_splay_set.cpp index b82f48a..8859165 100644 --- a/example/doc_splay_set.cpp +++ b/example/doc_splay_set.cpp @@ -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 diff --git a/example/doc_splaytree_algorithms.cpp b/example/doc_splaytree_algorithms.cpp index f6c7f6f..aeafaae 100644 --- a/example/doc_splaytree_algorithms.cpp +++ b/example/doc_splaytree_algorithms.cpp @@ -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_; } }; diff --git a/example/doc_stateful_value_traits.cpp b/example/doc_stateful_value_traits.cpp index 96d16f3..4712387 100644 --- a/example/doc_stateful_value_traits.cpp +++ b/example/doc_stateful_value_traits.cpp @@ -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 diff --git a/example/doc_treap_algorithms.cpp b/example/doc_treap_algorithms.cpp new file mode 100644 index 0000000..773aa69 --- /dev/null +++ b/example/doc_treap_algorithms.cpp @@ -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 +#include + +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 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; +} + +//] diff --git a/example/doc_treap_set.cpp b/example/doc_treap_set.cpp new file mode 100644 index 0000000..7ae4fec --- /dev/null +++ b/example/doc_treap_set.cpp @@ -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 +#include +#include +#include + +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 > > BaseSet; + +//Define an multiset using the member hook that will store +typedef member_hook, &MyClass::member_hook_> MemberOption; +typedef treap_multiset + < MyClass, MemberOption, priority > MemberMultiset; + +int main() +{ + typedef std::vector::iterator VectIt; + + //Create several MyClass objects, each one with a different value + std::vector 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(i/10)) + return 1; + if(membermultiset.top()->get_priority() != 9u - static_cast(i/10)) + return 1; + baseset.erase(baseset.top()); + membermultiset.erase(membermultiset.top()); + } + } + return 0; +} +//] diff --git a/example/doc_unordered_set.cpp b/example/doc_unordered_set.cpp index 531ef10..a007919 100644 --- a/example/doc_unordered_set.cpp +++ b/example/doc_unordered_set.cpp @@ -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 diff --git a/example/doc_value_traits.cpp b/example/doc_value_traits.cpp index e50e23b..f9bb897 100644 --- a/example/doc_value_traits.cpp +++ b/example/doc_value_traits.cpp @@ -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 diff --git a/example/doc_window.cpp b/example/doc_window.cpp index 7a0e12d..f00f43b 100644 --- a/example/doc_window.cpp +++ b/example/doc_window.cpp @@ -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 diff --git a/perf/perf_list.cpp b/perf/perf_list.cpp index 5bf8012..ef73947 100644 --- a/perf/perf_list.cpp +++ b/perf/perf_list.cpp @@ -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 @@ -11,6 +11,7 @@ ///////////////////////////////////////////////////////////////////////////// //Includes for tests +#include #include #include #include @@ -545,3 +546,5 @@ int main() do_all_tests(); return 0; } + +#include diff --git a/proj/vc7ide/Intrusive.sln b/proj/vc7ide/Intrusive.sln index 0b105c0..4726fdc 100644 --- a/proj/vc7ide/Intrusive.sln +++ b/proj/vc7ide/Intrusive.sln @@ -83,6 +83,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "any_hook", "any_test\any_te ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "treap_set", "treap_set\treap_set.vcproj", "{1E09E697-4A2F-BC76-7C91-2BA479B29159}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "treap_multiset", "treap_multiset\treap_multiset.vcproj", "{16E09E95-F4A2-C971-BC76-9BA407191C59}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -175,6 +183,14 @@ Global {97B61B24-4C97-9681-50BF-243175A813B6}.Debug.Build.0 = Debug|Win32 {97B61B24-4C97-9681-50BF-243175A813B6}.Release.ActiveCfg = Release|Win32 {97B61B24-4C97-9681-50BF-243175A813B6}.Release.Build.0 = Release|Win32 + {1E09E697-4A2F-BC76-7C91-2BA479B29159}.Debug.ActiveCfg = Debug|Win32 + {1E09E697-4A2F-BC76-7C91-2BA479B29159}.Debug.Build.0 = Debug|Win32 + {1E09E697-4A2F-BC76-7C91-2BA479B29159}.Release.ActiveCfg = Release|Win32 + {1E09E697-4A2F-BC76-7C91-2BA479B29159}.Release.Build.0 = Release|Win32 + {16E09E95-F4A2-C971-BC76-9BA407191C59}.Debug.ActiveCfg = Debug|Win32 + {16E09E95-F4A2-C971-BC76-9BA407191C59}.Debug.Build.0 = Debug|Win32 + {16E09E95-F4A2-C971-BC76-9BA407191C59}.Release.ActiveCfg = Release|Win32 + {16E09E95-F4A2-C971-BC76-9BA407191C59}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj index c5a1d2e..abe74de 100644 --- a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj +++ b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj @@ -198,6 +198,15 @@ + + + + + + @@ -219,6 +228,9 @@ + + @@ -397,6 +409,12 @@ + + + + diff --git a/proj/vc7ide/to-do.txt b/proj/vc7ide/to-do.txt index 1874bf6..f62414d 100644 --- a/proj/vc7ide/to-do.txt +++ b/proj/vc7ide/to-do.txt @@ -1,3 +1,26 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (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. +// +///////////////////////////////////////////////////////////////////////////// -> Implement C++0x features (variadic templates & rvalue references) -> Offer bidirectional iterator for hashtables -> Non-array buckets +-> Document incremental<> option better + +-> Revise treap's hooks should be restored if the operation throws +-> Revise treap help to add priority changes (throw, new functions, etc.) +-> Revise make_functions, and any hook tests to add missing containers +-> On exceptions, auto_unlink/safe_link hooks default state should be recovered + (insert_equal, insert_lower_bound, insert_equal_upper_bound) +-> insert_unique_check should also compare priorities. +-> test insert_unique_check with hint in tests +-> revise strong exception safety concepts for treap::erase functions. + What happens with range deletions? +-> Assure stable order for optimize_multikey and inverse order otherwise diff --git a/proj/vc7ide/treap_multiset/treap_multiset.vcproj b/proj/vc7ide/treap_multiset/treap_multiset.vcproj new file mode 100644 index 0000000..b0b1edd --- /dev/null +++ b/proj/vc7ide/treap_multiset/treap_multiset.vcproj @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/proj/vc7ide/treap_set/treap_set.vcproj b/proj/vc7ide/treap_set/treap_set.vcproj new file mode 100644 index 0000000..a6d68a3 --- /dev/null +++ b/proj/vc7ide/treap_set/treap_set.vcproj @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/any_test.cpp b/test/any_test.cpp index 9c24c56..bd2c955 100644 --- a/test/any_test.cpp +++ b/test/any_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include //std::vector @@ -48,8 +49,12 @@ class MyClass : public any_base_hook<> friend std::size_t hash_value(const MyClass &o) { return boost::hash()(o.get()); } + + friend bool priority_order(const MyClass &a, const MyClass &b) + { return a.int_ < b.int_; } }; + void instantiation_test() { typedef member_hook< MyClass, any_member_hook<>, &MyClass::member_hook_> MemberHook; @@ -96,6 +101,14 @@ void instantiation_test() sgtree < MyClass, any_to_bs_set_hook< MemberHook > > sgtree_member; sgtree_member.insert_unique(myclass); } + { + treap < MyClass, any_to_bs_set_hook< BaseHook > > treap_base; + treap_base.insert_unique(myclass); + } + { + treap < MyClass, any_to_bs_set_hook< MemberHook > > treap_member; + treap_member.insert_unique(myclass); + } { splaytree < MyClass, any_to_bs_set_hook< BaseHook > > splaytree_base; splaytree_base.insert_unique(myclass); diff --git a/test/avl_multiset_test.cpp b/test/avl_multiset_test.cpp index dcaf774..bc8c7eb 100644 --- a/test/avl_multiset_test.cpp +++ b/test/avl_multiset_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -17,6 +17,26 @@ #include "smart_ptr.hpp" #include "generic_multiset_test.hpp" +using namespace boost::intrusive; + +struct my_tag; + +template +struct hooks +{ + typedef avl_set_base_hook > base_hook_type; + typedef avl_set_base_hook + + , void_pointer + , tag + , optimize_size > auto_base_hook_type; + typedef avl_set_member_hook + > member_hook_type; + typedef avl_set_member_hook + < link_mode + , void_pointer > auto_member_hook_type; +}; + template< class ValueType , class Option1 = boost::intrusive::none , class Option2 = boost::intrusive::none @@ -39,19 +59,19 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::avl_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::avl_set_member_hook_t - , &value_type::avl_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -67,11 +87,11 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , false> value_type; test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::avl_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); @@ -79,8 +99,8 @@ class test_main_template test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::avl_set_member_hook_t - , &value_type::avl_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -88,7 +108,7 @@ class test_main_template test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::avl_set_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , GetContainer >::test_all(); @@ -96,8 +116,8 @@ class test_main_template test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::avl_set_auto_member_hook_t - , &value_type::avl_set_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , GetContainer diff --git a/test/avl_set_test.cpp b/test/avl_set_test.cpp index d53b56e..55e415c 100644 --- a/test/avl_set_test.cpp +++ b/test/avl_set_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -16,6 +16,26 @@ #include "smart_ptr.hpp" #include "generic_set_test.hpp" +using namespace boost::intrusive; + +struct my_tag; + +template +struct hooks +{ + typedef avl_set_base_hook > base_hook_type; + typedef avl_set_base_hook + + , void_pointer + , tag + , optimize_size > auto_base_hook_type; + typedef avl_set_member_hook + > member_hook_type; + typedef avl_set_member_hook + < link_mode + , void_pointer > auto_member_hook_type; +}; + template< class ValueType , class Option1 = boost::intrusive::none , class Option2 = boost::intrusive::none @@ -38,19 +58,19 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::avl_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::avl_set_member_hook_t - , &value_type::avl_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -66,11 +86,11 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , false> value_type; test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::avl_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); @@ -78,8 +98,8 @@ class test_main_template test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::avl_set_member_hook_t - , &value_type::avl_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -87,7 +107,7 @@ class test_main_template test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::avl_set_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , GetContainer >::test_all(); @@ -95,8 +115,8 @@ class test_main_template test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::avl_set_auto_member_hook_t - , &value_type::avl_set_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , GetContainer diff --git a/test/common_functors.hpp b/test/common_functors.hpp index d3bc3fa..db52197 100644 --- a/test/common_functors.hpp +++ b/test/common_functors.hpp @@ -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 diff --git a/test/custom_bucket_traits_test.cpp b/test/custom_bucket_traits_test.cpp index 7539b9c..a74eb0b 100644 --- a/test/custom_bucket_traits_test.cpp +++ b/test/custom_bucket_traits_test.cpp @@ -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 diff --git a/test/default_hook_test.cpp b/test/default_hook_test.cpp index 90f664d..55c31a2 100644 --- a/test/default_hook_test.cpp +++ b/test/default_hook_test.cpp @@ -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 diff --git a/test/external_value_traits_test.cpp b/test/external_value_traits_test.cpp index fa380e2..ec70f13 100644 --- a/test/external_value_traits_test.cpp +++ b/test/external_value_traits_test.cpp @@ -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 diff --git a/test/generic_assoc_test.hpp b/test/generic_assoc_test.hpp index 5ee4720..9f39ff7 100644 --- a/test/generic_assoc_test.hpp +++ b/test/generic_assoc_test.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -117,16 +117,27 @@ void test_generic_assoc::test_insert_erase_burst( //Now random insertions std::random_shuffle(values.begin(), values.end()); testset.insert(&values[0], &values[0] + values.size()); - std::sort(values.begin(), values.end()); + std::vector values_ordered(values); + std::sort(values_ordered.begin(), values_ordered.end()); TEST_INTRUSIVE_SEQUENCE_EXPECTED(testset, testset.begin()); - //Random erasure - std::random_shuffle(values.begin(), values.end()); - for(int i = 0; i != MaxValues; ++i){ - it = testset.erase(testset.iterator_to(values[i])); - } + { + typedef typename std::vector::const_iterator cvec_iterator; + //Random erasure + std::vector it_vector; + + for(cvec_iterator it(values.begin()), itend(values.end()) + ; it != itend + ; ++it){ + it_vector.push_back(it); + } + std::random_shuffle(it_vector.begin(), it_vector.end()); + for(int i = 0; i != MaxValues; ++i){ + testset.erase(testset.iterator_to(*it_vector[i])); + } - BOOST_TEST(testset.empty()); + BOOST_TEST(testset.empty()); + } } template class ContainerDefiner> diff --git a/test/generic_multiset_test.hpp b/test/generic_multiset_test.hpp index 0df4e72..21aeb3c 100644 --- a/test/generic_multiset_test.hpp +++ b/test/generic_multiset_test.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 diff --git a/test/generic_set_test.hpp b/test/generic_set_test.hpp index 0498759..5df2489 100644 --- a/test/generic_set_test.hpp +++ b/test/generic_set_test.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 diff --git a/test/itestvalue.hpp b/test/itestvalue.hpp index 4fd6750..a2885db 100644 --- a/test/itestvalue.hpp +++ b/test/itestvalue.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -14,220 +14,25 @@ #define BOOST_INTRUSIVE_DETAIL_ITESTVALUE_HPP #include -#include -#include -#include -#include -#include -#include -#include #include #include -#include "smart_ptr.hpp" namespace boost{ namespace intrusive{ -struct my_tag; - -template -struct set_base_hook_type -{ typedef set_base_hook > type; }; - -template -struct set_auto_base_hook_type -{ typedef set_base_hook, void_pointer, tag, optimize_size > type; }; - -template -struct set_member_hook_type -{ typedef set_member_hook, optimize_size > type; }; - -template -struct set_auto_member_hook_type -{ typedef set_member_hook, void_pointer > type; }; - -template -struct splay_set_base_hook_type -{ typedef splay_set_base_hook > type; }; - -template -struct splay_set_auto_base_hook_type -{ typedef splay_set_base_hook, void_pointer, tag > type; }; - -template -struct splay_set_member_hook_type -{ typedef splay_set_member_hook > type; }; - -template -struct splay_set_auto_member_hook_type -{ typedef splay_set_member_hook, void_pointer > type; }; - -template -struct bs_set_base_hook_type -{ typedef bs_set_base_hook > type; }; - -template -struct bs_set_member_hook_type -{ typedef bs_set_member_hook > type; }; - -template -struct avl_set_base_hook_type -{ typedef avl_set_base_hook > type; }; - -template -struct avl_set_auto_base_hook_type -{ typedef avl_set_base_hook, void_pointer, tag, optimize_size > type; }; - -template -struct avl_set_member_hook_type -{ typedef avl_set_member_hook, optimize_size > type; }; - -template -struct avl_set_auto_member_hook_type -{ typedef avl_set_member_hook, void_pointer > type; }; - -template -struct list_base_hook_type -{ typedef list_base_hook > type; }; - -template -struct list_auto_base_hook_type -{ typedef list_base_hook, void_pointer, tag > type; }; - -template -struct list_member_hook_type -{ typedef list_member_hook > type; }; - -template -struct list_auto_member_hook_type -{ typedef list_member_hook, void_pointer > type; }; - -template -struct slist_base_hook_type -{ typedef slist_base_hook > type; }; - -template -struct slist_auto_base_hook_type -{ typedef slist_base_hook, void_pointer, tag > type; }; - -template -struct slist_member_hook_type -{ typedef slist_member_hook > type; }; - -template -struct slist_auto_member_hook_type -{ typedef slist_member_hook, void_pointer > type; }; - -template -struct uset_base_hook_type -{ typedef unordered_set_base_hook > type; }; - -template -struct uset_auto_base_hook_type +struct testvalue_filler { - typedef unordered_set_base_hook - < link_mode - , void_pointer - , tag - , store_hash - > type; + void *dummy_[3]; }; -template -struct uset_member_hook_type -{ - typedef unordered_set_member_hook - < void_pointer - , optimize_multikey - > type; -}; - -template -struct uset_auto_member_hook_type -{ - typedef unordered_set_member_hook - < link_mode, void_pointer - , store_hash - , optimize_multikey - > type; -}; - -template +template struct testvalue - : set_base_hook_type::type - , set_auto_base_hook_type::type - , splay_set_base_hook_type::type - , splay_set_auto_base_hook_type::type - , bs_set_base_hook_type::type - , avl_set_base_hook_type::type - , avl_set_auto_base_hook_type::type - , list_base_hook_type::type - , list_auto_base_hook_type::type - , slist_base_hook_type::type - , slist_auto_base_hook_type::type - , uset_base_hook_type::type - , uset_auto_base_hook_type::type + : testvalue_filler + , Hooks::base_hook_type + , Hooks::auto_base_hook_type { - typedef typename set_auto_base_hook_type::type set_auto_base_hook_t; - typedef typename set_base_hook_type::type set_base_hook_t; - typedef typename set_auto_member_hook_type::type set_auto_member_hook_t; - typedef typename set_member_hook_type::type set_member_hook_t; - - typedef typename splay_set_auto_base_hook_type::type splay_set_auto_base_hook_t; - typedef typename splay_set_base_hook_type::type splay_set_base_hook_t; - typedef typename splay_set_auto_member_hook_type::type splay_set_auto_member_hook_t; - typedef typename splay_set_member_hook_type::type splay_set_member_hook_t; - - typedef typename bs_set_base_hook_type::type bs_set_base_hook_t; - typedef typename bs_set_member_hook_type::type bs_set_member_hook_t; - - typedef typename avl_set_auto_base_hook_type::type avl_set_auto_base_hook_t; - typedef typename avl_set_base_hook_type::type avl_set_base_hook_t; - typedef typename avl_set_auto_member_hook_type::type avl_set_auto_member_hook_t; - typedef typename avl_set_member_hook_type::type avl_set_member_hook_t; - - typedef typename uset_auto_base_hook_type::type unordered_set_auto_base_hook_t; - typedef typename uset_base_hook_type::type unordered_set_base_hook_t; - typedef typename uset_auto_member_hook_type::type unordered_set_auto_member_hook_t; - typedef typename uset_member_hook_type::type unordered_set_member_hook_t; - - typedef typename list_auto_base_hook_type::type list_auto_base_hook_t; - typedef typename list_base_hook_type::type list_base_hook_t; - typedef typename list_auto_member_hook_type::type list_auto_member_hook_t; - typedef typename list_member_hook_type::type list_member_hook_t; - - typedef typename slist_auto_base_hook_type::type slist_auto_base_hook_t; - typedef typename slist_base_hook_type::type slist_base_hook_t; - typedef typename slist_auto_member_hook_type::type slist_auto_member_hook_t; - typedef typename slist_member_hook_type::type slist_member_hook_t; - - //Set members - set_member_hook_t set_node_; - set_auto_member_hook_t set_auto_node_; - - //SplaySet members - splay_set_member_hook_t splay_set_node_; - splay_set_auto_member_hook_t splay_set_auto_node_; - - //ScapegoatSet members - bs_set_member_hook_t sg_set_node_; - - //AvlSet members - avl_set_member_hook_t avl_set_node_; - avl_set_auto_member_hook_t avl_set_auto_node_; - - //Unordered set members - unordered_set_member_hook_t unordered_set_node_; - unordered_set_auto_member_hook_t unordered_set_auto_node_; - - //List members - list_member_hook_t list_node_; - list_auto_member_hook_t list_auto_node_; - - //Slist members - slist_member_hook_t slist_node_; - slist_auto_member_hook_t slist_auto_node_; - + typename Hooks::member_hook_type node_; + typename Hooks::auto_member_hook_type auto_node_; int value_; static const bool constant_time_size = ConstantTimeSize; @@ -245,130 +50,30 @@ struct testvalue // testvalue is used in std::vector and thus prev and next // have to be handled appropriately when copied: - testvalue & operator= (const testvalue& src) - {/* - set_base_hook_t::operator=(src); - set_auto_base_hook_t::operator=(src); - this->set_node_ = src.set_node_; - this->set_auto_node_ = src.set_auto_node_; - - splay_set_base_hook_t::operator=(src); - splay_set_auto_base_hook_t::operator=(src); - this->splay_set_node_ = src.splay_set_node_; - this->splay_set_auto_node_ = src.splay_set_auto_node_; - - bs_set_base_hook_t::operator=(src); - this->sg_set_node_ = src.sg_set_node_; - - avl_set_base_hook_t::operator=(src); - avl_set_auto_base_hook_t::operator=(src); - this->avl_set_node_ = src.avl_set_node_; - this->avl_set_auto_node_ = src.avl_set_auto_node_; - - unordered_set_base_hook_t::operator=(src); - unordered_set_auto_base_hook_t::operator=(src); - this->unordered_set_node_ = src.unordered_set_node_; - this->unordered_set_auto_node_ = src.unordered_set_auto_node_; - - list_base_hook_t::operator=(src); - list_auto_base_hook_t::operator=(src); - this->list_node_ = src.list_node_; - this->list_auto_node_ = src.list_auto_node_; - - slist_base_hook_t::operator=(src); - slist_auto_base_hook_t::operator=(src); - this->slist_node_ = src.slist_node_; - this->slist_auto_node_ = src.slist_auto_node_; -*/ + { + Hooks::base_hook_type::operator=(src); + Hooks::auto_base_hook_type::operator=(src); + this->node_ = src.node_; + this->auto_node_ = src.auto_node_; value_ = src.value_; return *this; } void swap_nodes(testvalue &other) { - //Set - set_base_hook_t::swap_nodes(other); - set_auto_base_hook_t::swap_nodes(other); - set_node_.swap_nodes(other.set_node_); - set_auto_node_.swap_nodes(other.set_auto_node_); - - //SplaySet - splay_set_base_hook_t::swap_nodes(other); - splay_set_auto_base_hook_t::swap_nodes(other); - splay_set_node_.swap_nodes(other.splay_set_node_); - splay_set_auto_node_.swap_nodes(other.splay_set_auto_node_); - - //ScapeoatSet - bs_set_base_hook_t::swap_nodes(other); - sg_set_node_.swap_nodes(other.sg_set_node_); - - //AvlSet - avl_set_base_hook_t::swap_nodes(other); - avl_set_auto_base_hook_t::swap_nodes(other); - avl_set_node_.swap_nodes(other.avl_set_node_); - avl_set_auto_node_.swap_nodes(other.avl_set_auto_node_); - - //Unordered set - unordered_set_base_hook_t::swap_nodes(other); - unordered_set_auto_base_hook_t::swap_nodes(other); - unordered_set_node_.swap_nodes(other.unordered_set_node_); - unordered_set_auto_node_.swap_nodes(other.unordered_set_auto_node_); - - //List - list_base_hook_t::swap_nodes(other); - list_auto_base_hook_t::swap_nodes(other); - list_node_.swap_nodes(other.list_node_); - list_auto_node_.swap_nodes(other.list_auto_node_); - - //Slist - slist_base_hook_t::swap_nodes(other); - slist_auto_base_hook_t::swap_nodes(other); - slist_node_.swap_nodes(other.slist_node_); - slist_auto_node_.swap_nodes(other.slist_auto_node_); + Hooks::base_hook_type::swap_nodes(other); + Hooks::auto_base_hook_type::swap_nodes(other); + node_.swap_nodes(other.node_); + auto_node_.swap_nodes(other.auto_node_); } bool is_linked() const { - //Set - return set_base_hook_t::is_linked() || - set_auto_base_hook_t::is_linked() || - set_node_.is_linked() || - set_auto_node_.is_linked() || - - //SplaySet - splay_set_base_hook_t::is_linked() || - splay_set_auto_base_hook_t::is_linked() || - splay_set_node_.is_linked() || - splay_set_auto_node_.is_linked() || - - //ScapeoatSet - bs_set_base_hook_t::is_linked() || - sg_set_node_.is_linked() || - - //AvlSet - avl_set_base_hook_t::is_linked() || - avl_set_auto_base_hook_t::is_linked() || - avl_set_node_.is_linked() || - avl_set_auto_node_.is_linked() || - - //Unordered set - unordered_set_base_hook_t::is_linked() || - unordered_set_auto_base_hook_t::is_linked() || - unordered_set_node_.is_linked() || - unordered_set_auto_node_.is_linked() || - - //List - list_base_hook_t::is_linked() || - list_auto_base_hook_t::is_linked() || - list_node_.is_linked() || - list_auto_node_.is_linked() || - - //Slist - slist_base_hook_t::is_linked() || - slist_auto_base_hook_t::is_linked() || - slist_node_.is_linked() || - slist_auto_node_.is_linked(); + return Hooks::base_hook_type::is_linked() || + Hooks::auto_base_hook_type::is_linked() || + node_.is_linked() || + auto_node_.is_linked(); } ~testvalue() @@ -402,24 +107,34 @@ struct testvalue { return other1.value_ != other2; } }; -template -std::size_t hash_value(const testvalue &t) +template +std::size_t hash_value(const testvalue &t) { boost::hash hasher; return hasher(t.value_); } -template +template +bool priority_order(const testvalue &t1, const testvalue &t2) +{ + std::size_t hash1 = hash_value(t1); + boost::hash_combine(hash1,&t1); + std::size_t hash2 = hash_value(t2); + boost::hash_combine(hash2,&t2); + return hash1 < hash2; +} + +template std::ostream& operator<< - (std::ostream& s, const testvalue& t) + (std::ostream& s, const testvalue& t) { return s << t.value_; } struct even_odd { - template + template bool operator() - (const testvalue& v1 - ,const testvalue& v2) const + (const testvalue& v1 + ,const testvalue& v2) const { if ((v1.value_ & 1) == (v2.value_ & 1)) return v1.value_ < v2.value_; @@ -430,9 +145,9 @@ struct even_odd struct is_even { - template + template bool operator() - (const testvalue& v1) const + (const testvalue& v1) const { return (v1.value_ & 1) == 0; } }; diff --git a/test/list_test.cpp b/test/list_test.cpp index 65cfa8b..8e67f8b 100644 --- a/test/list_test.cpp +++ b/test/list_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -25,6 +25,19 @@ using namespace boost::intrusive; +class my_tag; + +template +struct hooks +{ + typedef list_base_hook > base_hook_type; + typedef list_base_hook< link_mode + , void_pointer, tag > auto_base_hook_type; + typedef list_member_hook, tag > member_hook_type; + typedef list_member_hook< link_mode + , void_pointer > auto_member_hook_type; +}; + template struct test_list { @@ -400,21 +413,21 @@ class test_main_template public: int operator()() { - typedef testvalue value_type; + typedef testvalue, constant_time_size> value_type; std::vector data (5); for (int i = 0; i < 5; ++i) data[i].value_ = i + 1; test_list < typename detail::get_base_value_traits < value_type - , typename value_type::list_base_hook_t + , typename hooks::base_hook_type >::type >::test_all(data); test_list < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::list_member_hook_t - , &value_type::list_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type >::test_all(data); @@ -428,22 +441,22 @@ class test_main_template public: int operator()() { - typedef testvalue value_type; + typedef testvalue, false> value_type; std::vector data (5); for (int i = 0; i < 5; ++i) data[i].value_ = i + 1; test_list < typename detail::get_base_value_traits < value_type - , typename value_type::list_base_hook_t + , typename hooks::base_hook_type >::type >::test_all(data); test_list < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::list_member_hook_t - , &value_type::list_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type >::test_all(data); @@ -455,15 +468,15 @@ class test_main_template // >::test_all(data); test_list < typename detail::get_base_value_traits < value_type - , typename value_type::list_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type >::test_all(data); test_list < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::list_auto_member_hook_t - , &value_type::list_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type >::test_all(data); @@ -488,285 +501,3 @@ int main( int, char* [] ) return boost::report_errors(); } #include - - - - - - - - - - - - - -/* -#include - - -//////////////////////////////////////////////////// -// Builds an index_tuple<0, 1, 2, ..., Num-1>, that will -// be used to "unpack" into comma-separated values -// in a function call. -//////////////////////////////////////////////////// - -template -struct index_tuple{}; - -template > -struct build_number_seq; - -template -struct build_number_seq > - : build_number_seq > -{}; - -template -struct build_number_seq<0, index_tuple > -{ typedef index_tuple type; }; - -template -struct typelist -{}; - -template -struct invert_typelist; - -template -struct typelist_element; - -template -struct typelist_element > -{ - typedef typename typelist_element >::type type; -}; - -template -struct typelist_element<0, typelist > -{ - typedef Head type; -}; - -template -typelist >::type...> - inverted_typelist(index_tuple, typelist) -{ - return typelist >::type...>(); -} - - -template -struct sizeof_typelist; - -template -struct sizeof_typelist< typelist > -{ - static const std::size_t value = sizeof...(Types); -}; - -//invert_typelist_impl -template -struct invert_typelist_impl; - - -template -struct invert_typelist_impl< Typelist, index_tuple > -{ - static const std::size_t last_idx = sizeof_typelist::value - 1; - typedef typelist - ::type...> type; -}; - -template -struct invert_typelist_impl< Typelist, index_tuple > -{ - typedef Typelist type; -}; - -template -struct invert_typelist_impl< Typelist, index_tuple<> > -{ - typedef Typelist type; -}; - -//invert_typelist -template -struct invert_typelist; - -template -struct invert_typelist< typelist > -{ - typedef typelist typelist_t; - typedef typename build_number_seq::type indexes_t; - typedef typename invert_typelist_impl::type type; -}; - -struct none -{ - template - struct pack : Base - { }; -}; - -//!This option setter specifies the type of -//!a void pointer. This will instruct the hook -//!to use this type of pointer instead of the -//!default one -template -struct void_pointer -{ -/// @cond - template - struct pack : Base - { - typedef VoidPointer void_pointer; - }; -/// @endcond -}; - -//!This option setter specifies the type of -//!the tag of a base hook. A type cannot have two -//!base hooks of the same type, so a tag can be used -//!to differentiate two base hooks with otherwise same type -template -struct tag -{ -/// @cond - template - struct pack : Base - { - typedef Tag tag; - }; -/// @endcond -}; - - -//!This option setter specifies if the hook -//!should be optimized for size instead of for speed. -template -struct optimize_size -{ -/// @cond - template - struct pack : Base - { - static const bool optimize_size = Enabled; - }; -/// @endcond -}; - -//!This option setter specifies if the list container should -//!use a linear implementation instead of a circular one. -template -struct linear -{ -/// @cond - template - struct pack : Base - { - static const bool linear = Enabled; - }; -/// @endcond -}; - -//!This option setter specifies if the list container should -//!use a linear implementation instead of a circular one. -template -struct cache_last -{ -/// @cond - template - struct pack : Base - { - static const bool cache_last = Enabled; - }; -/// @endcond -}; - - - -template -struct do_pack; - -template<> -struct do_pack >; - -template -struct do_pack > -{ - typedef Prev type; -}; - -template -struct do_pack > -{ - typedef typename Prev::template pack type; -}; - -template -struct do_pack > -{ - typedef typename Prev::template pack - >::type> type; -}; - - -template -struct pack_options -{ - typedef typelist typelist_t; - typedef typename invert_typelist::type inverted_typelist; - typedef typename do_pack::type type; -}; - -struct hook_defaults - : public pack_options - < none - , void_pointer - , tag - , optimize_size - , linear - >::type -{}; - - -#include -#include - -struct S -{}; - -int main() -{ - { - typedef typelist typelist_t; - typedef invert_typelist::type inverted_typelist; - std::cout << "original: " << typeid(typelist_t).name() << std::endl; - std::cout << "inverted: " << typeid(inverted_typelist).name() << std::endl; - } - { - typedef typelist typelist_t; - typedef invert_typelist::type inverted_typelist; - std::cout << "original: " << typeid(typelist_t).name() << std::endl; - std::cout << "inverted: " << typeid(inverted_typelist).name() << std::endl; - } - { - typedef typelist<> typelist_t; - typedef invert_typelist::type inverted_typelist; - std::cout << "original: " << typeid(typelist_t).name() << std::endl; - std::cout << "inverted: " << typeid(inverted_typelist).name() << std::endl; - } - { - typedef pack_options::type options_t; - std::cout << "options_t " << typeid(options_t).name() << std::endl; - } - { - typedef pack_options::type options_t; - std::cout << "options_t " << typeid(options_t).name() << std::endl; - } - - hook_defaults h; - return 1; -} -*/ \ No newline at end of file diff --git a/test/make_functions_test.cpp b/test/make_functions_test.cpp index bf40afb..2f8e1aa 100644 --- a/test/make_functions_test.cpp +++ b/test/make_functions_test.cpp @@ -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 #include #include +#include +#include +#include +#include #include #include "smart_ptr.hpp" #include using namespace boost::intrusive; +struct my_tag; + +typedef make_bs_set_base_hook + < void_pointer >, link_mode + , tag >::type TreapHook; + class MyClass : public make_list_base_hook < void_pointer >, link_mode >::type @@ -28,6 +38,13 @@ class MyClass < void_pointer >, link_mode >::type , public make_unordered_set_base_hook < void_pointer >, link_mode >::type +, public make_avl_set_base_hook + < void_pointer >, link_mode >::type +, public make_splay_set_base_hook + < void_pointer >, link_mode >::type +, public make_bs_set_base_hook + < void_pointer >, link_mode >::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::type Slist; typedef make_set::type Set; typedef make_unordered_set::type USet; +typedef make_avl_set::type AvlSet; +typedef make_splay_set::type SplaySet; +typedef make_sg_set::type SgSet; +typedef make_treap_set >::type TreapSet; + int main() { typedef std::vector::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, link_mode >::type + ,make_avl_set_base_hook<>::type + >::value == false){ + return 1; + } + + if(detail::is_same, link_mode >::type + ,make_bs_set_base_hook<>::type + >::value == false){ + return 1; + } + + if(detail::is_same, link_mode >::type + ,make_splay_set_base_hook<>::type + >::value == false){ + return 1; + } + //Check defined types and implicitly defined types are unequal if(detail::is_same, link_mode >::type ,make_list_base_hook<>::type @@ -142,6 +208,24 @@ int main() return 1; } + if(detail::is_same, link_mode >::type + ,make_avl_set_base_hook<>::type + >::value == true){ + return 1; + } + + if(detail::is_same, link_mode >::type + ,make_splay_set_base_hook<>::type + >::value == true){ + return 1; + } + + if(detail::is_same, link_mode >::type + ,make_bs_set_base_hook<>::type + >::value == true){ + return 1; + } + return 0; } diff --git a/test/multiset_test.cpp b/test/multiset_test.cpp index 180ee62..6bb0b06 100644 --- a/test/multiset_test.cpp +++ b/test/multiset_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -16,6 +16,26 @@ #include "smart_ptr.hpp" #include "generic_multiset_test.hpp" +using namespace boost::intrusive; + +struct my_tag; + +template +struct hooks +{ + typedef set_base_hook + > base_hook_type; + typedef set_base_hook + + , void_pointer + , tag + , optimize_size > auto_base_hook_type; + typedef set_member_hook, optimize_size > member_hook_type; + typedef set_member_hook + , void_pointer > auto_member_hook_type; +}; + template< class ValueType , class Option1 = boost::intrusive::none , class Option2 = boost::intrusive::none @@ -38,19 +58,19 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::set_member_hook_t - , &value_type::set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -66,11 +86,11 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , false> value_type; test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); @@ -78,8 +98,8 @@ class test_main_template test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::set_member_hook_t - , &value_type::set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -87,7 +107,7 @@ class test_main_template test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::set_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , GetContainer >::test_all(); @@ -95,8 +115,8 @@ class test_main_template test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::set_auto_member_hook_t - , &value_type::set_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , GetContainer diff --git a/test/set_test.cpp b/test/set_test.cpp index 44a0141..6d28424 100644 --- a/test/set_test.cpp +++ b/test/set_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -16,6 +16,26 @@ #include "smart_ptr.hpp" #include "generic_set_test.hpp" +struct my_tag; + +using namespace boost::intrusive; + +template +struct hooks +{ + typedef set_base_hook + > base_hook_type; + typedef set_base_hook + + , void_pointer + , tag + , optimize_size > auto_base_hook_type; + typedef set_member_hook, optimize_size > member_hook_type; + typedef set_member_hook + , void_pointer > auto_member_hook_type; +}; + template< class ValueType , class Option1 = boost::intrusive::none , class Option2 = boost::intrusive::none @@ -38,19 +58,19 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::set_member_hook_t - , &value_type::set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -66,11 +86,11 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , false> value_type; test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); @@ -78,8 +98,8 @@ class test_main_template test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::set_member_hook_t - , &value_type::set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -87,7 +107,7 @@ class test_main_template test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::set_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , GetContainer >::test_all(); @@ -95,8 +115,8 @@ class test_main_template test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::set_auto_member_hook_t - , &value_type::set_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , GetContainer diff --git a/test/sg_multiset_test.cpp b/test/sg_multiset_test.cpp index e5bff6a..327eaf0 100644 --- a/test/sg_multiset_test.cpp +++ b/test/sg_multiset_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -36,6 +36,22 @@ struct has_rebalance +struct hooks +{ + typedef bs_set_base_hook > base_hook_type; + typedef bs_set_member_hook > member_hook_type; + typedef member_hook_type auto_member_hook_type; + struct auto_base_hook_type + : bs_set_base_hook, tag > + {}; +}; + + template< class ValueType , class Option1 = boost::intrusive::none , class Option2 = boost::intrusive::none @@ -74,34 +90,34 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , true> value_type; test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::bs_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::bs_set_member_hook_t - , &value_type::sg_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer >::test_all(); test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::bs_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainerFixedAlpha >::test_all(); test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::bs_set_member_hook_t - , &value_type::sg_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainerFixedAlpha diff --git a/test/sg_set_test.cpp b/test/sg_set_test.cpp index df424cc..61c19a4 100644 --- a/test/sg_set_test.cpp +++ b/test/sg_set_test.cpp @@ -35,6 +35,22 @@ struct has_rebalance +struct hooks +{ + typedef bs_set_base_hook > base_hook_type; + typedef bs_set_member_hook > member_hook_type; + typedef member_hook_type auto_member_hook_type; + struct auto_base_hook_type + : bs_set_base_hook, tag > + {}; +}; + template< class ValueType , class Option1 = boost::intrusive::none , class Option2 = boost::intrusive::none @@ -73,19 +89,19 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , true> value_type; test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::bs_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::bs_set_member_hook_t - , &value_type::sg_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -93,15 +109,15 @@ class test_main_template test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::bs_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainerFixedAlpha >::test_all(); test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::bs_set_member_hook_t - , &value_type::sg_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainerFixedAlpha diff --git a/test/slist_test.cpp b/test/slist_test.cpp index 7ca0afc..569c1ae 100644 --- a/test/slist_test.cpp +++ b/test/slist_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -24,6 +24,19 @@ using namespace boost::intrusive; +struct my_tag; + +template +struct hooks +{ + typedef slist_base_hook > base_hook_type; + typedef slist_base_hook< link_mode + , void_pointer, tag > auto_base_hook_type; + typedef slist_member_hook, tag > member_hook_type; + typedef slist_member_hook< link_mode + , void_pointer > auto_member_hook_type; +}; + template struct test_slist { @@ -491,14 +504,14 @@ class test_main_template public: int operator()() { - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; std::vector data (5); for (int i = 0; i < 5; ++i) data[i].value_ = i + 1; test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_base_hook_t + , typename hooks::base_hook_type >::type , false , false @@ -506,8 +519,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_member_hook_t - , &value_type::slist_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , false @@ -517,7 +530,7 @@ class test_main_template //Now linear slists test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_base_hook_t + , typename hooks::base_hook_type >::type , true , false @@ -526,8 +539,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_member_hook_t - , &value_type::slist_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , true @@ -537,7 +550,7 @@ class test_main_template //Now the same but caching the last node test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_base_hook_t + , typename hooks::base_hook_type >::type , false , true @@ -545,8 +558,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_member_hook_t - , &value_type::slist_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , false @@ -556,7 +569,7 @@ class test_main_template //Now linear slists test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_base_hook_t + , typename hooks::base_hook_type >::type , true , true @@ -565,8 +578,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_member_hook_t - , &value_type::slist_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , true @@ -582,14 +595,14 @@ class test_main_template public: int operator()() { - typedef testvalue value_type; + typedef testvalue , false> value_type; std::vector data (5); for (int i = 0; i < 5; ++i) data[i].value_ = i + 1; test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_base_hook_t + , typename hooks::base_hook_type >::type , false , false @@ -598,8 +611,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_member_hook_t - , &value_type::slist_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , false @@ -608,7 +621,7 @@ class test_main_template test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , false , false @@ -617,8 +630,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_auto_member_hook_t - , &value_type::slist_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , false @@ -627,7 +640,7 @@ class test_main_template test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_base_hook_t + , typename hooks::base_hook_type >::type , true , false @@ -636,8 +649,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_member_hook_t - , &value_type::slist_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , true @@ -647,7 +660,7 @@ class test_main_template //Now cache last test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_base_hook_t + , typename hooks::base_hook_type >::type , false , true @@ -656,8 +669,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_member_hook_t - , &value_type::slist_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , false @@ -666,7 +679,7 @@ class test_main_template test_slist < typename detail::get_base_value_traits < value_type - , typename value_type::slist_base_hook_t + , typename hooks::base_hook_type >::type , true , true @@ -675,8 +688,8 @@ class test_main_template test_slist < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::slist_member_hook_t - , &value_type::slist_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , true diff --git a/test/splay_multiset_test.cpp b/test/splay_multiset_test.cpp index fbccdef..21bd600 100644 --- a/test/splay_multiset_test.cpp +++ b/test/splay_multiset_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -70,6 +70,24 @@ struct has_rebalance +struct hooks +{ + typedef splay_set_base_hook > base_hook_type; + typedef splay_set_base_hook + < link_mode + , void_pointer + , tag > auto_base_hook_type; + typedef splay_set_member_hook > member_hook_type; + typedef splay_set_member_hook + < link_mode + , void_pointer > auto_member_hook_type; +}; + template< class ValueType , class Option1 = boost::intrusive::none , class Option2 = boost::intrusive::none @@ -92,19 +110,19 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::splay_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::splay_set_member_hook_t - , &value_type::splay_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -120,11 +138,11 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , false> value_type; test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::splay_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); @@ -132,8 +150,8 @@ class test_main_template test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::splay_set_member_hook_t - , &value_type::splay_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -141,7 +159,7 @@ class test_main_template test::test_generic_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::splay_set_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , GetContainer >::test_all(); @@ -149,8 +167,8 @@ class test_main_template test::test_generic_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::splay_set_auto_member_hook_t - , &value_type::splay_set_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , GetContainer diff --git a/test/splay_set_test.cpp b/test/splay_set_test.cpp index 3f61609..299e12b 100644 --- a/test/splay_set_test.cpp +++ b/test/splay_set_test.cpp @@ -67,6 +67,24 @@ struct has_rebalance +struct hooks +{ + typedef splay_set_base_hook > base_hook_type; + typedef splay_set_base_hook + < link_mode + , void_pointer + , tag > auto_base_hook_type; + typedef splay_set_member_hook > member_hook_type; + typedef splay_set_member_hook + < link_mode + , void_pointer > auto_member_hook_type; +}; + template< class ValueType , class Option1 = boost::intrusive::none , class Option2 = boost::intrusive::none @@ -89,19 +107,19 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::splay_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::splay_set_member_hook_t - , &value_type::splay_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -117,11 +135,11 @@ class test_main_template int operator()() { using namespace boost::intrusive; - typedef testvalue value_type; + typedef testvalue , false> value_type; test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::splay_set_base_hook_t + , typename hooks::base_hook_type >::type , GetContainer >::test_all(); @@ -129,8 +147,8 @@ class test_main_template test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::splay_set_member_hook_t - , &value_type::splay_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , GetContainer @@ -138,7 +156,7 @@ class test_main_template test::test_generic_set < typename detail::get_base_value_traits < value_type - , typename value_type::splay_set_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , GetContainer >::test_all(); @@ -146,8 +164,8 @@ class test_main_template test::test_generic_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::splay_set_auto_member_hook_t - , &value_type::splay_set_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , GetContainer diff --git a/test/stateful_value_traits_test.cpp b/test/stateful_value_traits_test.cpp index aca8cb3..ffba752 100644 --- a/test/stateful_value_traits_test.cpp +++ b/test/stateful_value_traits_test.cpp @@ -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 diff --git a/test/test_container.hpp b/test/test_container.hpp index 9ae000a..b3124e9 100644 --- a/test/test_container.hpp +++ b/test/test_container.hpp @@ -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 diff --git a/test/test_macros.hpp b/test/test_macros.hpp index 3a76541..0b23322 100644 --- a/test/test_macros.hpp +++ b/test/test_macros.hpp @@ -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 diff --git a/test/treap_multiset_test.cpp b/test/treap_multiset_test.cpp new file mode 100644 index 0000000..dbae120 --- /dev/null +++ b/test/treap_multiset_test.cpp @@ -0,0 +1,135 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Olaf Krzikalla 2004-2006. +// (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. +// +///////////////////////////////////////////////////////////////////////////// + +#include +#include +#include "itestvalue.hpp" +#include "smart_ptr.hpp" +#include "generic_multiset_test.hpp" + +using namespace boost::intrusive; + +struct my_tag; + +template +struct hooks +{ + typedef bs_set_base_hook > base_hook_type; + typedef bs_set_base_hook + < void_pointer + , tag > auto_base_hook_type; + typedef bs_set_member_hook + < void_pointer > member_hook_type; + typedef bs_set_member_hook + < void_pointer > auto_member_hook_type; +}; + +template< class ValueType + , class Option1 = boost::intrusive::none + , class Option2 = boost::intrusive::none + , class Option3 = boost::intrusive::none + > +struct GetContainer +{ + typedef boost::intrusive::treap_multiset + < ValueType + , Option1 + , Option2 + , Option3 + > type; +}; + +template +class test_main_template +{ + public: + int operator()() + { + using namespace boost::intrusive; + typedef testvalue , constant_time_size> value_type; + + test::test_generic_multiset < typename detail::get_base_value_traits + < value_type + , typename hooks::base_hook_type + >::type + , GetContainer + >::test_all(); + test::test_generic_multiset < typename detail::get_member_value_traits + < value_type + , member_hook< value_type + , typename hooks::member_hook_type + , &value_type::node_ + > + >::type + , GetContainer + >::test_all(); + return 0; + } +}; + +template +class test_main_template +{ + public: + int operator()() + { + using namespace boost::intrusive; + typedef testvalue , false> value_type; + + test::test_generic_multiset < typename detail::get_base_value_traits + < value_type + , typename hooks::base_hook_type + >::type + , GetContainer + >::test_all(); + + test::test_generic_multiset < typename detail::get_member_value_traits + < value_type + , member_hook< value_type + , typename hooks::member_hook_type + , &value_type::node_ + > + >::type + , GetContainer + >::test_all(); + + test::test_generic_multiset < typename detail::get_base_value_traits + < value_type + , typename hooks::auto_base_hook_type + >::type + , GetContainer + >::test_all(); + + test::test_generic_multiset < typename detail::get_member_value_traits + < value_type + , member_hook< value_type + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ + > + >::type + , GetContainer + >::test_all(); + return 0; + } +}; + +int main( int, char* [] ) +{ + test_main_template()(); + test_main_template, false>()(); + test_main_template()(); + test_main_template, true>()(); + return boost::report_errors(); +} + +#include diff --git a/test/treap_set_test.cpp b/test/treap_set_test.cpp new file mode 100644 index 0000000..cbd6471 --- /dev/null +++ b/test/treap_set_test.cpp @@ -0,0 +1,134 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (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. +// +///////////////////////////////////////////////////////////////////////////// +#include +#include +#include "itestvalue.hpp" +#include "smart_ptr.hpp" +#include "generic_set_test.hpp" + +using namespace boost::intrusive; + +struct my_tag; + +template +struct hooks +{ + typedef bs_set_base_hook > base_hook_type; + typedef bs_set_base_hook + < void_pointer + , tag > auto_base_hook_type; + typedef bs_set_member_hook + < void_pointer > member_hook_type; + typedef bs_set_member_hook + < void_pointer > auto_member_hook_type; +}; + +template< class ValueType + , class Option1 = boost::intrusive::none + , class Option2 = boost::intrusive::none + , class Option3 = boost::intrusive::none + > +struct GetContainer +{ + typedef boost::intrusive::treap_set + < ValueType + , Option1 + , Option2 + , Option3 + > type; +}; + +template +class test_main_template +{ + public: + int operator()() + { + using namespace boost::intrusive; + typedef testvalue , constant_time_size> value_type; + + test::test_generic_set < typename detail::get_base_value_traits + < value_type + , typename hooks::base_hook_type + >::type + , GetContainer + >::test_all(); + test::test_generic_set < typename detail::get_member_value_traits + < value_type + , member_hook< value_type + , typename hooks::member_hook_type + , &value_type::node_ + > + >::type + , GetContainer + >::test_all(); + return 0; + } +}; + +template +class test_main_template +{ + public: + int operator()() + { + using namespace boost::intrusive; + typedef testvalue , false> value_type; + + test::test_generic_set < typename detail::get_base_value_traits + < value_type + , typename hooks::base_hook_type + >::type + , GetContainer + >::test_all(); + + test::test_generic_set < typename detail::get_member_value_traits + < value_type + , member_hook< value_type + , typename hooks::member_hook_type + , &value_type::node_ + > + >::type + , GetContainer + >::test_all(); + + test::test_generic_set < typename detail::get_base_value_traits + < value_type + , typename hooks::auto_base_hook_type + >::type + , GetContainer + >::test_all(); + + test::test_generic_set < typename detail::get_member_value_traits + < value_type + , member_hook< value_type + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ + > + >::type + , GetContainer + >::test_all(); + + return 0; + } +}; + +int main( int, char* [] ) +{ + test_main_template()(); + test_main_template, false>()(); + test_main_template()(); + test_main_template, true>()(); + return boost::report_errors(); +} + +#include diff --git a/test/unordered_multiset_test.cpp b/test/unordered_multiset_test.cpp index 1adab30..868d264 100644 --- a/test/unordered_multiset_test.cpp +++ b/test/unordered_multiset_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -25,6 +25,30 @@ using namespace boost::intrusive; +struct my_tag; + +template +struct hooks +{ + typedef unordered_set_base_hook > base_hook_type; + typedef unordered_set_base_hook + < link_mode + , void_pointer + , tag + , store_hash + > auto_base_hook_type; + + typedef unordered_set_member_hook + < void_pointer + , optimize_multikey + > member_hook_type; + typedef unordered_set_member_hook + < link_mode, void_pointer + , store_hash + , optimize_multikey + > auto_member_hook_type; +}; + static const std::size_t BucketSize = 8; template @@ -669,15 +693,15 @@ class test_main_template public: int operator()() { - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; static const int random_init[6] = { 3, 2, 4, 1, 5, 2 }; - std::vector > data (6); + std::vector , constant_time_size> > data (6); for (int i = 0; i < 6; ++i) data[i].value_ = random_init[i]; test_unordered_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::unordered_set_base_hook_t + , typename hooks::base_hook_type >::type , true , false @@ -687,8 +711,8 @@ class test_main_template test_unordered_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::unordered_set_member_hook_t - , &value_type::unordered_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , false @@ -706,15 +730,15 @@ class test_main_template public: int operator()() { - typedef testvalue value_type; + typedef testvalue , false> value_type; static const int random_init[6] = { 3, 2, 4, 1, 5, 2 }; - std::vector > data (6); + std::vector , false> > data (6); for (int i = 0; i < 6; ++i) data[i].value_ = random_init[i]; test_unordered_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::unordered_set_base_hook_t + , typename hooks::base_hook_type >::type , true , false @@ -724,8 +748,8 @@ class test_main_template test_unordered_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::unordered_set_member_hook_t - , &value_type::unordered_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , false @@ -735,7 +759,7 @@ class test_main_template test_unordered_multiset < typename detail::get_base_value_traits < value_type - , typename value_type::unordered_set_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , true , true @@ -745,8 +769,8 @@ class test_main_template test_unordered_multiset < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::unordered_set_auto_member_hook_t - , &value_type::unordered_set_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , false diff --git a/test/unordered_set_test.cpp b/test/unordered_set_test.cpp index 8aa27da..b84414b 100644 --- a/test/unordered_set_test.cpp +++ b/test/unordered_set_test.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (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 @@ -24,6 +24,30 @@ using namespace boost::intrusive; +struct my_tag; + +template +struct hooks +{ + typedef unordered_set_base_hook > base_hook_type; + typedef unordered_set_base_hook + < link_mode + , void_pointer + , tag + , store_hash + > auto_base_hook_type; + + typedef unordered_set_member_hook + < void_pointer + , optimize_multikey + > member_hook_type; + typedef unordered_set_member_hook + < link_mode, void_pointer + , store_hash + , optimize_multikey + > auto_member_hook_type; +}; + static const std::size_t BucketSize = 8; template @@ -532,15 +556,15 @@ class test_main_template public: int operator()() { - typedef testvalue value_type; + typedef testvalue , constant_time_size> value_type; static const int random_init[6] = { 3, 2, 4, 1, 5, 2 }; - std::vector > data (6); + std::vector , constant_time_size> > data (6); for (int i = 0; i < 6; ++i) data[i].value_ = random_init[i]; test_unordered_set < typename detail::get_base_value_traits < value_type - , typename value_type::unordered_set_base_hook_t + , typename hooks::base_hook_type >::type , true , false @@ -549,8 +573,8 @@ class test_main_template test_unordered_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::unordered_set_member_hook_t - , &value_type::unordered_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , false @@ -568,15 +592,15 @@ class test_main_template public: int operator()() { - typedef testvalue value_type; + typedef testvalue , false> value_type; static const int random_init[6] = { 3, 2, 4, 1, 5, 2 }; - std::vector > data (6); + std::vector , false> > data (6); for (int i = 0; i < 6; ++i) data[i].value_ = random_init[i]; test_unordered_set < typename detail::get_base_value_traits < value_type - , typename value_type::unordered_set_base_hook_t + , typename hooks::base_hook_type >::type , true , false @@ -586,8 +610,8 @@ class test_main_template test_unordered_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::unordered_set_member_hook_t - , &value_type::unordered_set_node_ + , typename hooks::member_hook_type + , &value_type::node_ > >::type , false @@ -597,7 +621,7 @@ class test_main_template test_unordered_set < typename detail::get_base_value_traits < value_type - , typename value_type::unordered_set_auto_base_hook_t + , typename hooks::auto_base_hook_type >::type , true , true @@ -607,8 +631,8 @@ class test_main_template test_unordered_set < typename detail::get_member_value_traits < value_type , member_hook< value_type - , typename value_type::unordered_set_auto_member_hook_t - , &value_type::unordered_set_auto_node_ + , typename hooks::auto_member_hook_type + , &value_type::auto_node_ > >::type , false diff --git a/test/virtual_base_test.cpp b/test/virtual_base_test.cpp index 14bd885..92a700b 100644 --- a/test/virtual_base_test.cpp +++ b/test/virtual_base_test.cpp @@ -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