diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 823d326..9cac616 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -1,6 +1,6 @@ # Boost.Intrusive library documentation Jamfile # -# Copyright Ion Gaztañaga 2006. +# Copyright Ion Gaztanaga 2006. # 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) diff --git a/doc/intrusive.qbk b/doc/intrusive.qbk index 3a84c3f..2b410ed 100644 --- a/doc/intrusive.qbk +++ b/doc/intrusive.qbk @@ -127,7 +127,7 @@ way to make user classes compatible with those containers. [section:properties_of_intrusive Properties of Boost.Intrusive containers] -Semantically, a [*Boost.Intrusive] container is similar to an STL container +Semantically, a [*Boost.Intrusive] container is similar to a STL container holding pointers to objects. That is, if you have an intrusive list holding objects of type `T`, then `std::list` would allow you to do quite the same operations (maintaining and navigating a set of objects of type T and @@ -141,7 +141,7 @@ A non-intrusive container has some limitations: * The use of dynamic allocation to create copies of passed values can be a performance and size bottleneck in some applications. Normally, dynamic allocation imposes - a size overhead for each allocation to store bookeeping information and a + a size overhead for each allocation to store bookkeeping information and a synchronization to protected concurrent allocation from different threads. * Only copies of objects are stored in non-intrusive containers. Hence copy @@ -160,7 +160,7 @@ Intrusive containers have some important advantages: equivalent container of pointers: iteration is faster. * Intrusive containers offer better exception guarantees than non-intrusive containers. - In some situation intrusives containers offer a no-throw guarantee that can't be + In some situations intrusive containers offer a no-throw guarantee that can't be achieved with non-intrusive containers. * The computation of an iterator to an element from a pointer or reference to that element @@ -168,19 +168,19 @@ Intrusive containers have some important advantages: linear complexity). * Intrusive containers offer predictability when inserting and erasing objects since no - memory managed is done with intrusive containers. Memory management usually is not a predicable + memory management is done with intrusive containers. Memory management usually is not a predictable operation so complexity guarantees from non-intrusive containers are looser than the guarantees offered by intrusive containers. Intrusive containers have also downsides: * Each type stored in an intrusive container needs additional memory holding the - maintenance information needed by the container. Hence, whenever a certain type shall + maintenance information needed by the container. Hence, whenever a certain type will be stored in an intrusive container [*you have to change the definition of that type] appropriately. Although this task is easy with [*Boost.Intrusive], touching the definition of a type is sometimes a crucial issue. -* In intrusive containers you don't store a copy of an object, [*but they rather the original object +* In intrusive containers you don't store a copy of an object, [*but rather the original object is linked with other objects in the container]. Objects don't need copy-constructors or assignment operators to be stored in intrusive containers. But you have to take care of possible side effects, whenever you change the contents of an object (this is especially important for @@ -194,14 +194,14 @@ Intrusive containers have also downsides: can be disposed before is erased from the container. * [*Boost.Intrusive] containers are [*non-copyable and non-assignable]. Since intrusive - containers don't have allocation capabilities, these operations have no sense. However, - swapping can be used to implement move-capabilities. To ease the implementation of + containers don't have allocation capabilities, these operations make no sense. However, + swapping can be used to implement move capabilities. To ease the implementation of copy constructors and assignment operators of classes storing [*Boost.Intrusive] containers, [*Boost.Intrusive] offers special cloning functions. See [link intrusive.clone_from Cloning [*Boost.Intrusive] containers] section for more information. -* Analyzing thread-safety of a program that uses containers is harder with intrusive containers, becuase - the container might be modified indirectly without an explicitly call to a container member. +* Analyzing the thread safety of a program that uses containers is harder with intrusive containers, because + the container might be modified indirectly without an explicit call to a container member. [table Summay of intrusive containers advantages and disadvantages [[Issue] [Intrusive] [Non-intrusive]] @@ -233,8 +233,8 @@ For a performance comparison between Intrusive and Non-intrusive containers see If you plan to insert a class in an intrusive container, you have to make some decisions influencing the class definition itself. Each class that will be used in an intrusive container needs some appropriate data members storing the information needed by the -container. We will take a simple intrusive container, like an intrusive list -([classref boost::intrusive::list boost::intrusive::list]) for the following +container. We will take a simple intrusive container, the intrusive list +([classref boost::intrusive::list boost::intrusive::list]), for the following examples, but all [*Boost.Intrusive] containers are very similar. To compile the example using [classref boost::intrusive::list boost::intrusive::list], just include: @@ -312,7 +312,7 @@ and optionally, the user can specify options. We have 3 option types: [link intrusive.value_traits Containers with custom ValueTraits] section. [*If no option is specified, the container will be configured to use the base hook with the default tag]. - Some options configured for the hook (the type of the pointers, link mode...) + Some options configured for the hook (the type of the pointers, link mode, etc.) will be propagated to the container. * [*`constant_time_size`]: Specifies if a constant time `size()` @@ -326,7 +326,7 @@ and optionally, the user can specify options. We have 3 option types: is requested. The user normally will not need to change this type, but some containers can have a `size_type` that might be different from `std::size_t` - (for example, STL-like containers, use the `size_type` defined by their allocator). + (for example, STL-like containers use the `size_type` defined by their allocator). [*Boost.Intrusive] can be used to implement such containers specifying the the type of the size. By default the type is `std::size_t`. @@ -428,8 +428,8 @@ Now we can use the container: [section:usage_both_hooks Using both hooks] -You can insert the same object in several intrusive containers at the same time, just -using one hook for each container. This is a full example using base and member hooks: +You can insert the same object in several intrusive containers at the same time, +using one hook per container. This is a full example using base and member hooks: [import ../example/doc_how_to_use.cpp] [doc_how_to_use_code] @@ -456,7 +456,7 @@ stored object is not bound to or managed by the container: [section:usage_when When to use?] Intrusive containers can be used for highly optimized algorithms, where speed is a crucial -issue and... +issue and: * additional memory management should be avoided. * the programmer needs to efficiently track the construction and destruction of objects. @@ -467,24 +467,24 @@ issue and... * localization of data (e.g. for cache hit optimization) leads to measureable effects. The last point is important if you have a lot of containers over a set of elements. E.g. if -you have a vector of objects (say, `std::vector`) and you also have a list +you have a vector of objects (say, `std::vector`), and you also have a list storing a subset of those objects (`std::list`), then operating on an Object -from the list iterator (`std::list::iterator`) needs two steps: +from the list iterator (`std::list::iterator`) requires two steps: * Access from the iterator (usually on the stack) to the list node storing a pointer to `Object`. * Access from the pointer to `Object` to the Object stored in the vector. While the objects themselves are tightly packed in the memory of the vector -(vector's memory is guaranteed to be contiguous), and form something -like a data block, list nodes can stay dispersed in the heap memory. -Hence depending on your system you can get a lot of cache misses. The same doesn't hold -for an intrusive list. Indeed, dereferencing an an iterator from an intrusive list is performed in +(a vector's memory is guaranteed to be contiguous), and form something +like a data block, list nodes may be dispersed in the heap memory. +Hence depending on your system you might get a lot of cache misses. The same doesn't hold +for an intrusive list. Indeed, dereferencing an iterator from an intrusive list is performed in the same two steps as described above. But the list node is already embedded in the Object, so the memory is directly tracked from the iterator to the Object. It's also possible to use intrusive containers when the objects to be stored can have different or unknown size. This allows storing base and derived objects -in the same container as shown in the following example: +in the same container, as shown in the following example: [import ../example/doc_window.cpp] [doc_window_code] @@ -493,7 +493,7 @@ Due to certain properties of intrusive containers they are often more difficult to use than their STL-counterparts. That's why you should avoid them in public interfaces of libraries. Classes to be stored in intrusive containers must change their implementation to store the hook and this is not always -posible or desirable. +possible or desirable. [endsect] @@ -504,13 +504,13 @@ chapters: [variablelist Brief Concepts Summary [[Node Algorithms][A class containing typedefs and static functions that define - basic operations that can be applied to a groups of nodes. It's independent - from the node definition, and it's configured taking a NodeTraits template + basic operations that can be applied to a group of nodes. It's independent + from the node definition and configured using a NodeTraits template parameter that describes the node.]] -[[Node Traits][A class that stores basic information and operations to insert a node in a group of nodes.]] +[[Node Traits][A class that stores basic information and operations to insert a node into a group of nodes.]] [[Hook][A class that a user must add as a base class or as a member to make the user class compatible with intrusive containers.]] [[Intrusive Container][A class that stores user classes that have the needed hooks. It takes a ValueTraits template parameter as configuration information.]] -[[Pseudo-Intrusive Container][Similar to an intrusive container but a pseudo-intrusive container needs additional memory (e.g. an auxiliary array) to work.]] +[[Semi-Intrusive Container][Similar to an intrusive container but a semi-intrusive container needs additional memory (e.g. an auxiliary array) to work.]] [[Value Traits][A class containing typedefs and operations to obtain the node to be used by Node Algorithms from the user class and the inverse.]] ] @@ -528,27 +528,45 @@ chapters: small for user classes (usually the size of two pointers). Many operations have constant time complexity. -* [*set/multiset]: A `std::set/std::multiset` like intrusive associative containers. +* [*set/multiset/rbtree]: `std::set/std::multiset` like intrusive associative containers + based on red-black trees. The size overhead is moderate for user classes (usually the size of three pointers). Many operations have logarithmic time complexity. -[*Boost.Intrusive] also offers pseudo-intrusive containers: +* [*avl_set/avl_multiset/avltree]: A `std::set/std::multiset` like intrusive associative + containers based on AVL trees. + The size overhead is moderate for user classes (usually the size of three pointers). + Many operations have logarithmic time complexity. -* [*unordered_set/unordered_multiset]: A `std::tr1::unordered_set/std::tr1::unordered_multiset` +* [*splay_set/splay_multiset/splaytree]: `std::set/std::multiset` like intrusive associative + containers based on splay trees. Splay trees have no constant operations, but they + have some interesting caching properties. + The size overhead is moderate for user classes (usually the size of three pointers). + Many operations have logarithmic time complexity. + +* [*sg_set/sg_multiset/sgtree]: A `std::set/std::multiset` like intrusive associative + containers based on scapegoat trees. Scapegoat can be configured with the desired + balance factor to achieve the desired rebalancing frequency/search time compromise. + The size overhead is moderate for user classes (usually the size of three pointers). + Many operations have logarithmic time complexity. + +[*Boost.Intrusive] also offers semi-intrusive containers: + +* [*unordered_set/unordered_multiset]: `std::tr1::unordered_set/std::tr1::unordered_multiset` like intrusive unordered associative containers. The size overhead is moderate for user classes (an average of two pointers per element). - Many operations have an amortized constant time complexity. + Many operations have amortized constant time complexity. -Each of these intrusive containers can be configured with constant or linear time +Most of these intrusive containers can be configured with constant or linear time size: -* [*Linear time size]: The intrusive container doesn't hold a size member that it's -updated with every insertion/erasure. This implies that the `size()` function has not constant +* [*Linear time size]: The intrusive container doesn't hold a size member that is +updated with every insertion/erasure. This implies that the `size()` function doesn't have constant time complexity. On the other hand, the container is smaller, and some operations, like -`splice()` taking a range of iterators in linked lists have constant time complexity +`splice()` taking a range of iterators in linked lists, have constant time complexity instead of linear complexity. -* [*Constant time size]: The intrusive container holds a size member that it's updated +* [*Constant time size]: The intrusive container holds a size member that is updated with every insertion/erasure. This implies that the `size()` function has constant time complexity. On the other hand, increases the size of the container, and some operations, like `splice()` taking a range of iterators, have linear time complexity in linked lists. @@ -566,19 +584,19 @@ Apart from that, [*Boost.Intrusive] offers additional features: safe state and intrusive containers check that state before inserting a value in the container. When erasing an element from the container, the container puts the hook in the safe state again. This allows a safer use mode and it can be used to detect - programming errors. It implies an slight performance overhead in some operations - and can convert some constant time operations in linear time operations. + programming errors. It implies a slight performance overhead in some operations + and can convert some constant time operations to linear time operations. * [*Auto-unlink hooks]: The hook destructor removes the object from the container automatically and the user can safely unlink the object from the container without - having any reference to the container. + referring to the container. * [*Non-raw pointers]: If the user wants to use smart pointers instead of raw pointers, [*Boost.Intrusive] hooks can - be configured to use any type of pointers. This configuration information is also + be configured to use any type of pointer. This configuration information is also transmitted to the containers, so all the internal pointers used by intrusive containers configured with these hooks will be smart pointers. As an example, - [*Boost.Interprocess] defines an smart pointer compatible with shared memory, + [*Boost.Interprocess] defines an mart pointer compatible with shared memory, called `offset_ptr`. [*Boost.Intrusive] can be configured to use this smart pointer to allow shared memory intrusive containers. @@ -593,19 +611,19 @@ The safe mode is activated by default, but it can be also explicitly activated: [c++] - //Configuring explicity the safe mode + //Configuring the safe mode explicitly class Foo : public list_base_hook< link_mode > {}; -Thanks to the safe-mode the user can detect without any external reference, if the object -is actually inserted in a container. Let's review the basic features of the safe-mode: +With the safe mode the user can detect if the object +is actually inserted in a container without any external reference. Let's review the basic features of the safe mode: -* Hooks' constructor puts the hook in a well-known default state. +* Hook's constructor puts the hook in a well-known default state. -* Hooks' destructor checks if the hook is in the well-known default state. If not, +* Hook's destructor checks if the hook is in the well-known default state. If not, an assertion is raised. -* Every time an object is being inserted in the intrusive container, the container +* Every time an object is inserted in the intrusive container, the container checks if the hook is in the well-known default state. If not, an assertion is raised. @@ -613,9 +631,9 @@ is actually inserted in a container. Let's review the basic features of the safe puts the erased object in the well-known default state. With these features, without any external reference the user can know if the object -has been inserted in a container calling the `is_linked()` member function. +has been inserted in a container by calling the `is_linked()` member function. If the object is not actually inserted -in a container, the hook is in the default state and if it's inserted in a container, the +in a container, the hook is in the default state, and if it is inserted in a container, the hook is not in the default state. [endsect] @@ -637,7 +655,7 @@ want to redefine intrusive safe-mode assertions without modifying the global * `BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT`: This assertion will be used in hooks' destructors to check that the hook is in a default state. -If any of these macros is not redefined, the assertion will be defaul to `BOOST_ASSERT`. +If any of these macros is not redefined, the assertion will default to `BOOST_ASSERT`. [endsect] @@ -652,17 +670,17 @@ If any of these macros is not redefined, the assertion will be defaul to `BOOST_ * When the destructor of the hook is called, the hook checks if the node is inserted in a container. If so, the hook removes the node from the container. * The hook has a member function called `unlink()` that can be used to unlink the - node from the container at any moment, without having any reference to the container, - if the user want to do so. + node from the container at any time, without having any reference to the container, + if the user wants to do so. -These hooks have exactly the same size overhead as their analogue non auto-unlinking +These hooks have exactly the same size overhead as their analog non auto-unlinking hooks, but they have a restriction: they can only be used with [link intrusive.presenting_containers non-constant time containers]. There is a reason for this: * Auto-unlink hooks don't store any reference to the container where they are inserted. * Only containers with non constant-time `size()` allow removing an object from the container - without using any reference to the container. + without referring to the container. This auto-unlink feature is useful in certain applications but it must be used [*very carefuly]: @@ -678,11 +696,11 @@ These auto-unlink hooks have also safe-mode properties: * Hooks' constructors put the hook in a well-known default state. -* Every time an object is being inserted in the intrusive container, the container - checks if the hook is the well-known default state. If not, +* Every time an object is inserted in the intrusive container, the container + checks if the hook is in the well-known default state. If not, an assertion is raised. -* Every time an object is being erased from the intrusive container, the container +* Every time an object is erased from an intrusive container, the container puts the erased object in the well-known default state. [endsect] @@ -700,7 +718,7 @@ Let's see an example of an auto-unlink hook: As explained, [*Boost.Intrusive] auto-unlink hooks are incompatible with containers that have constant-time `size()`, so if you try to define such container with an -auto-unlink hook's value_traits, you will get an static assertion: +auto-unlink hook's value_traits, you will get a static assertion: [c++] @@ -745,17 +763,17 @@ in constant-time size containers. [classref boost::intrusive::slist slist] is the simplest intrusive container of [*Boost.Intrusive]: a singly linked list. The memory overhead -that imposes is 1 pointer per node. The size of an empty, non constant-time size -[classref boost::intrusive::slist slist], is the size of 1 pointer. This -lightweight memory overhead comes with its drawbacks, though: many operations have +it imposes is 1 pointer per node. The size of an empty, non constant-time size +[classref boost::intrusive::slist slist] is the size of 1 pointer. This +lightweight memory overhead comes with drawbacks, though: many operations have linear time complexity, even some that usually are constant time, like [classref boost::intrusive::slist::swap swap]. [classref boost::intrusive::slist slist] only provides forward iterators. For most cases, a doubly linked list is preferrable because it offers more -constant-time functions with a slightly bigger overhead. +constant-time functions with a slightly bigger size overhead. However, for some applications like -constructing more elaborated containers, singly linked lists are essential +constructing more elaborate containers, singly linked lists are essential because of their low size overhead. [section:slist_hooks slist hooks] @@ -784,7 +802,8 @@ Like the rest of [*Boost.Intrusive] containers, it [classref boost::intrusive::slist slist]-compatible. [classref boost::intrusive::slist_base_hook slist_base_hook] and -[classref boost::intrusive::slist_member_hook slist_member_hook] receive the same options explained in +[classref boost::intrusive::slist_member_hook slist_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, @@ -807,25 +826,41 @@ the section [link intrusive.usage How to use Boost.Intrusive]: template class slist; -[classref boost::intrusive::slist slist] receives the same options explained in +[classref boost::intrusive::slist slist] receives the 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 know about value traits go to the section - titled [link intrusive.value_traits Containers with custom ValueTraits]. + 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` + of the container. Default: `size_type`. + +[classref boost::intrusive::slist slist] can receive additional options: + +* [*`linear`]: the singly linked list is implemented as a + null-terminated list instead of a circular list. This allows `O(1)` swap, + but losses some operations like `container_from_end_iterator`. +* [*`cache_last`]: the singly linked also stores a pointer to the + last element of the singly linked list. This allows `O(1)` swap, + `splice_after(iterator, slist &)` and makes the list offer new functions + like `push_back(reference)` and `back()`. Logically, the size an empty list is + increased in `sizeof(void_pointer)` and the the cached last node pointer must + be updated in every operation, and that might incur in a slight performance impact. + +`auto_unlink` hooks are not usable if `linear` and/or `cache_last` options are +used. If `auto_unlink` hooks are used and those options are specified, a static +assertion will be raised. [endsect] [section:slist_example Example] -Now let's see an small example using both hooks: +Now let's see a small example using both hooks: [import ../example/doc_slist.cpp] [doc_slist_code] @@ -837,10 +872,10 @@ Now let's see an small example using both hooks: [section:list Intrusive doubly linked list: list] [classref boost::intrusive::list list] is a doubly linked list. The memory overhead -that imposes is 2 pointers per node. An empty, non constant-time size [classref boost::intrusive::list list] -has also the size of 2 pointers. [classref boost::intrusive::list list] +it imposes is 2 pointers per node. An empty, non constant-time size [classref boost::intrusive::list list] +also has the size of 2 pointers. [classref boost::intrusive::list list] has many more constant-time operations than [classref boost::intrusive::slist slist] -and provides bidirectional iterator. It's recommendable to use use +and provides a bidirectional iterator. It is recommended to use [classref boost::intrusive::list list] instead of [classref boost::intrusive::slist slist] if the size overhead is acceptable: @@ -898,8 +933,8 @@ 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 know about value traits go to the section - titled [link intrusive.value_traits Containers with custom ValueTraits]. + 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` @@ -911,7 +946,7 @@ the section [link intrusive.usage How to use Boost.Intrusive]: [section:list_example Example] -Now let's see an small example using both hooks: +Now let's see a small example using both hooks: [import ../example/doc_list.cpp] [doc_list_code] @@ -939,7 +974,7 @@ An empty, non constant-time size [classref boost::intrusive::set set], has also the size of 3 pointers and an integer (3 pointers when optimized for size). These containers have logarithmic complexity in many operations like -searches, insertions, erasures, etc... [classref boost::intrusive::set set] and +searches, insertions, erasures, etc. [classref boost::intrusive::set set] and [classref boost::intrusive::multiset multiset] are the intrusive equivalents of standard `std::set` and `std::multiset` containers. @@ -1021,8 +1056,8 @@ These containers receive the same options explained in the section * [*`base_hook`] / [*`member_hook`] / [*`value_traits`]: To specify the hook type or value traits used - to configure the container (to know about value traits go to the section - titled [link intrusive.value_traits Containers with custom ValueTraits]. + 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` @@ -1040,7 +1075,7 @@ And they also can receive an additional option: [section:set_multiset_example Example] -Now let's see an small example using both hooks and both containers: +Now let's see a small example using both hooks and both containers: [import ../example/doc_set.cpp] [doc_set_code] @@ -1049,17 +1084,17 @@ Now let's see an small example using both hooks and both containers: [endsect] -[section:unordered_set_unordered_multiset Pseudo-Intrusive unordered associative containers: unordered_set, unordered_multiset] +[section:unordered_set_unordered_multiset Semi-Intrusive unordered associative containers: unordered_set, unordered_multiset] [*Boost.Intrusive] also offers hashed containers that can be very useful to implement fast-lookup containers. These containers ([classref boost::intrusive::unordered_set unordered_set] and [classref boost::intrusive::unordered_multiset unordered_multiset]) -are pseudo-intrusive containers: they need additional memory apart from the hook +are semi-intrusive containers: they need additional memory apart from the hook stored in the `value_type`. This additional memory must be passed in the constructor of the container. Unlike C++ TR1 unordered associative containers (which are also hashed containers), -the contents of these pseudo-intrusive containers are not rehashed to maintain a +the contents of these semi-intrusive containers are not rehashed to maintain a load factor: that would require memory management and intrusive containers don't implement any memory management at all. However, the user can request an explicit rehashing passing a new bucket array. @@ -1151,6 +1186,11 @@ Apart from them, these hooks offer additional options: rehashing is frequent or hashing the value is a slow operation. Default: `store_hash`. +* [*`optimize_multikey`]: This option reserves additional space in + the hook that will be used to group equal elements in unordered multisets, + improving significantly the performance when many equal values are inserted + in these containers. Default: `optimize_multikey`. + [endsect] [section:unordered_set_unordered_multiset_containers unordered_set and unordered_multiset containers] @@ -1201,8 +1241,8 @@ receive the same options explained in the section * [*`base_hook`] / [*`member_hook`] / [*`value_traits`]: To specify the hook type or value traits used - to configure the container (to know about value traits go to the section - titled [link intrusive.value_traits Containers with custom ValueTraits]. + 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` @@ -1210,7 +1250,7 @@ receive the same options explained in the section * [*`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 two additional options: +And they also can receive additional options: * [*`equal`]: Equality function for the objects to be inserted in containers. Default: `equal< std::equal_to >` @@ -1228,13 +1268,31 @@ And they also can receive two additional options: modulo operations and for some applications modulo operations can impose a considerable overhead. In debug mode an assertion will be raised if the user provides a bucket length that is not power of two. - Default: `constant_time_size`. + Default: `power_2_buckets`. + +* [*`cache_begin`]: Due to its internal structure, finding the first + element of an unordered container (`begin()` operation) is + amortized constant-time. It's possible to speed up `begin()` and other operations + related to it (like `clear()`) if the container caches internally the position + of the first element. This imposes the overhead of one pointer to the size + of the container. Default: `cache_begin`. + +* [*`compare_hash`]: + [*Note: this option requires `store_hash` option in the hook]. + When the comparison function is expensive, + (e.g. strings with a long common predicate) sometimes (specially when the + load factor is high or we have many equivalent elements in an + [classref boost::intrusive::unordered_multiset unordered_multiset] and + no `optimize_multikey<>` is activatedin the hook) + the equality function is a performance problem. Two equal values must have + equal hashes, so comparing the hash values of two elements before using the + comparison functor can speed up some implementations. [endsect] [section:unordered_set_unordered_multiset_example Example] -Now let's see an small example using both hooks and both containers: +Now let's see a small example using both hooks and both containers: [import ../example/doc_unordered_set.cpp] [doc_unordered_set_code] @@ -1277,9 +1335,9 @@ C++ associative containers are usually based on red-black tree implementations ( Boost.Intrusive associative containers). However, there are other interesting data structures that offer some advantages (and also disadvantages). -Splay trees are self-adjusting binary search trees used tipically in caches, memory +Splay trees are self-adjusting binary search trees used typically in caches, memory allocators and other applications, because splay trees have a "caching effect": recently -accessed elements have better access times that elements accessed less frequently. +accessed elements have better access times than elements accessed less frequently. For more information on splay trees see [@http://en.wikipedia.org/wiki/Splay_tree Wikipedia entry]. [*Boost.Intrusive] offers 3 containers based on splay trees: @@ -1291,23 +1349,23 @@ For more information on splay trees see [@http://en.wikipedia.org/wiki/Splay_tre that offers functions both to insert unique and multiple keys. The memory overhead of these containers with Boost.Intrusive hooks is usually 3 pointers. -An empty, non constant-time size splay container has also the size of 3 pointers. +An empty, non constant-time size splay container has also a size of 3 pointers. [section:splay_set_multiset_disadvantages Advantages and disadvantages of splay tree based containers] Splay tree based intrusive containers have logarithmic complexity in many -operations like searches, insertions, erasures, etc... but if some elements are +operations like searches, insertions, erasures, etc., but if some elements are more frequently accessed than others, splay trees perform faster searches than equivalent balanced binary trees (such as red-black trees). The caching effect offered by splay trees comes with a cost: the tree must be -rebalanced when a element is searched. This disallows const versions of search +rebalanced when an element is searched. This disallows const versions of search functions like `find()`, `lower_bound()`, `upper_bound()`, `equal_range()`, -`count()`... +`count()`, etc. Because of this, splay-tree based associative containers are not drop-in replacements of [classref boost::intrusive::set set]/ -[classref boost::intrusive::splay_set splay_set]. +[classref boost::intrusive::multiset multiset]. Apart from this, if element searches are randomized, the tree will be rebalanced without taking advantage of the cache effect, so splay trees can offer worse @@ -1376,8 +1434,8 @@ These containers receive the same options explained in the section * [*`base_hook`] / [*`member_hook`] / [*`value_traits`]: To specify the hook type or value traits used - to configure the container (to know about value traits go to the section - titled [link intrusive.value_traits Containers with custom ValueTraits]. + 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` @@ -1401,11 +1459,11 @@ Intrusive splay containers can also use plain binary search tree hooks These hooks can be used by other intrusive containers like intrusive scapegoat containers [classref boost::intrusive::sg_set sg_set] and -[classref boost::intrusive::sg_multiset sg_multiset] so a programmer +[classref boost::intrusive::sg_multiset sg_multiset]. A programmer might prefer using a binary search tree hook so that the same type -can be introduced in some situations in an splay container but that -can also be introduced in other compatible containers as well when -the hook is not being used in an splay container. +can be inserted in some situations in a splay container but +also inserted in other compatible containers when +the hook is not being used in a splay container. [classref boost::intrusive::bs_set_base_hook bs_set_base_hook] and [classref boost::intrusive::bs_set_base_hook bs_set_member_hook] admit @@ -1415,7 +1473,7 @@ the same options as [classref boost::intrusive::splay_set_base_hook splay_set_ba [section:splay_set_multiset_example Example] -Now let's see an small example using both splay hooks, +Now let's see a small example using both splay hooks, binary search tree hooks and [classref boost::intrusive::splay_set splay_set]/ [classref boost::intrusive::splay_multiset splay_multiset] @@ -1432,7 +1490,7 @@ containers: Similar to red-black trees, AVL trees are balanced binary trees. AVL trees are often compared with red-black trees because they support the same set of operations -and because red-black trees also take O(log n) time for the basic operations. +and because both take O(log n) time for basic operations. AVL trees are more rigidly balanced than Red-Black trees, leading to slower insertion and removal but faster retrieval, so AVL trees perform better than red-black trees for lookup-intensive applications. @@ -1453,7 +1511,7 @@ This size can be reduced to 3 pointers if pointers have 4 byte alignment An empty, non constant-time size [classref boost::intrusive::avl_set avl_set], [classref boost::intrusive::avl_multiset avl_multiset] or [classref boost::intrusive::avltree avltree] -has also the size of 3 pointers and an integer (3 pointers when optimized for size). +also has a size of 3 pointers and an integer (3 pointers when optimized for size). [section:avl_set_multiset_hooks avl_set, avl_multiset and avltree hooks] @@ -1524,8 +1582,8 @@ These containers receive the same options explained in the section * [*`base_hook`] / [*`member_hook`] / [*`value_traits`]: To specify the hook type or value traits used - to configure the container (to know about value traits go to the section - titled [link intrusive.value_traits Containers with custom ValueTraits]. + 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` @@ -1543,7 +1601,7 @@ And they also can receive an additional option: [section:avl_set_multiset_example Example] -Now let's see an small example using both hooks and +Now let's see a small example using both hooks and [classref boost::intrusive::avl_set avl_set]/ [classref boost::intrusive::avl_multiset avl_multiset] containers: @@ -1565,22 +1623,22 @@ time, scapegoat trees have no additional per-node overhead compared to a regular search tree. A binary search tree is said to be weight balanced if half the nodes are on the left -of the root, and half on the right. An α-height-balanced tree is defined with defined +of the root, and half on the right. An a-height-balanced tree is defined with defined with the following equation: -[*['height(tree) <= log1/α(tree.size())]] +[*['height(tree) <= log1/a(tree.size())]] -* [*['α == 1]]: A tree forming a linked list is considered balanced. -* [*['α == 0.5]]: Only a perfectly balanced binary is considered balanced. +* [*['a == 1]]: A tree forming a linked list is considered balanced. +* [*['a == 0.5]]: Only a perfectly balanced binary is considered balanced. -Scapegoat trees are loosely ['α-height-balanced] so: +Scapegoat trees are loosely ['a-height-balanced] so: -[*['height(tree) <= log1/α(tree.size()) + 1]] +[*['height(tree) <= log1/a(tree.size()) + 1]] -Scapegoat trees support any α between 0.5 and 1. If α is higher, the tree is rebalanced +Scapegoat trees support any a between 0.5 and 1. If a is higher, the tree is rebalanced less often, obtaining quicker insertions but slower searches. Lower -α values improve search times. Scapegoat-trees implemented in [*Boost.Intrusive] offer the possibility of -[*changing α at run-time] taking advantage of the flexibility of scapegoat trees. +a values improve search times. Scapegoat-trees implemented in [*Boost.Intrusive] offer the possibility of +[*changing a at run-time] taking advantage of the flexibility of scapegoat trees. For more information on scapegoat trees see [@http://en.wikipedia.org/wiki/Scapegoat_tree Wikipedia entry]. Scapegoat trees also have downsides: @@ -1591,7 +1649,7 @@ Scapegoat trees also have downsides: tree is also considerably increased. * The operations needed to determine if the tree is unbalanced require floating-point - operations like ['log1/α]. If the system has no floating point operations (like some + operations like ['log1/a]. If the system has no floating point operations (like some embedded systems), scapegoat tree operations might become slow. [*Boost.Intrusive] offers 3 containers based on scapegoat trees: @@ -1675,8 +1733,8 @@ These containers receive the same options explained in the section * [*`base_hook`] / [*`member_hook`] / [*`value_traits`]: To specify the hook type or value traits used - to configure the container (to know about value traits go to the section - titled [link intrusive.value_traits Containers with custom ValueTraits]. + to configure the container. (To learn about value traits go to the section + [link intrusive.value_traits Containers with custom ValueTraits].) * [*`size_type`]: To specify the type that will be used to store the size of the container. Default: `size_type` @@ -1689,16 +1747,16 @@ And they also can receive additional options: * [*`floating_point`]: When this option is deactivated, the scapegoat tree loses the ability to change - the balance factor α at run-time, but the size of an empty container is reduced + the balance factor a at run-time, but the size of an empty container is reduced and no floating point operations are performed, normally increasing container - performance. The fixed α factor that is used when this option is activated + performance. The fixed a factor that is used when this option is activated is ['1/sqrt(2) ~ 0,70711]. Default: `floating_point` [endsect] [section:sg_set_multiset_example Example] -Now let's see an small example using both hooks and +Now let's see a small example using both hooks and [classref boost::intrusive::sg_set sg_set]/ [classref boost::intrusive::sg_multiset sg_multiset] containers: @@ -1739,9 +1797,9 @@ containers. However, STL and TR1 ordered and unordered simple associative contai have some inefficiencies caused by the interface: the user can only operate with `value_type` objects. When using these containers we must use `iterator find(const value_type &value)` to find a value. The same happens in other functions -like `equal_range`, `lower_bound`, `upper_bound`... +like `equal_range`, `lower_bound`, `upper_bound`, etc. -However, sometimes the object to be searched it's quite expensive to construct: +However, sometimes the object to be searched is quite expensive to construct: [import ../example/doc_assoc_optimized_code.cpp] [doc_assoc_optimized_code_normal_find] @@ -1758,7 +1816,7 @@ equivalent one. Sometimes this interface limitation is severe, because we [*might not have enough information to construct the object] but we might -[*have enough information to find the object]. In this case, a name it's enough +[*have enough information to find the object]. In this case, a name is enough to search `Expensive` in the container but constructing an `Expensive` might require more information that the user might not have. @@ -1815,7 +1873,7 @@ will be discarded, and this is a waste of resources. Instead of that, let's use `insert_check` is similar to a normal `insert` but: * `insert_check` can be used with arbitrary keys -* if the insertion is possible (there is no equivalent value) collects all the needed information +* if the insertion is possible (there is no equivalent value) `insert_check` collects all the needed information in an `insert_commit_data` structure, so that `insert_commit`: * [*does not execute] further comparisons * can be executed with [*constant-time complexity] @@ -1824,7 +1882,7 @@ in an `insert_commit_data` structure, so that `insert_commit`: These functions must be used with care, since no other insertion or erasure must be executed between an `insert_check` and an `insert_commit` pair. Otherwise, the behaviour is undefined. -`insert_check` and `insert_commit` will come handy +`insert_check` and `insert_commit` will come in handy for developers programming efficient non-intrusive associative containers. See [classref boost::intrusive::set set] and [classref boost::intrusive::unordered_set unordered_set] reference for more information about @@ -1870,13 +1928,13 @@ object that will be called after the element has been erased from the container. With this function the user can efficiently remove and destroy elements if the disposer function destroys an object: `remove_and_dispose_if` -will call "disposer" function object for every removed element. [classref boost::intrusive::list list] offers +will call the "disposer" function object for every removed element. [classref boost::intrusive::list list] offers more functions taking a disposer function object as argument, like `erase_and_dispose`, `clear_and_dispose`, -`remove_and_dispose`... +`remove_and_dispose`, etc. Note that the disposing function does not need to just destroy the object. It can implement any other operation like inserting the remove object in another container. -Let's see an small example: +Let's see a small example: [import ../example/doc_erasing_and_disposing.cpp] [doc_erasing_and_disposing] @@ -1893,13 +1951,13 @@ that erase an element from the container. As previously mentioned, [*Boost.Intrusive] containers are [*non-copyable and non-assignable], because intrusive containers don't allocate memory at all. To implement a copy-constructor or assignment operator, the user must clone one by one all the elements of the container and insert them in another intrusive container. -However, cloning by hand is usually more inefficient than a member cloning function and an specialized cloning +However, cloning by hand is usually more inefficient than a member cloning function and a specialized cloning function can offer more guarantees than the manual cloning (better exception safety guarantees, for example). To ease the implementation of copy constructors and assignment operators of classes containing [*Boost.Intrusive] -containers, all [*Boost.Intrusive] containers offer an special cloning function called `clone_from`. +containers, all [*Boost.Intrusive] containers offer a special cloning function called `clone_from`. -Apart from the container to be cloned, `clone_from` takes two function objects as arguments. For example, the +Apart from the container to be cloned, `clone_from` takes two function objects as arguments. For example, consider the `clone_from` member function of [classref boost::intrusive::list list]: [c++] @@ -1918,8 +1976,8 @@ This function will make `*this` a clone of `src`. Let's explain the arguments: The cloning function works as follows: -* First clears and disposes all the elements from *this using the disposer function object. -* After that starts cloning all the elements of the source container using the cloner function object. +* First it clears and disposes all the elements from *this using the disposer function object. +* After that it starts cloning all the elements of the source container using the cloner function object. * If any operation in the cloning function (for example, the cloner function object) throws, all the constructed elements are disposed using the disposer function object. @@ -1934,9 +1992,9 @@ Here's an example of `clone_from`: [section:using_smart_pointers Using smart pointers with Boost.Intrusive containers] [*Boost.Intrusive] hooks can be configured to use other pointers than raw pointers. -When a [*Boost.Intrusive] hook is configured with an smart pointer as an argument, +When a [*Boost.Intrusive] hook is configured with a smart pointer as an argument, this pointer configuration is passed to the containers. For example, if the following -hook is configured with an smart pointer (for example, an offset pointer from +hook is configured with a smart pointer (for example, an offset pointer from [*Boost.Interprocess]): [import ../example/doc_offset_ptr.cpp] @@ -1951,7 +2009,7 @@ and [*Boost.Intrusive]: [section:smart_pointers_requirements Requirements for smart pointers compatible with Boost.Intrusive] -Not every smart pointer is compatible with [*Boost.Intrusive], the smart pointer must +Not every smart pointer is compatible with [*Boost.Intrusive]; the smart pointer must have the following features: * It must support the same operations as a raw pointer, except casting. @@ -1961,7 +2019,7 @@ have the following features: The conversion from the smart pointer to a raw pointer must be implemented following Boost smart pointer `detail::get_pointer()` function. This function will be found using -ADL. For example, for `boost::interprocess::offset_ptr` `detail::get_pointer` is defined +ADL. For example, for `boost::interprocess::offset_ptr`, `detail::get_pointer` is defined as follows: [c++] @@ -2009,11 +2067,11 @@ On the other hand, `local_iterator_to` functions have their `s_local_iterator_to` static alternatives. Alternative static functions are available under certain circunstances -explained in the [link intrusive.value_traits.stateful_value_traits Stateful value traits] section, -but the programmer uses hooks provided by [*Boost.Intrusive], those functions +explained in the [link intrusive.value_traits.stateful_value_traits Stateful value traits] section; +if the programmer uses hooks provided by [*Boost.Intrusive], those functions will be available. -Let's see an small function that shows the use of `iterator_to` and +Let's see a small function that shows the use of `iterator_to` and `local_iterator_to`: [import ../example/doc_iterator_from_value.cpp] @@ -2021,6 +2079,51 @@ Let's see an small function that shows the use of `iterator_to` and [endsect] +[section:any_hooks Any Hooks: A single hook for any Intrusive container] + +Sometimes, a class programmer wants to place a class in several intrusive +containers but no at the same time. In this case, the programmer might +decide to insert two hooks in the same class. + +[c++] + + class MyClass + : public list_base_hook<>, public slist_base_hook<> //... + {}; + +However, there is a more size-efficient alternative in [*Boost.Intrusive]: "any" hooks +([classref boost::intrusive::any_base_hook any_base_hook] and +[classref boost::intrusive::any_member_hook any_member_hook]. +These hooks can be used to store a type in several containers +offered by [*Boost.Intrusive] minimizing the size of the class. + +These hooks support these options: + +* [*`tag`] (for base hooks only): This argument serves as a tag, + so you can derive from more than one slist hook. + Default: `tag`. + +* [*`link_mode`]: The linking policy. + `link_mode` is [*not] supported and `link_mode` + might offer weaker error detection in any hooks than in other hooks. + Default: `link_mode`. + +* [*`void_pointer`]: The pointer type to be used + internally in the hook and propagated to the container. + Default: `void_pointer`. + +`auto_unlink` can't be supported because the hook does not know in which type of might +be inserted container. Additionally, these hooks don't support `unlink()` and +`swap_nodes()` operations for the same reason. + +Here's an example that creates a class with two any hooks, and uses one to insert the +class in a [classref slist] and the other one in a [classref list]. + +[import ../example/doc_any_hook.cpp] +[doc_any_hook] + +[endsect] + [section:concepts Concepts explained] This section will expand the explanation of previously presented basic concepts @@ -2028,11 +2131,11 @@ before explaining the customization options of [*Boost.Intrusive]. * [*Node Algorithms]: A set of static functions that implement basic operations on a group of nodes: initialize a node, link_mode_type a node to a group of nodes, - unlink a node from another group of nodes... For example, a circular + unlink a node from another group of nodes, etc. For example, a circular singly linked list is a group of nodes, where each node has a pointer to the next node. [*Node Algorithms] just require a [*NodeTraits] template parameter and they can work with any [*NodeTraits] class that fulfills - the needed interface. As an example, here is a class that implements algorithms + the needed interface. As an example, here is a class that implements operations7' to manage a group of nodes forming a circular singly linked list: [c++] @@ -2069,11 +2172,11 @@ before explaining the customization options of [*Boost.Intrusive]. }; * [*Node Traits]: A class that encapsulates the basic information and - operations on a node that forms a group of nodes: - the type of the node, a function to obtain the pointer to the next node... - [*Node Traits] are the configuration information [*Node Algorithms] - need. Each type of [*Node Algorithms] expects an interface that compatible - [*Node Traits] must implement. + operations on a node within a group of nodes: + the type of the node, a function to obtain the pointer to the next node, etc. + [*Node Traits] specify the configuration information [*Node Algorithms] + need. Each type of [*Node Algorithm] expects an interface that compatible + [*Node Traits] classes must implement. As an example, this is the definition of a [*Node Traits] class that is compatible with the previously presented `my_slist_algorithms`: @@ -2102,7 +2205,7 @@ before explaining the customization options of [*Boost.Intrusive]. * [*Hook]: A class that the user must add as a base class or as a member to his own class to make that class insertable in an intrusive container. Usually the hook - contains a node object, that will be used to form the group of nodes: + contains a node object that will be used to form the group of nodes: For example, the following class is a [*Hook] that the user can add as a base class, to make the user class compatible with a singly linked list container: @@ -2140,11 +2243,11 @@ before explaining the customization options of [*Boost.Intrusive]. int value_; }; -* [*Intrusive Container]: A container that offers an STL-like interface to store +* [*Intrusive Container]: A container that offers a STL-like interface to store user objects. An intrusive container can be templatized to store different - value types that use different hooks. An intrusive container is also more elaborated + value types that use different hooks. An intrusive container is also more elaborate than a group of nodes: it can store the number of elements to achieve constant-time - size information, it can offer debugging facilities... + size information, it can offer debugging facilities, etc. For example, an [classref boost::intrusive::slist slist] container (intrusive singly linked list) should be able to hold `MyClass` objects that might have decided to store the hook @@ -2176,7 +2279,7 @@ before explaining the customization options of [*Boost.Intrusive]. // ... }; -* [*Pseudo-Intrusive Container]: A pseudo-intrusive container is similar to an +* [*Semi-Intrusive Container]: A semi-intrusive container is similar to an intrusive container, but apart from the values to be inserted in the container, it needs additional memory (for example, auxiliary arrays or indexes). @@ -2336,7 +2439,7 @@ members of the [classref boost::intrusive::rbtree_algorithms rbtree_algorithms] An empty tree is formed by a node whose pointer to the parent node is null, -the pointers to the left and right nodes to itself and whose color is red. +the left and right node pointers point to itself, and whose color is red. [classref boost::intrusive::rbtree_algorithms rbtree_algorithms] is configured with a NodeTraits class, which encapsulates the information about the node to be manipulated. NodeTraits must support the @@ -2407,7 +2510,7 @@ members of the [classref boost::intrusive::splaytree_algorithms splaytree_algori An empty tree is formed by a node whose pointer to the parent node is null, -the pointers to the left and right nodes to itself. +and whose left and right nodes pointers point to itself. [classref boost::intrusive::splaytree_algorithms splaytree_algorithms] is configured with a NodeTraits class, which encapsulates the information about the node to be manipulated. NodeTraits must support the @@ -2523,6 +2626,63 @@ For a complete list of functions see [endsect] +[/ +/ +/[section:sgtree_algorithms Intrusive sg tree algorithms] +/ +/ +/[classref boost::intrusive::sgtree_algorithms sgtree_algorithms] have the same +/interface as [classref boost::intrusive::rbtree_algorithms rbtree_algorithms]. +/ +/[c++] +/ +/ template +/ struct sgtree_algorithms; +/ +/[classref boost::intrusive::sgtree_algorithms sgtree_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 sgtree +/ +/* `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_sgtree_algorithms.cpp] +/[doc_sgtree_algorithms_code] +/ +/For a complete list of functions see +/[classref boost::intrusive::sgtree_algorithms sgtree_algorithms reference]. +/ +/[endsect] +/] [endsect] [section:value_traits Containers with custom ValueTraits] @@ -2534,11 +2694,11 @@ or implicitly configured (using hooks and their `base_hook<>`/`member_hook<>` op `ValueTraits` contains all the information to glue the `value_type` of the containers and the node to be used in node algorithms, since these types can be different. Apart from this, -`ValueTraits` also store information about the link policy of the values to be inserted. +`ValueTraits` also stores information about the link policy of the values to be inserted. Instead of using [*Boost.Intrusive] predefined hooks a user might want to develop customized containers, for example, using nodes that are -optimized for an specific +optimized for a specific application or that are compatible with a a legacy ABI. A user might want to have only two additional pointers in his class and insert the class in a doubly linked list sometimes and in a singly linked list in other situations. You can't @@ -2548,7 +2708,7 @@ achieve this using [*Boost.Intrusive] predefined hooks. Now, instead of using [section:value_traits_interface ValueTraits interface] -`ValueTraits` have the following interface: +`ValueTraits` has the following interface: [c++] @@ -2574,9 +2734,9 @@ achieve this using [*Boost.Intrusive] predefined hooks. Now, instead of using Let's explain each type and function: -* [*['node_traits]]: The node configuration that it's needed by node algorithms. +* [*['node_traits]]: The node configuration that is needed by node algorithms. These node traits and algorithms are - described in the previous chapter: [link intrusive.node_algorithms Nodes Algorithms]. + described in the previous chapter: [link intrusive.node_algorithms Node Algorithms]. * If my_value_traits is meant to be used with [classref boost::intrusive::slist slist], `node_traits` should follow @@ -2604,13 +2764,13 @@ Let's explain each type and function: same type, the `to_node_ptr` and `to_value_ptr` functions are trivial. * [*['pointer]]: The type of a pointer to a `value_type`. It must be the same pointer type - as `node_ptr`: If `node_ptr` is `node *` `pointer` must be `value_type*`. If + as `node_ptr`: If `node_ptr` is `node*`, `pointer` must be `value_type*`. If `node_ptr` is `smart_ptr`, `pointer` must be `smart_ptr`. This can be generically achieved using `boost::pointer_to_other` utility from [*Boost SmartPointers] defined in ``. * [*['const_pointer]]: The type of a pointer to a `const value_type`. It must be the same pointer type - as `node_ptr`: If `node_ptr` is `node *` `const_pointer` must be `const value_type*`. If + as `node_ptr`: If `node_ptr` is `node*`, `const_pointer` must be `const value_type*`. If `node_ptr` is `smart_ptr`, `const_pointer` must be `smart_ptr` This can be generically achieved using `boost::pointer_to_other` utility from [*Boost SmartPointers] defined in ``. @@ -2620,32 +2780,31 @@ Let's explain each type and function: These are the possible types: * [*`normal_link`]: If this linking policy is specified in a `ValueTraits` class - as the link, containers + as the link mode, containers configured with such `ValueTraits` won't set the hooks of the erased values to a default state. Containers also won't check that the hooks of the new values are default initialized. - normal_link, - * [*`safe_link`]: If this linking policy is specified in a `ValueTraits` class - as the link, containers - configured with such `ValueTraits` will set the hooks + * [*`safe_link`]: If this linking policy is specified as the link mode + in a `ValueTraits` class, containers + configured with this `ValueTraits` will set the hooks of the erased values to a default state. Containers also will check that the hooks of the new values are default initialized. * [*`auto_unlink`]: Same as "safe_link" but containers with constant-time size features won't be compatible with `ValueTraits` configured with this policy. - Containers also know that the a value can be silently erased from + Containers also know that a value can be silently erased from the container without using any function provided by the containers. * [*['static node_ptr to_node_ptr (value_type &value)]] and [*['static const_node_ptr to_node_ptr (const value_type &value)]]: - These function take a reference to a value_type and return a pointer to the node + These functions take a reference to a value_type and return a pointer to the node to be used with node algorithms. * [*['static pointer to_value_ptr (node_ptr n)]] and [*['static const_pointer to_value_ptr (const_node_ptr n)]]: - These function take a pointer to a node and return a pointer to the value + These functions take a pointer to a node and return a pointer to the value that contains the node. [endsect] @@ -2657,7 +2816,7 @@ containers with an old C structure whose definition can't be changed. That legacy type has two pointers that can be used to build singly and doubly linked lists: in singly linked lists we only need a pointer, whereas in doubly linked lists, we need two pointers. Since we only have two pointers, we can't insert -the object in a singly and doubly linked list at the same time. +the object in both a singly and a doubly linked list at the same time. This is the definition of the old node: [import ../example/doc_value_traits.cpp] @@ -2669,7 +2828,7 @@ we'll define a ValueTraits class that will configure [*Boost.Intrusive] containe [doc_value_traits_value_traits] -Defining a value traits class that just defines `value_type` as +Defining a value traits class that simply defines `value_type` as `legacy_node_traits::node` is a common approach when defining customized intrusive containers, so [*Boost.Intrusive] offers a templatized [classref boost::intrusive::trivial_value_traits trivial_value_traits] class @@ -2690,7 +2849,7 @@ a little test: [doc_value_traits_test] As seen, several key elements of [*Boost.Intrusive] can be reused with custom user types, -if the user does not want to use provided [*Boost.Intrusive] facilities. +if the user does not want to use the provided [*Boost.Intrusive] facilities. [endsect] @@ -2701,7 +2860,7 @@ In the previous example, `legacy_node_traits::node` type and to have several `ValueTraits` defining the same `node_traits` type (and thus, the same `node_traits::node`). This reduces the number of node algorithm instantiations, but now `ValueTraits::to_node_ptr` and `ValueTraits::to_value_ptr` functions need to offer -conversions between both types. Let's see an small example: +conversions between both types. Let's see a small example: First, we'll define the node to be used in the algorithms. For a linked list, we just need a node that stores two pointers: @@ -2710,7 +2869,7 @@ we just need a node that stores two pointers: [doc_advanced_value_traits_code] Now we'll define two different types that will be inserted in intrusive lists and -we'll define a templatized `ValueTraits` that will work for both types: +a templatized `ValueTraits` that will work for both types: [doc_advanced_value_traits_value_traits] @@ -2721,7 +2880,7 @@ due to the fact that the value traits used to define the containers provide the [doc_advanced_value_traits_containers] All [*Boost.Intrusive] containers using predefined hooks use this technique to minimize code size: -all the possible [classref boost::intrusive::list list] containers +all possible [classref boost::intrusive::list list] containers created with predefined hooks that define the same `VoidPointer` type share the same list algorithms. @@ -2729,7 +2888,7 @@ share the same list algorithms. [section:simplifying_value_traits Simplifying value traits definition] -The previous example can be further simplified using +The previous example can be further simplified using the [classref boost::intrusive::derivation_value_traits derivation_value_traits] class to define a value traits class with a value that stores the `simple_node` as a base class: @@ -2765,8 +2924,8 @@ to define the needed value traits classes: Until now all shown custom value traits are stateless, that is, [*the transformation between nodes and values is implemented in terms of static functions]. It's possible to use [*stateful] value traits -so that we can even separate nodes and values and [*avoid modifying types to insert nodes]. -[*Boost.Intrusive] differentiates between stateful and stateless value traits checking if the ValueTraits +so that we can separate nodes and values and [*avoid modifying types to insert nodes]. +[*Boost.Intrusive] differentiates between stateful and stateless value traits by checking if the ValueTraits class is empty: * If the class is empty, a [*stateless] value traits is assumed. @@ -2776,20 +2935,20 @@ class is empty: Using stateful value traits it's possible to create containers of non-copyable/moveble objects [*without modifying] the definition of the class to be inserted. This interesting property is achieved without using global variables -(stateless value traits could use global variables to achieve the same property), so: +(stateless value traits could use global variables to achieve the same goal), so: * [*Thread-safety guarantees]: Better thread-safety guarantees can be achieved with stateful - value traits, since accessing to global resources might require syncronization primitives that - can be avoided when using the internal state. + value traits, since accessing global resources might require syncronization primitives that + can be avoided when using internal state. * [*Flexibility]: A stateful value traits type can be configured at run-time. -* [*Run-time polimorphism]: A value traits might implement node <-> value +* [*Run-time polymorphism]: A value traits might implement node <-> value transformations as virtual functions. A single container type could be configured at run-time to use different node <-> value relatioships. Stateful value traits have many advantages but also some downsides: * [*Performance]: Value traits operations should be very efficient since they are basic operations used by containers. - [*A heavy node <-> value transformation can downgrade intrusive containers' performance]. + [*A heavy node <-> value transformation will hurt intrusive containers' performance]. * [*Exception guarantees]: The stateful ValueTraits must maintain no-throw guarantees, otherwise, the container invariants won't be preserved. * [*Static functions]: Some static functions offered by intrusive containers are not @@ -2810,31 +2969,31 @@ in a list guaranteeing no additional allocation apart from the initial resource [section:thread_safety Thread safety guarantees] -Intrusive containers have similar same thread-safety guarantees than STL containers. +Intrusive containers have thread safety guarantees similar to STL containers. -* Several threads can have read or write access to different instances is safe as long as inserted +* Several threads having read or write access to different instances is safe as long as inserted objects are different. * Concurrent read-only access to the same container is safe. Some Intrusive hooks (auto-unlink hooks, for example) modify containers without having a reference to them: this is considered a write access to the container. -Other functions, like checking if an objects is already inserted in a containers using the `is_linked()` -member of safe hooks is a read-access to the container without having a reference to them, so no other +Other functions, like checking if an object is already inserted in a container using the `is_linked()` +member of safe hooks, constitute read access on the container without having a reference to it, so no other thread should have write access (direct or indirect) to that container. Since the same object can be inserted in several containers at the same time using different hooks, -the thread safety of [*Boost.Intrusive] is related to the containers and also the object whose lifetime +the thread safety of [*Boost.Intrusive] is related to the containers and also to the object whose lifetime is manually managed by the user. As we can see, the analysis of the thread-safety of a program using [*Boost.Intrusive] is harder than with non-intrusive containers. -To analyze the thread-safety, take in care the following points: +To analyze the thread safety, consider the following points: -* Auto-unlink hook's destructor and `unlink()` functions modify the container indirectly. -* Safe mode and auto-unlink hook's `is_linked()` function is a read access to the container. -* Inserting an object in several containers that will be modified by different threads has no thread-safety +* The auto-unlink hook's destructor and `unlink()` functions modify the container indirectly. +* The safe mode and auto-unlink hooks' `is_linked()` functions are a read access to the container. +* Inserting an object in containers that will be modified by different threads has no thread safety guarantee, although in most platforms it will be thread-safe without locking. [endsect] @@ -2842,12 +3001,12 @@ To analyze the thread-safety, take in care the following points: [section:obtaining_same_type_reducing_space Obtaining the same types and reducing symbol length] The flexible option specification mechanism used by [*Boost.Intrusive] for hooks and containers -has also a couple of downsides: +has a couple of downsides: -* If a user specifies the same options in different order or specifies some options and lefts the - rest as defaults the type of the created container/hook will be different. Sometimes - this is annoying, because two programmers specifying the same options might end with incompatible - types. For example, the following two lists, although they're using the same options, have not +* If a user specifies the same options in different order or specifies some options and leaves the + rest as defaults, the type of the created container/hook will be different. Sometimes + this is annoying, because two programmers specifying the same options might end up with incompatible + types. For example, the following two lists, although using the same options, do not have the same type: [c++] @@ -2865,12 +3024,12 @@ has also a couple of downsides: * Option specifiers lead to long template symbols for classes and functions. Option specifiers themselves are verbose and without variadic templates, several default template parameters are assigned for non-specified options. Object and debugging information files can grow and compilation times - might suffer a bit if long names are produced. + may suffer if long names are produced. -To solve these issues [*Boost.Intrusive] offers some helper metafunctions that that reduce symbol lengths -and create the same type if the same options (either explicitly or implicitly) are used. This also -improves compilation times. All containers and hooks have their respective `make_xxx` versions. -Previous shown example can be rewritten like this to obtain the same list type: +To solve these issues [*Boost.Intrusive] offers some helper metafunctions that reduce symbol lengths +and create the same type if the same options (either explicitly or implicitly) are used. These also +improve compilation times. All containers and hooks have their respective `make_xxx` versions. +The previously shown example can be rewritten like this to obtain the same list type: [c++] @@ -2888,8 +3047,8 @@ Previous shown example can be rewritten like this to obtain the same list type: //Implicitly specify constant-time size and size type typedef make_list::type List2; -Produced symbol lengths and compilation times are usually shorter and object/debug files are smaller. -If you are a programmer concerned with file sizes and compilation times, this option is your choice. +Produced symbol lengths and compilation times will usually be shorter and object/debug files smaller. +If you are concerned with file sizes and compilation times, this option is your best choice. [endsect] @@ -2918,26 +3077,26 @@ and following this guideline [*Boost.Intrusive] separates node algorithms and intrusive containers to avoid instantiating node algorithms for each user type. For example, a single class of red-black algorithms will be instantiated to implement all set and multiset containers using raw pointers. This way, -[*Boost.Intrusive] wants to avoid any code size overhead associated with templates. +[*Boost.Intrusive] seeks to avoid any code size overhead associated with templates. Apart from that, [*Boost.Intrusive] implements some size improvements: for example, red-black trees embed the color bit in the parent pointer lower bit, if nodes -are two-byte aligned. The possibility to avoid constant-time size operations can -save some size on containers, and this extra size optimization is noticeable +are two-byte aligned. The option to forgo constant-time size operations can +reduce container size, and this extra size optimization is noticeable when the container is empty or contains few values. [endsect] -[section: Boost.Intrusive as basic building block] +[section: Boost.Intrusive as a basic building block] -[*Boost.Intrusive] should be a basic building block to build more complex containers -and this guideline has motivated many design decisions. For example, the possibility -to have more than one hook per user type opens the possibility to implement multi-index +[*Boost.Intrusive] can be a basic building block to build more complex containers +and this potential has motivated many design decisions. For example, the ability +to have more than one hook per user type opens the opportunity to implement multi-index containers on top of [*Boost.Intrusive]. [*Boost.Intrusive] containers implement advanced functions taking function objects -as arguments (`clone_from`, `erase_and_dispose`, `insert_check`...). These -functions come handy when implementing non-intrusive containers +as arguments (`clone_from`, `erase_and_dispose`, `insert_check`, etc.). These +functions come in handy when implementing non-intrusive containers (for example, STL-like containers) on top of intrusive containers. [endsect] @@ -2947,9 +3106,9 @@ functions come handy when implementing non-intrusive containers [*Boost.Intrusive] offers a wide range of containers but also allows the construction of custom containers reusing [*Boost.Intrusive] elements. The programer might want to use node algorithms directly or -build special hooks that take advantage of its application environment. +build special hooks that take advantage of an application environment. -For example, the programmer can use can customize parts of [*Boost.Intrusive] +For example, the programmer can customize parts of [*Boost.Intrusive] to manage old data structures whose definition can't be changed. [endsect] @@ -2958,25 +3117,25 @@ to manage old data structures whose definition can't be changed. [section:performance Performance] -[*Boost.Intrusive] containers offer speed improvements comparing to non-intrusive containers, -basically because: +[*Boost.Intrusive] containers offer speed improvements compared to non-intrusive containers +primarily because: -* We can minimize memory allocation/deallocation calls. -* We obtain better memory locality. +* They minimize memory allocation/deallocation calls. +* They obtain better memory locality. -This section will show some performance tests comparing some operations on +This section will show performance tests comparing some operations on `boost::intrusive::list` and `std::list`: * Insertions using `push_back` and container destruction will show the overhead associated with memory allocation/deallocation. -* `reverse` member function will show the advantages of the compact +* The `reverse` member function will show the advantages of the compact memory representation that can be achieved with intrusive containers. -* `sort` and `write access` tests will show the advantage of intrusive containers - minimizing the memory accesses when comparing them with containers of pointers. +* The `sort` and `write access` tests will show the advantage of intrusive containers + minimizing memory accesses compared to containers of pointers. Given an object of type `T`, [classref boost::intrusive::list boost::intrusive::list] can replace `std::list` to avoid memory allocation overhead, -or it can replace `std::list` when the user wants to obtain containers with +or it can replace `std::list` when the user wants containers with polymorphic values or wants to share values between several containers. Because of this versatility, the performance tests will be executed for 6 different list types: @@ -3008,7 +3167,7 @@ is just a class that has a base hook ([classref boost::intrusive::list_base_hook and also derives from `test_class`. `func_ptr_adaptor` is just a functor adaptor to convert function objects taking -`test_list` objects to funtion objects taking pointers to them. +`test_list` objects to function objects taking pointers to them. You can find the full test code code in the [@../../libs/intrusive/perf/perf_list.cpp perf_list.cpp] source file. @@ -3016,9 +3175,9 @@ You can find the full test code code in the [section:performance_results_push_back Back insertion and destruction] The first test will measure the benefits we can obtain with intrusive containers -avoiding memory allocations and deallocations . All the objects to be +avoiding memory allocations and deallocations. All the objects to be inserted in intrusive containers are allocated in a single allocation call, -whereas `std::list` will need to allocate memory for every and deallocate it +whereas `std::list` will need to allocate memory for each object and deallocate it for every erasure (or container destruction). Let's compare the code to be executed for each container type for different insertion tests: @@ -3076,35 +3235,35 @@ These are the times in microseconds for each case, and the normalized time: The results are logical: intrusive lists just need one allocation. The destruction time of the `normal_link` intrusive container is trivial (complexity: `O(1)`), -whereas `safe_link` and `auto_unlink` intrusive containers need to put the hook of -erased values' in the default state (complexity: `O(NumElements)`). That's why +whereas `safe_link` and `auto_unlink` intrusive containers need to put the hooks of +erased values in the default state (complexity: `O(NumElements)`). That's why `normal_link` intrusive list shines in this test. -Non-intrusive containers need to make much more allocations and that's why they are -lagging behind. The `disperse pointer list` needs to make `NumElements*2` allocations, +Non-intrusive containers need to make many more allocations and that's why they +lag behind. The `disperse pointer list` needs to make `NumElements*2` allocations, so the result is not surprising. -Linux test shows that standard containers perform very well against intrusive containers -with big objects. Nearly the same GCC version in MinGW performs worse, so maybe the -a good memory allocator is the reason for these excelent results. +The Linux test shows that standard containers perform very well against intrusive containers +with big objects. Nearly the same GCC version in MinGW performs worse, so maybe +a good memory allocator is the reason for these excellent results. [endsect] [section:performance_results_reversing Reversing] The next test measures the time needed to complete calls to the member function `reverse()`. -Values (`test_class` and `itest_class`) and lists are created like explained in the +Values (`test_class` and `itest_class`) and lists are created as explained in the previous section. Note that for pointer lists, `reverse` [*does not need to access `test_class` values stored in another list or vector], -since this function just needs to adjust internal pointers, so in theory, all tested +since this function just needs to adjust internal pointers, so in theory all tested lists need to perform the same operations. These are the results: [table Reverse times for Visual C++ 7.1 / Windows XP - [[Container] [Time in us/iteration (small object / big object)] [Normalized time (small object / big object) (small object / big object)]] + [[Container] [Time in us/iteration (small object / big object)] [Normalized time (small object / big object)]] [[`normal_link` intrusive list] [2656 / 10625] [1 / 1.83]] [[`safe_link` intrusive list] [2812 / 10937] [1.05 / 1.89]] [[`auto_unlink` intrusive list] [2710 / 10781] [1.02 / 1.86]] @@ -3156,18 +3315,18 @@ in the code: l.push_back(&objects.back()); } -For big values the compact pointer list wins because when reversing doesn't need access -to the values stored in another container. Since all the allocations for nodes of -this pointer list are likely to be near (since there is no other allocation in the +For big objects the compact pointer list wins because the reversal test doesn't need access +to values stored in another container. Since all the allocations for nodes of +this pointer list are likely to be close (since there is no other allocation in the process until the pointer list is created) locality is better than with intrusive -containers. The dispersed pointer list, like with small values, has poor locality. +containers. The dispersed pointer list, as with small values, has poor locality. [endsect] [section:performance_results_sorting Sorting] -The next test measures the time needed to complete calls the member function -`sort(Pred pred)`. Values (`test_class` and `itest_class`) and lists are created like explained in the +The next test measures the time needed to complete calls to the member function +`sort(Pred pred)`. Values (`test_class` and `itest_class`) and lists are created as explained in the first section. The values will be sorted in ascending and descenting order each iteration. For example, if ['l] is a list: @@ -3194,7 +3353,7 @@ For a pointer list, the function object will be adapted using `func_ptr_adaptor` Note that for pointer lists, `sort` will take a function object that [*will access `test_class` values stored in another list or vector], so pointer lists will suffer an extra indirection: they will need to access the `test_class` values stored in -another container to compare to elements. +another container to compare two elements. These are the results: @@ -3231,16 +3390,16 @@ These are the results: The results show that intrusive containers are faster than standard containers. We can see that the pointer list holding pointers to values stored in a vector is quite fast, so the extra -indirection that needs to access the value is minimized because all the values -are tightly stored, improving cache. The disperse list, on the other hand, is -slower because the indirection to access to values stored in the object list is -more expensive than the access to values stored in a vector. +indirection that is needed to access the value is minimized because all the values +are tightly stored, improving caching. The disperse list, on the other hand, is +slower because the indirection to access values stored in the object list is +more expensive than accessing values stored in a vector. [endsect] [section:performance_results_write_access Write access] -The next test measures the time needed to iterate all the elements of a list, and +The next test measures the time needed to iterate through all the elements of a list, and increment the value of the internal `i_` member: [c++] @@ -3249,7 +3408,7 @@ increment the value of the internal `i_` member: for(; it != end; ++it) ++(it->i_); -Values (`test_class` and `itest_class`) and lists are created like explained in +Values (`test_class` and `itest_class`) and lists are created as explained in the first section. Note that for pointer lists, the iteration will suffer an extra indirection: they will need to access the `test_class` values stored in another container: @@ -3292,9 +3451,9 @@ These are the results: [[Standard disperse pointer list] [6118 / 12453] [2.67 / 1.62]] ] -Like with the read access test, the results show that intrusive containers outperform +As with the read access test, the results show that intrusive containers outperform all other containers if the values are tightly packed in a vector. -The disperse list is again the slowest one. +The disperse list is again the slowest. [endsect] @@ -3302,7 +3461,7 @@ The disperse list is again the slowest one. Intrusive containers can offer performance benefits that can not be achieved with equivalent non-intrusive containers. Memory locality improvements are noticeable -when objects to be inserted are small. Minimizing memory allocation/deallocation calls is also +when the objects to be inserted are small. Minimizing memory allocation/deallocation calls is also an important factor and intrusive containers make this simple if the user allocates all the objects to be inserted in intrusive containers in containers like `std::vector` or `std::deque`. @@ -3310,41 +3469,41 @@ all the objects to be inserted in intrusive containers in containers like `std:: [endsect] -[section:disabling_exceptions Disabling exceptions support] +[section:release_notes Release Notes] -[*Boost.Intrusive] might be useful in environments where exceptions are not available -or recommendable (like embedded or real-time systems). [*Boost.Intrusive] uses the -global Boost mechanism to disable exception handling, so that if the compiler -configuration disables exceptions, `BOOST_NO_EXCEPTIONS` is defined and exception -handling is disabled. +[section:release_notes_boost_1_36_00 Boost 1.36 Release] -This mechanism is a global mechanism to disable exceptions. If for any reason, -the user wants to disable exception handling [*only] in [*Boost.Intrusive], -`BOOST_INTRUSIVE_DISABLE_EXCEPTION_HANDLING` can be defined to disable -exception handling in the library. +* Added `linear<>` and `cache_last<>` options to singly linked lists. +* Added `optimize_multikey<>` option to unordered container hooks. +* Optimized unordered containers when `store_hash` option is used in the hook. +* Implementation changed to be exception agnostic so that it can be used + in environments without exceptions. +* Added `container_from_iterator` function to tree-based containers. + +[endsect] [endsect] [section:tested_compilers Tested compilers] -[*Boost.Intrusive] has been tested in the following compilers/platforms: +[*Boost.Intrusive] has been tested on the following compilers/platforms: * Visual 7.1/WinXP * Visual 8.0/WinXP +* Visual 9.0/WinXP * GCC 4.1.1/MinGW * GCC 3.4.4/Cygwin * Intel 9.1/WinXP * GCC 4.1.2/Linux * GCC 3.4.3/Solaris 11 * GCC 4.0/Mac Os 10.4.1 -* SunCC 5.8/Solaris 11 [endsect] [section:references References] * SGI's [@http://www.sgi.com/tech/stl/ STL Programmer's Guide]. - [*Boost.Intrusive] is based on STL concepts and interface. + [*Boost.Intrusive] is based on STL concepts and interfaces. * Dr. Dobb's, September 1, 2005: [@http://www.ddj.com/architect/184402007 ['Implementing Splay Trees in C++] ]. [*Boost.Intrusive] splay containers code is based on this article. @@ -3369,16 +3528,16 @@ helpful discussions. * [*Olaf Krzikalla] for the permission to continue his great work. -* [*Joaquín M. López Muñoz] for his thorough review, help, and ideas. +* [*Joaquin M. Lopez Munoz] for his thorough review, help, and ideas. * [*Cory Nelson], [*Daniel James], [*Dave Harris], [*Guillaume Melquiond], - [*Henri Bavestrello], [*Hervé Brönnimann], [*Kai Brüning], [*Kevin Sopp], + [*Henri Bavestrello], [*Hervé Bronnimann], [*Kai Bruning], [*Kevin Sopp], [*Paul Rose], [*Pavel Vozelinek], [*Howard Hinnant], [*Olaf Krzikalla], [*Samuel Debionne], [*Stjepan Rajko], [*Thorsten Ottosen], [*Tobias Schwinger], [*Tom Brinkman] and [*Steven Watanabe] for their comments and reviews in the Boost.Intrusive formal review. -* Thanks to of [*Julienne Walker] and [*The EC Team] ([@http://eternallyconfuzzled.com]) +* Thanks to [*Julienne Walker] and [*The EC Team] ([@http://eternallyconfuzzled.com]) for their great algorithms. * Thanks to [*Daniel K. O.] for his AVL tree rebalancing code. diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 75ef95a..cfd371d 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -1,6 +1,6 @@ # Boost Intrusive Library Example Jamfile -# (C) Copyright Ion Gaztañaga 2006-2007. +# (C) Copyright Ion Gaztanaga 2006-2007. # Use, modification and distribution are subject to 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) diff --git a/example/doc_any_hook.cpp b/example/doc_any_hook.cpp new file mode 100644 index 0000000..15220dc --- /dev/null +++ b/example/doc_any_hook.cpp @@ -0,0 +1,62 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 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_any_hook +#include +#include +#include +#include + +using namespace boost::intrusive; + +class MyClass : public any_base_hook<> //Base hook +{ + int int_; + + public: + any_member_hook<> member_hook_; //Member hook + + MyClass(int i = 0) : int_(i) + {} +}; + +int main() +{ + //Define a base hook option that converts any_base_hook to a slist hook + typedef any_to_slist_hook < base_hook< any_base_hook<> > > BaseSlistOption; + typedef slist BaseSList; + + //Define a member hook option that converts any_base_hook to a list hook + typedef any_to_list_hook< member_hook + < MyClass, any_member_hook<>, &MyClass::member_hook_> > MemberListOption; + typedef list MemberList; + + //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)); } + + BaseSList base_slist; MemberList member_list; + + //Now insert them in reverse order in the slist and in order in the list + for(std::vector::iterator it(values.begin()), itend(values.end()); it != itend; ++it) + base_slist.push_front(*it), member_list.push_back(*it); + + //Now test lists + BaseSList::iterator bit(base_slist.begin()), bitend(base_slist.end()); + MemberList::reverse_iterator mrit(member_list.rbegin()), mritend(member_list.rend()); + std::vector::reverse_iterator rit(values.rbegin()), ritend(values.rend()); + + //Test the objects inserted in the base hook list + for(; rit != ritend; ++rit, ++bit, ++mrit) + if(&*bit != &*rit || &*mrit != &*rit) return 1; + return 0; +} +//] diff --git a/include/boost/intrusive/any_hook.hpp b/include/boost/intrusive/any_hook.hpp new file mode 100644 index 0000000..148d41d --- /dev/null +++ b/include/boost/intrusive/any_hook.hpp @@ -0,0 +1,320 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (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. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_ANY_HOOK_HPP +#define BOOST_INTRUSIVE_ANY_HOOK_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace boost { +namespace intrusive { + +/// @cond +template +struct get_any_node_algo +{ + typedef any_algorithms type; +}; +/// @endcond + +//! Helper metafunction to define a \c \c any_base_hook that yields to the same +//! type when the same options (either explicitly or implicitly) are used. +#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED +template +#else +template +#endif +struct make_any_base_hook +{ + /// @cond + typedef typename pack_options + < hook_defaults, O1, O2, O3>::type packed_options; + + typedef detail::generic_hook + < get_any_node_algo + , typename packed_options::tag + , packed_options::link_mode + , detail::AnyBaseHook + > implementation_defined; + /// @endcond + typedef implementation_defined type; +}; + +//! Derive a class from this hook in order to store objects of that class +//! in an intrusive container. +//! +//! The hook admits the following options: \c tag<>, \c void_pointer<> and +//! \c link_mode<>. +//! +//! \c tag<> defines a tag to identify the node. +//! The same tag value can be used in different classes, but if a class is +//! derived from more than one \c any_base_hook, then each \c any_base_hook needs its +//! unique tag. +//! +//! \c link_mode<> will specify the linking mode of the hook (\c normal_link, \c safe_link). +//! +//! \c void_pointer<> is the pointer type that will be used internally in the hook +//! and the the container configured to use this hook. +#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED +template +#else +template +#endif +class any_base_hook + : public make_any_base_hook::type +{ + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + public: + //! Effects: If link_mode is or \c safe_link + //! initializes the node to an unlinked state. + //! + //! Throws: Nothing. + any_base_hook(); + + //! Effects: If link_mode is or \c safe_link + //! initializes the node to an unlinked state. The argument is ignored. + //! + //! Throws: Nothing. + //! + //! Rationale: Providing a copy-constructor + //! makes classes using the hook STL-compliant without forcing the + //! user to do some additional work. \c swap can be used to emulate + //! move-semantics. + any_base_hook(const any_base_hook& ); + + //! Effects: Empty function. The argument is ignored. + //! + //! Throws: Nothing. + //! + //! Rationale: Providing an assignment operator + //! makes classes using the hook STL-compliant without forcing the + //! user to do some additional work. \c swap can be used to emulate + //! move-semantics. + any_base_hook& operator=(const any_base_hook& ); + + //! Effects: If link_mode is \c normal_link, the destructor does + //! nothing (ie. no code is generated). If link_mode is \c safe_link and the + //! object is stored in a container an assertion is raised. + //! + //! Throws: Nothing. + ~any_base_hook(); + + //! Precondition: link_mode must be \c safe_link. + //! + //! Returns: true, if the node belongs to a container, false + //! otherwise. This function can be used to test whether \c container::iterator_to + //! will return a valid iterator. + //! + //! Complexity: Constant + bool is_linked() const; + #endif +}; + +//! Helper metafunction to define a \c \c any_member_hook that yields to the same +//! type when the same options (either explicitly or implicitly) are used. +#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED +template +#else +template +#endif +struct make_any_member_hook +{ + /// @cond + typedef typename pack_options + < hook_defaults, O1, O2, O3>::type packed_options; + + typedef detail::generic_hook + < get_any_node_algo + , member_tag + , packed_options::link_mode + , detail::NoBaseHook + > implementation_defined; + /// @endcond + typedef implementation_defined type; +}; + +//! Store this hook in a class to be inserted +//! in an intrusive container. +//! +//! The hook admits the following options: \c void_pointer<> and +//! \c link_mode<>. +//! +//! \c link_mode<> will specify the linking mode of the hook (\c normal_link or \c safe_link). +//! +//! \c void_pointer<> is the pointer type that will be used internally in the hook +//! and the the container configured to use this hook. +#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED +template +#else +template +#endif +class any_member_hook + : public make_any_member_hook::type +{ + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + public: + //! Effects: If link_mode is or \c safe_link + //! initializes the node to an unlinked state. + //! + //! Throws: Nothing. + any_member_hook(); + + //! Effects: If link_mode is or \c safe_link + //! initializes the node to an unlinked state. The argument is ignored. + //! + //! Throws: Nothing. + //! + //! Rationale: Providing a copy-constructor + //! makes classes using the hook STL-compliant without forcing the + //! user to do some additional work. \c swap can be used to emulate + //! move-semantics. + any_member_hook(const any_member_hook& ); + + //! Effects: Empty function. The argument is ignored. + //! + //! Throws: Nothing. + //! + //! Rationale: Providing an assignment operator + //! makes classes using the hook STL-compliant without forcing the + //! user to do some additional work. \c swap can be used to emulate + //! move-semantics. + any_member_hook& operator=(const any_member_hook& ); + + //! Effects: If link_mode is \c normal_link, the destructor does + //! nothing (ie. no code is generated). If link_mode is \c safe_link and the + //! object is stored in a container an assertion is raised. + //! + //! Throws: Nothing. + ~any_member_hook(); + + //! Precondition: link_mode must be \c safe_link. + //! + //! Returns: true, if the node belongs to a container, false + //! otherwise. This function can be used to test whether \c container::iterator_to + //! will return a valid iterator. + //! + //! Complexity: Constant + bool is_linked() const; + #endif +}; + +/// @cond + +namespace detail{ + +template +struct any_to_get_base_pointer_type +{ + typedef typename pointer_to_other + ::type type; +}; + +template +struct any_to_get_member_pointer_type +{ + typedef typename pointer_to_other + ::type type; +}; + +//!This option setter specifies that the container +//!must use the specified base hook +template class NodeTraits> +struct any_to_some_hook +{ + typedef typename BaseHook::template pack::value_traits old_value_traits; + template + struct pack : public Base + { + struct value_traits : public old_value_traits + { + static const bool is_any_hook = true; + typedef typename detail::eval_if_c + < detail::internal_base_hook_bool_is_true::value + , any_to_get_base_pointer_type + , any_to_get_member_pointer_type + >::type void_pointer; + typedef NodeTraits node_traits; + }; + }; +}; + +} //namespace detail{ + +/// @endcond + +//!This option setter specifies that +//!any hook should behave as an slist hook +template +struct any_to_slist_hook +/// @cond + : public detail::any_to_some_hook +/// @endcond +{}; + +//!This option setter specifies that +//!any hook should behave as an list hook +template +struct any_to_list_hook +/// @cond + : public detail::any_to_some_hook +/// @endcond +{}; + +//!This option setter specifies that +//!any hook should behave as a set hook +template +struct any_to_set_hook +/// @cond + : public detail::any_to_some_hook +/// @endcond +{}; + +//!This option setter specifies that +//!any hook should behave as a set hook +template +struct any_to_avl_set_hook +/// @cond + : public detail::any_to_some_hook +/// @endcond +{}; + +//!This option setter specifies that any +//!hook should behave as a set hook +template +struct any_to_bs_set_hook +/// @cond + : public detail::any_to_some_hook +/// @endcond +{}; + +//!This option setter specifies that any hook +//!should behave as an unordered set hook +template +struct any_to_unordered_set_hook +/// @cond + : public detail::any_to_some_hook +/// @endcond +{}; + + +} //namespace intrusive +} //namespace boost + +#include + +#endif //BOOST_INTRUSIVE_ANY_HOOK_HPP diff --git a/include/boost/intrusive/avl_set.hpp b/include/boost/intrusive/avl_set.hpp index 8ff22a4..8429f13 100644 --- a/include/boost/intrusive/avl_set.hpp +++ b/include/boost/intrusive/avl_set.hpp @@ -240,7 +240,7 @@ class avl_set_impl //! Precondition: end_iterator must be a valid end const_iterator //! of avl_set. //! - //! Effects: Returns a const reference to the avl_set associated to the end iterator + //! Effects: Returns a const reference to the set associated to the end iterator //! //! Throws: Nothing. //! @@ -252,6 +252,34 @@ class avl_set_impl , &avl_set_impl::tree_); } + //! Precondition: it must be a valid iterator of set. + //! + //! Effects: Returns a reference to the set associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static avl_set_impl &container_from_iterator(iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &avl_set_impl::tree_); + } + + //! Precondition: it must be a valid const_iterator of set. + //! + //! Effects: Returns a const reference to the set associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const avl_set_impl &container_from_iterator(const_iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &avl_set_impl::tree_); + } + //! Effects: Returns the key_compare object used by the avl_set. //! //! Complexity: Constant. @@ -1085,6 +1113,12 @@ class avl_set static const avl_set &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static avl_set &container_from_iterator(iterator end_iterator) + { return static_cast(Base::container_from_iterator(end_iterator)); } + + static const avl_set &container_from_iterator(const_iterator end_iterator) + { return static_cast(Base::container_from_iterator(end_iterator)); } }; #endif @@ -1317,6 +1351,34 @@ class avl_multiset_impl , &avl_multiset_impl::tree_); } + //! Precondition: it must be a valid iterator of multiset. + //! + //! Effects: Returns a const reference to the multiset associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static avl_multiset_impl &container_from_iterator(iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &avl_multiset_impl::tree_); + } + + //! Precondition: it must be a valid const_iterator of multiset. + //! + //! Effects: Returns a const reference to the multiset associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const avl_multiset_impl &container_from_iterator(const_iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &avl_multiset_impl::tree_); + } + //! Effects: Returns the key_compare object used by the avl_multiset. //! //! Complexity: Constant. @@ -2057,6 +2119,12 @@ class avl_multiset static const avl_multiset &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static avl_multiset &container_from_iterator(iterator end_iterator) + { return static_cast(Base::container_from_iterator(end_iterator)); } + + static const avl_multiset &container_from_iterator(const_iterator end_iterator) + { return static_cast(Base::container_from_iterator(end_iterator)); } }; #endif diff --git a/include/boost/intrusive/avltree.hpp b/include/boost/intrusive/avltree.hpp index 86a2957..afd6bd4 100644 --- a/include/boost/intrusive/avltree.hpp +++ b/include/boost/intrusive/avltree.hpp @@ -387,6 +387,28 @@ class avltree_impl static const avltree_impl &container_from_end_iterator(const_iterator end_iterator) { return priv_container_from_end_iterator(end_iterator); } + //! Precondition: it must be a valid iterator + //! of rbtree. + //! + //! Effects: Returns a const reference to the tree associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static avltree_impl &container_from_iterator(iterator it) + { return priv_container_from_iterator(it); } + + //! Precondition: it must be a valid end const_iterator + //! of rbtree. + //! + //! Effects: Returns a const reference to the tree associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const avltree_impl &container_from_iterator(const_iterator it) + { return priv_container_from_iterator(it); } + //! Effects: Returns the value_compare object used by the tree. //! //! Complexity: Constant. @@ -1233,6 +1255,9 @@ class avltree_impl avltree_impl *avl = detail::parent_from_member(d, &avltree_impl::data_); return *avl; } + + static avltree_impl &priv_container_from_iterator(const const_iterator &it) + { return priv_container_from_end_iterator(it.end_iterator_from_it()); } }; #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED @@ -1426,6 +1451,12 @@ class avltree static const avltree &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static avltree &container_from_iterator(iterator it) + { return static_cast(Base::container_from_iterator(it)); } + + static const avltree &container_from_iterator(const_iterator it) + { return static_cast(Base::container_from_iterator(it)); } }; #endif diff --git a/include/boost/intrusive/avltree_algorithms.hpp b/include/boost/intrusive/avltree_algorithms.hpp index 94d046f..dc4eed4 100644 --- a/include/boost/intrusive/avltree_algorithms.hpp +++ b/include/boost/intrusive/avltree_algorithms.hpp @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -69,6 +68,7 @@ template class avltree_algorithms { public: + typedef typename NodeTraits::node node; typedef NodeTraits node_traits; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; @@ -76,8 +76,6 @@ class avltree_algorithms /// @cond private: - - typedef typename NodeTraits::node node; typedef detail::tree_algorithms tree_algorithms; template @@ -641,6 +639,16 @@ class avltree_algorithms rebalance_after_insertion(header, new_value); } + //! Requires: "n" must be a node inserted in a tree. + //! + //! Effects: Returns a pointer to the header node of the tree. + //! + //! Complexity: Logarithmic. + //! + //! Throws: Nothing. + static node_ptr get_header(node_ptr n) + { return tree_algorithms::get_header(n); } + /// @cond private: diff --git a/include/boost/intrusive/circular_list_algorithms.hpp b/include/boost/intrusive/circular_list_algorithms.hpp index 97438bf..d48fffc 100644 --- a/include/boost/intrusive/circular_list_algorithms.hpp +++ b/include/boost/intrusive/circular_list_algorithms.hpp @@ -50,6 +50,7 @@ template class circular_list_algorithms { public: + typedef typename NodeTraits::node node; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; typedef NodeTraits node_traits; @@ -62,8 +63,8 @@ class circular_list_algorithms //! Throws: Nothing. static void init(node_ptr this_node) { - NodeTraits::set_next(this_node, 0); - NodeTraits::set_previous(this_node, 0); + NodeTraits::set_next(this_node, node_ptr(0)); + NodeTraits::set_previous(this_node, node_ptr(0)); } //! Effects: Returns true is "this_node" is in a non-used state diff --git a/include/boost/intrusive/circular_slist_algorithms.hpp b/include/boost/intrusive/circular_slist_algorithms.hpp index 73e4590..f74a641 100644 --- a/include/boost/intrusive/circular_slist_algorithms.hpp +++ b/include/boost/intrusive/circular_slist_algorithms.hpp @@ -54,6 +54,7 @@ class circular_slist_algorithms typedef detail::common_slist_algorithms base_t; /// @endcond public: + typedef typename NodeTraits::node node; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; typedef NodeTraits node_traits; @@ -305,12 +306,12 @@ class circular_slist_algorithms static node_ptr move_backwards(node_ptr p, std::size_t n) { //Null shift, nothing to do - if(!n) return 0; + if(!n) return node_ptr(0); node_ptr first = NodeTraits::get_next(p); //count() == 1 or 2, nothing to do if(NodeTraits::get_next(first) == p) - return 0; + return node_ptr(0); bool end_found = false; node_ptr new_last(0); @@ -326,7 +327,7 @@ class circular_slist_algorithms //Shortcut the shift with the modulo of the size of the list n %= i; if(!n) - return 0; + return node_ptr(0); i = 0; //Unlink p and continue the new first node search first = NodeTraits::get_next(p); @@ -357,11 +358,11 @@ class circular_slist_algorithms static node_ptr move_forward(node_ptr p, std::size_t n) { //Null shift, nothing to do - if(!n) return 0; + if(!n) return node_ptr(0); node_ptr first = node_traits::get_next(p); //count() == 1 or 2, nothing to do - if(node_traits::get_next(first) == p) return 0; + if(node_traits::get_next(first) == p) return node_ptr(0); //Iterate until p is found to know where the current last node is. //If the shift count is less than the size of the list, we can also obtain @@ -380,7 +381,7 @@ class circular_slist_algorithms //Shortcut the shift with the modulo of the size of the list std::size_t new_before_last_pos = (distance - (n % distance))% distance; //If the shift is a multiple of the size there is nothing to do - if(!new_before_last_pos) return 0; + if(!new_before_last_pos) return node_ptr(0); for( new_last = p ; new_before_last_pos-- diff --git a/include/boost/intrusive/detail/any_node_and_algorithms.hpp b/include/boost/intrusive/detail/any_node_and_algorithms.hpp new file mode 100644 index 0000000..6b75f57 --- /dev/null +++ b/include/boost/intrusive/detail/any_node_and_algorithms.hpp @@ -0,0 +1,292 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (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. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_ANY_NODE_HPP +#define BOOST_INTRUSIVE_ANY_NODE_HPP + +#include +#include +#include +#include +#include + +namespace boost { +namespace intrusive { + +template +struct any_node +{ + typedef typename boost::pointer_to_other + ::type node_ptr; + node_ptr node_ptr_1; + node_ptr node_ptr_2; + node_ptr node_ptr_3; + std::size_t size_t_1; +}; + +template +struct any_list_node_traits +{ + typedef any_node node; + typedef typename boost::pointer_to_other + ::type node_ptr; + typedef typename boost::pointer_to_other + ::type const_node_ptr; + + static node_ptr get_next(const_node_ptr n) + { return n->node_ptr_1; } + + static void set_next(node_ptr n, node_ptr next) + { n->node_ptr_1 = next; } + + static node_ptr get_previous(const_node_ptr n) + { return n->node_ptr_2; } + + static void set_previous(node_ptr n, node_ptr prev) + { n->node_ptr_2 = prev; } +}; + + +template +struct any_slist_node_traits +{ + typedef any_node node; + typedef typename boost::pointer_to_other + ::type node_ptr; + typedef typename boost::pointer_to_other + ::type const_node_ptr; + + static node_ptr get_next(const_node_ptr n) + { return n->node_ptr_1; } + + static void set_next(node_ptr n, node_ptr next) + { n->node_ptr_1 = next; } +}; + + +template +struct any_unordered_node_traits + : public any_slist_node_traits +{ + typedef any_slist_node_traits reduced_slist_node_traits; + typedef typename reduced_slist_node_traits::node node; + typedef typename reduced_slist_node_traits::node_ptr node_ptr; + typedef typename reduced_slist_node_traits::const_node_ptr const_node_ptr; + + static const bool store_hash = true; + static const bool optimize_multikey = true; + + static node_ptr get_next(const_node_ptr n) + { return node_ptr(&static_cast(*n->node_ptr_1)); } + + static void set_next(node_ptr n, node_ptr next) + { n->node_ptr_1 = next; } + + static node_ptr get_prev_in_group(const_node_ptr n) + { return n->node_ptr_2; } + + static void set_prev_in_group(node_ptr n, node_ptr prev) + { n->node_ptr_2 = prev; } + + static std::size_t get_hash(const_node_ptr n) + { return n->size_t_1; } + + static void set_hash(node_ptr n, std::size_t h) + { n->size_t_1 = h; } +}; + + +template +struct any_rbtree_node_traits +{ + typedef any_node node; + + typedef typename boost::pointer_to_other + ::type node_ptr; + typedef typename boost::pointer_to_other + ::type const_node_ptr; + + typedef std::size_t color; + + static node_ptr get_parent(const_node_ptr n) + { return n->node_ptr_1; } + + static void set_parent(node_ptr n, node_ptr p) + { n->node_ptr_1 = p; } + + static node_ptr get_left(const_node_ptr n) + { return n->node_ptr_2; } + + static void set_left(node_ptr n, node_ptr l) + { n->node_ptr_2 = l; } + + static node_ptr get_right(const_node_ptr n) + { return n->node_ptr_3; } + + static void set_right(node_ptr n, node_ptr r) + { n->node_ptr_3 = r; } + + static color get_color(const_node_ptr n) + { return n->size_t_1; } + + static void set_color(node_ptr n, color c) + { n->size_t_1 = c; } + + static color black() + { return 0u; } + + static color red() + { return 1u; } +}; + + +template +struct any_avltree_node_traits +{ + typedef any_node node; + + typedef typename boost::pointer_to_other + ::type node_ptr; + typedef typename boost::pointer_to_other + ::type const_node_ptr; + typedef std::size_t balance; + + static node_ptr get_parent(const_node_ptr n) + { return n->node_ptr_1; } + + static void set_parent(node_ptr n, node_ptr p) + { n->node_ptr_1 = p; } + + static node_ptr get_left(const_node_ptr n) + { return n->node_ptr_2; } + + static void set_left(node_ptr n, node_ptr l) + { n->node_ptr_2 = l; } + + static node_ptr get_right(const_node_ptr n) + { return n->node_ptr_3; } + + static void set_right(node_ptr n, node_ptr r) + { n->node_ptr_3 = r; } + + static balance get_balance(const_node_ptr n) + { return n->size_t_1; } + + static void set_balance(node_ptr n, balance b) + { n->size_t_1 = b; } + + static balance negative() + { return 0u; } + + static balance zero() + { return 1u; } + + static balance positive() + { return 2u; } +}; + + +template +struct any_tree_node_traits +{ + typedef any_node node; + + typedef typename boost::pointer_to_other + ::type node_ptr; + typedef typename boost::pointer_to_other + ::type const_node_ptr; + + static node_ptr get_parent(const_node_ptr n) + { return n->node_ptr_1; } + + static void set_parent(node_ptr n, node_ptr p) + { n->node_ptr_1 = p; } + + static node_ptr get_left(const_node_ptr n) + { return n->node_ptr_2; } + + static void set_left(node_ptr n, node_ptr l) + { n->node_ptr_2 = l; } + + static node_ptr get_right(const_node_ptr n) + { return n->node_ptr_3; } + + static void set_right(node_ptr n, node_ptr r) + { n->node_ptr_3 = r; } +}; + +template +class any_node_traits +{ + public: + typedef any_node node; + typedef typename boost::pointer_to_other + ::type node_ptr; + typedef typename boost::pointer_to_other + ::type const_node_ptr; +}; + +template +class any_algorithms +{ + public: + typedef any_node node; + typedef typename boost::pointer_to_other + ::type node_ptr; + typedef typename boost::pointer_to_other + ::type const_node_ptr; + typedef any_node_traits node_traits; + + //! Requires: node must not be part of any tree. + //! + //! Effects: After the function unique(node) == true. + //! + //! Complexity: Constant. + //! + //! Throws: Nothing. + //! + //! Nodes: If node is inserted in a tree, this function corrupts the tree. + static void init(node_ptr node) + { node->node_ptr_1 = 0; }; + + //! Effects: Returns true if node is in the same state as if called init(node) + //! + //! Complexity: Constant. + //! + //! Throws: Nothing. + static bool inited(const_node_ptr node) + { return !node->node_ptr_1; }; + + static bool unique(const_node_ptr node) + { return 0 == node->node_ptr_1; } + + static void unlink(node_ptr) + { + //Auto-unlink hooks and unlink() call for safe hooks are not + //available for any hooks!!! + any_algorithms::unlink_not_available_for_any_hooks(); + } + + static void swap_nodes(node_ptr l, node_ptr r) + { + //Any nodes have no swap_nodes capability because they don't know + //what algorithm they must use from unlink them from the container + any_algorithms::swap_nodes_not_available_for_any_hooks(); + } +}; + +} //namespace intrusive +} //namespace boost + +#include + +#endif //BOOST_INTRUSIVE_ANY_NODE_HPP diff --git a/include/boost/intrusive/detail/avltree_node.hpp b/include/boost/intrusive/detail/avltree_node.hpp index f60f7db..92458a4 100644 --- a/include/boost/intrusive/detail/avltree_node.hpp +++ b/include/boost/intrusive/detail/avltree_node.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include namespace boost { @@ -111,7 +111,7 @@ struct compact_avltree_node_traits_impl ::type const_node_ptr; typedef typename node::balance balance; - typedef pointer_plus_2_bits ptr_bit; + typedef pointer_plus_bits ptr_bit; static node_ptr get_parent(const_node_ptr n) { return ptr_bit::get_pointer(n->parent_); } @@ -148,7 +148,7 @@ struct compact_avltree_node_traits_impl }; //Dispatches the implementation based on the boolean -template +template struct avltree_node_traits_dispatch : public default_avltree_node_traits_impl {}; @@ -164,10 +164,10 @@ struct avltree_node_traits : public avltree_node_traits_dispatch < VoidPointer , OptimizeSize && - has_pointer_plus_2_bits + max_pointer_plus_bits < VoidPointer , detail::alignment_of >::value - >::value + >::value >= 2u > {}; diff --git a/include/boost/intrusive/detail/common_slist_algorithms.hpp b/include/boost/intrusive/detail/common_slist_algorithms.hpp index 4f4a8f1..ada51a9 100644 --- a/include/boost/intrusive/detail/common_slist_algorithms.hpp +++ b/include/boost/intrusive/detail/common_slist_algorithms.hpp @@ -26,6 +26,7 @@ template class common_slist_algorithms { public: + typedef typename NodeTraits::node node; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; typedef NodeTraits node_traits; @@ -47,13 +48,13 @@ class common_slist_algorithms { NodeTraits::set_next(this_node, this_node); } static void init(node_ptr this_node) - { NodeTraits::set_next(this_node, 0); } + { NodeTraits::set_next(this_node, node_ptr(0)); } static bool unique(const_node_ptr this_node) { node_ptr next = NodeTraits::get_next(this_node); return !next || next == this_node; - } + } static bool inited(const_node_ptr this_node) { return !NodeTraits::get_next(this_node); } diff --git a/include/boost/intrusive/detail/ebo_functor_holder.hpp b/include/boost/intrusive/detail/ebo_functor_holder.hpp index 69c50cd..369d2ca 100644 --- a/include/boost/intrusive/detail/ebo_functor_holder.hpp +++ b/include/boost/intrusive/detail/ebo_functor_holder.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Joaquín M López Muñoz 2006-2007 +// (C) Copyright Joaquin M Lopez Munoz 2006-2007 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -23,8 +23,15 @@ template class ebo_functor_holder_impl { public: - ebo_functor_holder_impl(){} - ebo_functor_holder_impl(const T& t):t(t){} + ebo_functor_holder_impl() + {} + ebo_functor_holder_impl(const T& t) + : t(t) + {} + template + ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2) + : t(arg1, arg2) + {} T& get(){return t;} const T& get()const{return t;} @@ -38,8 +45,15 @@ class ebo_functor_holder_impl : public T { public: - ebo_functor_holder_impl(){} - ebo_functor_holder_impl(const T& t):T(t){} + ebo_functor_holder_impl() + {} + ebo_functor_holder_impl(const T& t) + : T(t) + {} + template + ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2) + : T(arg1, arg2) + {} T& get(){return *this;} const T& get()const{return *this;} @@ -54,7 +68,14 @@ class ebo_functor_holder public: ebo_functor_holder(){} - ebo_functor_holder(const T& t):super(t){} + ebo_functor_holder(const T& t) + : super(t) + {} + + template + ebo_functor_holder(const Arg1& arg1, const Arg2& arg2) + : super(arg1, arg2) + {} ebo_functor_holder& operator=(const ebo_functor_holder& x) { diff --git a/include/boost/intrusive/detail/generic_hook.hpp b/include/boost/intrusive/detail/generic_hook.hpp index 87dafe2..837f928 100644 --- a/include/boost/intrusive/detail/generic_hook.hpp +++ b/include/boost/intrusive/detail/generic_hook.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace boost { @@ -35,6 +36,7 @@ enum , SplaySetBaseHook , AvlSetBaseHook , BsSetBaseHook +, AnyBaseHook }; struct no_default_definer{}; @@ -70,6 +72,10 @@ template struct default_definer { typedef Hook default_bs_set_hook; }; +template +struct default_definer +{ typedef Hook default_any_hook; }; + template struct make_default_definer { @@ -90,11 +96,11 @@ struct make_node_holder typedef typename detail::if_c ::value , detail::node_holder - < typename GetNodeAlgorithms::type::node_traits::node + < typename GetNodeAlgorithms::type::node , Tag , LinkMode , HookType> - , typename GetNodeAlgorithms::type::node_traits::node + , typename GetNodeAlgorithms::type::node >::type type; }; @@ -122,38 +128,38 @@ class generic_hook , public make_node_holder::type /// @endcond { - public: /// @cond + typedef typename GetNodeAlgorithms::type node_algorithms; + typedef typename node_algorithms::node node; + typedef typename node_algorithms::node_ptr node_ptr; + typedef typename node_algorithms::const_node_ptr const_node_ptr; + + public: struct boost_intrusive_tags { static const int hook_type = HookType; static const link_mode_type link_mode = LinkMode; - typedef Tag tag; - typedef typename GetNodeAlgorithms::type node_algorithms; - typedef typename node_algorithms::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename node_traits::node_ptr node_ptr; - typedef typename node_traits::const_node_ptr const_node_ptr; + typedef Tag tag; + typedef typename GetNodeAlgorithms::type::node_traits node_traits; static const bool is_base_hook = !detail::is_same::value; - enum { safemode_or_autounlink = - (int)link_mode == (int)auto_unlink || - (int)link_mode == (int)safe_link }; + static const bool safemode_or_autounlink = + (int)link_mode == (int)auto_unlink || (int)link_mode == (int)safe_link; }; + + public: /// @endcond generic_hook() { if(boost_intrusive_tags::safemode_or_autounlink){ - boost_intrusive_tags::node_algorithms::init - (static_cast(this)); + node_algorithms::init(static_cast(this)); } } generic_hook(const generic_hook& ) { if(boost_intrusive_tags::safemode_or_autounlink){ - boost_intrusive_tags::node_algorithms::init - (static_cast(this)); + node_algorithms::init(static_cast(this)); } } @@ -168,26 +174,23 @@ class generic_hook void swap_nodes(generic_hook &other) { - boost_intrusive_tags::node_algorithms::swap_nodes - ( static_cast(this) - , static_cast(&other)); + node_algorithms::swap_nodes + ( static_cast(this), static_cast(&other)); } bool is_linked() const { //is_linked() can be only used in safe-mode or auto-unlink BOOST_STATIC_ASSERT(( boost_intrusive_tags::safemode_or_autounlink )); - return !boost_intrusive_tags::node_algorithms::unique - (static_cast(this)); + return !node_algorithms::unique + (static_cast(this)); } void unlink() { BOOST_STATIC_ASSERT(( (int)boost_intrusive_tags::link_mode == (int)auto_unlink )); - boost_intrusive_tags::node_algorithms::unlink - (static_cast(this)); - boost_intrusive_tags::node_algorithms::init - (static_cast(this)); + node_algorithms::unlink(static_cast(this)); + node_algorithms::init(static_cast(this)); } }; diff --git a/include/boost/intrusive/detail/hashtable_node.hpp b/include/boost/intrusive/detail/hashtable_node.hpp index 0a8e85d..44a5f5a 100644 --- a/include/boost/intrusive/detail/hashtable_node.hpp +++ b/include/boost/intrusive/detail/hashtable_node.hpp @@ -50,6 +50,7 @@ const std::size_t prime_list_holder::prime_list_size template struct bucket_impl : public Slist { + typedef Slist slist_type; bucket_impl() {} @@ -69,28 +70,6 @@ struct bucket_impl : public Slist //Slist::clear(); return *this; } - - static typename Slist::difference_type get_bucket_num - ( typename Slist::const_iterator it - , const bucket_impl &first_bucket - , const bucket_impl &last_bucket) - { - typename Slist::const_iterator - first(first_bucket.cend()), last(last_bucket.cend()); - - //The end node is embedded in the singly linked list: - //iterate until we reach it. - while(!(first.pointed_node() <= it.pointed_node() && - it.pointed_node() <= last.pointed_node())){ - ++it; - } - //Now get the bucket_impl from the iterator - const bucket_impl &b = static_cast - (Slist::container_from_end_iterator(it)); - - //Now just calculate the index b has in the bucket array - return &b - &first_bucket; - } }; template @@ -125,13 +104,16 @@ class hashtable_iterator ::type > { - typedef typename Container::real_value_traits real_value_traits; - typedef typename Container::siterator siterator; - typedef typename Container::const_siterator const_siterator; - typedef typename Container::bucket_type bucket_type; + typedef typename Container::real_value_traits real_value_traits; + typedef typename Container::siterator siterator; + typedef typename Container::const_siterator const_siterator; + typedef typename Container::bucket_type bucket_type; typedef typename boost::pointer_to_other - < typename Container::pointer, const Container>::type const_cont_ptr; - typedef typename Container::size_type size_type; + < typename Container::pointer, const Container>::type const_cont_ptr; + typedef typename Container::size_type size_type; + + static typename Container::node_ptr downcast_bucket(typename bucket_type::node_ptr p) + { return typename Container::node_ptr(&static_cast(*p)); } public: typedef typename detail::add_const_if_c @@ -172,7 +154,7 @@ class hashtable_iterator { return *this->operator ->(); } value_type* operator->() const - { return detail::get_pointer(this->get_real_value_traits()->to_value_ptr(slist_it_.pointed_node())); } + { return detail::get_pointer(this->get_real_value_traits()->to_value_ptr(downcast_bucket(slist_it_.pointed_node()))); } const Container *get_container() const { return detail::get_pointer(cont_); } @@ -186,17 +168,19 @@ class hashtable_iterator const Container *cont = detail::get_pointer(cont_); bucket_type* buckets = detail::get_pointer(cont->bucket_pointer()); size_type buckets_len = cont->bucket_count(); - const_siterator first(buckets[0].cend()); - const_siterator last (buckets[buckets_len].cend()); ++slist_it_; - if(first.pointed_node() <= slist_it_.pointed_node() && - slist_it_.pointed_node()<= last.pointed_node() ){ - size_type n_bucket = (size_type) - bucket_type::get_bucket_num(slist_it_, buckets[0], buckets[buckets_len]); + if(buckets[0].cend().pointed_node() <= slist_it_.pointed_node() && + slist_it_.pointed_node()<= buckets[buckets_len].cend().pointed_node() ){ + //Now get the bucket_impl from the iterator + const bucket_type &b = static_cast + (bucket_type::slist_type::container_from_end_iterator(slist_it_)); + + //Now just calculate the index b has in the bucket array + size_type n_bucket = static_cast(&b - &buckets[0]); do{ if (++n_bucket == buckets_len){ - slist_it_ = buckets->end(); + slist_it_ = (&buckets[0] + buckets_len)->end(); break; } slist_it_ = buckets[n_bucket].begin(); diff --git a/include/boost/intrusive/detail/list_node.hpp b/include/boost/intrusive/detail/list_node.hpp index ec48a6d..371224e 100644 --- a/include/boost/intrusive/detail/list_node.hpp +++ b/include/boost/intrusive/detail/list_node.hpp @@ -18,7 +18,6 @@ #include #include #include -#include namespace boost { namespace intrusive { @@ -32,7 +31,8 @@ struct list_node { typedef typename boost::pointer_to_other ::type node_ptr; - node_ptr prev_, next_; + node_ptr next_; + node_ptr prev_; }; template @@ -85,7 +85,7 @@ class list_iterator typedef value_type * pointer; list_iterator() - : members_ (0, 0) + : members_ (node_ptr(0), 0) {} explicit list_iterator(node_ptr node, const Container *cont_ptr) diff --git a/include/boost/intrusive/detail/mpl.hpp b/include/boost/intrusive/detail/mpl.hpp index 5dcd75c..ed68350 100644 --- a/include/boost/intrusive/detail/mpl.hpp +++ b/include/boost/intrusive/detail/mpl.hpp @@ -13,6 +13,8 @@ #ifndef BOOST_INTRUSIVE_DETAIL_MPL_HPP #define BOOST_INTRUSIVE_DETAIL_MPL_HPP +#include + namespace boost { namespace intrusive { namespace detail { @@ -290,6 +292,24 @@ class is_empty_class static const bool value = sizeof(empty_helper_t1) == sizeof(empty_helper_t2); }; +template +struct ls_zeros +{ + static const std::size_t value = (S & std::size_t(1)) ? 0 : (1 + ls_zeros<(S>>1u)>::value); +}; + +template<> +struct ls_zeros<0> +{ + static const std::size_t value = 0; +}; + +template<> +struct ls_zeros<1> +{ + static const std::size_t value = 0; +}; + } //namespace detail } //namespace intrusive } //namespace boost diff --git a/include/boost/intrusive/detail/no_exceptions_support.hpp b/include/boost/intrusive/detail/no_exceptions_support.hpp deleted file mode 100644 index 4344684..0000000 --- a/include/boost/intrusive/detail/no_exceptions_support.hpp +++ /dev/null @@ -1,28 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2007 -// -// 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. -// -///////////////////////////////////////////////////////////////////////////// - -#ifndef BOOST_INTRUSIVE_NO_EXCEPTION_SUPPORT_HPP - -#if !(defined BOOST_INTRUSIVE_DISABLE_EXCEPTION_HANDLING) -# include -# define BOOST_INTRUSIVE_TRY BOOST_TRY -# define BOOST_INTRUSIVE_CATCH(x) BOOST_CATCH(x) -# define BOOST_INTRUSIVE_RETHROW BOOST_RETHROW -# define BOOST_INTRUSIVE_CATCH_END BOOST_CATCH_END -#else -# define BOOST_INTRUSIVE_TRY { if (true) -# define BOOST_INTRUSIVE_CATCH(x) else if (false) -# define BOOST_INTRUSIVE_RETHROW -# define BOOST_INTRUSIVE_CATCH_END } -#endif - -#endif //#ifndef BOOST_INTRUSIVE_NO_EXCEPTION_SUPPORT_HPP diff --git a/include/boost/intrusive/detail/parent_from_member.hpp b/include/boost/intrusive/detail/parent_from_member.hpp index c566e77..d5fc96a 100644 --- a/include/boost/intrusive/detail/parent_from_member.hpp +++ b/include/boost/intrusive/detail/parent_from_member.hpp @@ -13,25 +13,30 @@ #define BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP #include -#include #include +#if defined(BOOST_MSVC) || (defined (BOOST_WINDOWS) && defined(BOOST_INTEL)) +#define BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER +#include +#endif + namespace boost { namespace intrusive { namespace detail { template -inline std::size_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member) +inline std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member) { - //BOOST_STATIC_ASSERT(( sizeof(std::ptrdiff_t) == sizeof(ptr_to_member) )); //The implementation of a pointer to member is compiler dependent. - #if defined(BOOST_MSVC) || (defined (BOOST_WINDOWS) && defined(BOOST_INTEL)) + #if defined(BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER) + //msvc compliant compilers use their the first 32 bits as offset (even in 64 bit mode) + return *(const boost::int32_t*)(void*)&ptr_to_member; //This works with gcc, msvc, ac++, ibmcpp - return *(const std::ptrdiff_t*)(void*)&ptr_to_member; - #elif defined(__GNUC__) || defined(__HP_aCC) || defined(BOOST_INTEL) || defined (__IBMCPP__) || defined (__DECCXX) + #elif defined(__GNUC__) || defined(__HP_aCC) || defined(BOOST_INTEL) || \ + defined(__IBMCPP__) || defined(__DECCXX) const Parent * const parent = 0; const char *const member = reinterpret_cast(&(parent->*ptr_to_member)); - return std::size_t(member - reinterpret_cast(parent)); + return std::ptrdiff_t(member - reinterpret_cast(parent)); #else //This is the traditional C-front approach: __MWERKS__, __DMC__, __SUNPRO_CC return (*(const std::ptrdiff_t*)(void*)&ptr_to_member) - 1; @@ -56,6 +61,10 @@ inline const Parent *parent_from_member(const Member *member, const Member Paren } //namespace intrusive { } //namespace boost { +#ifdef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER +#undef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER +#endif + #include #endif //#ifndef BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP diff --git a/include/boost/intrusive/detail/rbtree_node.hpp b/include/boost/intrusive/detail/rbtree_node.hpp index 647c6e5..5345209 100644 --- a/include/boost/intrusive/detail/rbtree_node.hpp +++ b/include/boost/intrusive/detail/rbtree_node.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include namespace boost { @@ -110,7 +110,7 @@ struct compact_rbtree_node_traits_impl typedef typename boost::pointer_to_other ::type const_node_ptr; - typedef pointer_plus_bit ptr_bit; + typedef pointer_plus_bits ptr_bit; typedef typename node::color color; @@ -133,10 +133,10 @@ struct compact_rbtree_node_traits_impl { n->right_ = r; } static color get_color(const_node_ptr n) - { return (color)ptr_bit::get_bit(n->parent_); } + { return (color)ptr_bit::get_bits(n->parent_); } static void set_color(node_ptr n, color c) - { ptr_bit::set_bit(n->parent_, c != 0); } + { ptr_bit::set_bits(n->parent_, c != 0); } static color black() { return node::black_t; } @@ -146,7 +146,7 @@ struct compact_rbtree_node_traits_impl }; //Dispatches the implementation based on the boolean -template +template struct rbtree_node_traits_dispatch : public default_rbtree_node_traits_impl {}; @@ -161,11 +161,11 @@ template struct rbtree_node_traits : public rbtree_node_traits_dispatch < VoidPointer - , OptimizeSize && - has_pointer_plus_bit + , OptimizeSize && + (max_pointer_plus_bits < VoidPointer , detail::alignment_of >::value - >::value + >::value >= 1) > {}; diff --git a/include/boost/intrusive/detail/slist_node.hpp b/include/boost/intrusive/detail/slist_node.hpp index a5d8883..8195e54 100644 --- a/include/boost/intrusive/detail/slist_node.hpp +++ b/include/boost/intrusive/detail/slist_node.hpp @@ -18,7 +18,6 @@ #include #include #include -#include namespace boost { namespace intrusive { @@ -78,7 +77,7 @@ class slist_iterator typedef value_type * pointer; slist_iterator() - : members_ (0, 0) + : members_ (node_ptr(0), 0) {} explicit slist_iterator(node_ptr node, const Container *cont_ptr) diff --git a/include/boost/intrusive/detail/tree_algorithms.hpp b/include/boost/intrusive/detail/tree_algorithms.hpp index 7cf320c..65e673f 100644 --- a/include/boost/intrusive/detail/tree_algorithms.hpp +++ b/include/boost/intrusive/detail/tree_algorithms.hpp @@ -17,7 +17,6 @@ #include #include #include -#include #include namespace boost { @@ -95,12 +94,8 @@ namespace detail { template class tree_algorithms { - /// @cond - private: - typedef typename NodeTraits::node node; - /// @endcond - public: + typedef typename NodeTraits::node node; typedef NodeTraits node_traits; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; @@ -123,6 +118,26 @@ class tree_algorithms /// @cond private: + template + struct dispose_subtree_disposer + { + dispose_subtree_disposer(Disposer &disp, node_ptr subtree) + : disposer_(&disp), subtree_(subtree) + {} + + void release() + { disposer_ = 0; } + + ~dispose_subtree_disposer() + { + if(disposer_){ + dispose_subtree(subtree_, *disposer_); + } + } + Disposer *disposer_; + node_ptr subtree_; + }; + static node_ptr uncast(const_node_ptr ptr) { return node_ptr(const_cast(::boost::intrusive::detail::get_pointer(ptr))); @@ -505,9 +520,21 @@ class tree_algorithms //! Nodes: If node is inserted in a tree, this function corrupts the tree. static void init(node_ptr node) { - NodeTraits::set_parent(node, 0); - NodeTraits::set_left(node, 0); - NodeTraits::set_right(node, 0); + NodeTraits::set_parent(node, node_ptr(0)); + NodeTraits::set_left(node, node_ptr(0)); + NodeTraits::set_right(node, node_ptr(0)); + }; + + //! Effects: Returns true if node is in the same state as if called init(node) + //! + //! Complexity: Constant. + //! + //! Throws: Nothing. + static bool inited(const_node_ptr node) + { + return !NodeTraits::get_parent(node) && + !NodeTraits::get_left(node) && + !NodeTraits::get_right(node) ; }; //! Requires: node must not be part of any tree. @@ -522,7 +549,7 @@ class tree_algorithms //! Nodes: If node is inserted in a tree, this function corrupts the tree. static void init_header(node_ptr header) { - NodeTraits::set_parent(header, 0); + NodeTraits::set_parent(header, node_ptr(0)); NodeTraits::set_left(header, header); NodeTraits::set_right(header, header); } @@ -565,7 +592,7 @@ class tree_algorithms { node_ptr leftmost = NodeTraits::get_left(header); if (leftmost == header) - return 0; + return node_ptr(0); node_ptr leftmost_parent(NodeTraits::get_parent(leftmost)); node_ptr leftmost_right (NodeTraits::get_right(leftmost)); bool is_root = leftmost_parent == header; @@ -580,12 +607,12 @@ class tree_algorithms NodeTraits::set_left(NodeTraits::get_parent(header), leftmost_right); } else if (is_root){ - NodeTraits::set_parent(header, 0); + NodeTraits::set_parent(header, node_ptr(0)); NodeTraits::set_left(header, header); NodeTraits::set_right(header, header); } else{ - NodeTraits::set_left(leftmost_parent, 0); + NodeTraits::set_left(leftmost_parent, node_ptr(0)); NodeTraits::set_left(header, leftmost_parent); } return leftmost; @@ -1143,58 +1170,54 @@ class tree_algorithms node_ptr rightmost = target_sub_root; //First set the subroot - NodeTraits::set_left(target_sub_root, 0); - NodeTraits::set_right(target_sub_root, 0); + NodeTraits::set_left(target_sub_root, node_ptr(0)); + NodeTraits::set_right(target_sub_root, node_ptr(0)); NodeTraits::set_parent(target_sub_root, target_parent); - try { - while(true) { - //First clone left nodes - if( NodeTraits::get_left(current) && - !NodeTraits::get_left(insertion_point)) { - current = NodeTraits::get_left(current); - node_ptr temp = insertion_point; - //Clone and mark as leaf - insertion_point = cloner(current); - NodeTraits::set_left (insertion_point, 0); - NodeTraits::set_right (insertion_point, 0); - //Insert left - NodeTraits::set_parent(insertion_point, temp); - NodeTraits::set_left (temp, insertion_point); - //Update leftmost - if(rightmost == target_sub_root) - leftmost = insertion_point; - } - //Then clone right nodes - else if( NodeTraits::get_right(current) && - !NodeTraits::get_right(insertion_point)){ - current = NodeTraits::get_right(current); - node_ptr temp = insertion_point; - //Clone and mark as leaf - insertion_point = cloner(current); - NodeTraits::set_left (insertion_point, 0); - NodeTraits::set_right (insertion_point, 0); - //Insert right - NodeTraits::set_parent(insertion_point, temp); - NodeTraits::set_right (temp, insertion_point); - //Update rightmost - rightmost = insertion_point; - } - //If not, go up - else if(current == source_root){ - break; - } - else{ - //Branch completed, go up searching more nodes to clone - current = NodeTraits::get_parent(current); - insertion_point = NodeTraits::get_parent(insertion_point); - } + dispose_subtree_disposer rollback(disposer, target_sub_root); + while(true) { + //First clone left nodes + if( NodeTraits::get_left(current) && + !NodeTraits::get_left(insertion_point)) { + current = NodeTraits::get_left(current); + node_ptr temp = insertion_point; + //Clone and mark as leaf + insertion_point = cloner(current); + NodeTraits::set_left (insertion_point, node_ptr(0)); + NodeTraits::set_right (insertion_point, node_ptr(0)); + //Insert left + NodeTraits::set_parent(insertion_point, temp); + NodeTraits::set_left (temp, insertion_point); + //Update leftmost + if(rightmost == target_sub_root) + leftmost = insertion_point; + } + //Then clone right nodes + else if( NodeTraits::get_right(current) && + !NodeTraits::get_right(insertion_point)){ + current = NodeTraits::get_right(current); + node_ptr temp = insertion_point; + //Clone and mark as leaf + insertion_point = cloner(current); + NodeTraits::set_left (insertion_point, node_ptr(0)); + NodeTraits::set_right (insertion_point, node_ptr(0)); + //Insert right + NodeTraits::set_parent(insertion_point, temp); + NodeTraits::set_right (temp, insertion_point); + //Update rightmost + rightmost = insertion_point; + } + //If not, go up + else if(current == source_root){ + break; + } + else{ + //Branch completed, go up searching more nodes to clone + current = NodeTraits::get_parent(current); + insertion_point = NodeTraits::get_parent(insertion_point); } } - catch(...) { - dispose_subtree(target_sub_root, disposer); - throw; - } + rollback.release(); leftmost_out = leftmost; rightmost_out = rightmost; } @@ -1321,8 +1344,8 @@ class tree_algorithms NodeTraits::set_right(header, z); } NodeTraits::set_parent(z, par); - NodeTraits::set_right(z, 0); - NodeTraits::set_left(z, 0); + NodeTraits::set_right(z, node_ptr(0)); + NodeTraits::set_left(z, node_ptr(0)); } static void erase(node_ptr header, node_ptr z) @@ -1384,7 +1407,7 @@ class tree_algorithms { std::size_t len; len = 0; - if(!old_root) return 0; + if(!old_root) return node_ptr(0); //To avoid irregularities in the algorithm (old_root can be a //left or right child or even the root of the tree) just put the @@ -1392,8 +1415,8 @@ class tree_algorithms //information to restore the original relationship after //the algorithm is applied. node_ptr super_root = NodeTraits::get_parent(old_root); - assert(super_root); - + BOOST_INTRUSIVE_INVARIANT_ASSERT(super_root); + //Get info node_ptr super_root_right_backup = NodeTraits::get_right(super_root); bool super_root_is_header = is_header(super_root); @@ -1464,7 +1487,7 @@ class tree_algorithms //information to restore the original relationship after //the algorithm is applied. node_ptr super_root = NodeTraits::get_parent(old_root); - assert(super_root); + BOOST_INTRUSIVE_INVARIANT_ASSERT(super_root); //Get info node_ptr super_root_right_backup = NodeTraits::get_right(super_root); @@ -1511,6 +1534,28 @@ class tree_algorithms return new_root; } + //! Requires: "n" must be a node inserted in a tree. + //! + //! Effects: Returns a pointer to the header node of the tree. + //! + //! Complexity: Logarithmic. + //! + //! Throws: Nothing. + static node_ptr get_root(node_ptr node) + { + BOOST_INTRUSIVE_INVARIANT_ASSERT((!inited(node))); + node_ptr x = NodeTraits::get_parent(node); + if(x){ + while(!is_header(x)){ + x = NodeTraits::get_parent(x); + } + return x; + } + else{ + return node; + } + } + private: static void erase_impl(node_ptr header, node_ptr z, data_for_rebalance &info) { @@ -1569,7 +1614,6 @@ class tree_algorithms info.x_parent = x_parent; info.y = y; } - }; } //namespace detail { diff --git a/include/boost/intrusive/detail/tree_node.hpp b/include/boost/intrusive/detail/tree_node.hpp index ea53b1c..a375cba 100644 --- a/include/boost/intrusive/detail/tree_node.hpp +++ b/include/boost/intrusive/detail/tree_node.hpp @@ -168,6 +168,11 @@ class tree_iterator return 0; } + tree_iterator end_iterator_from_it() const + { + return tree_iterator(node_algorithms::get_header(this->pointed_node()), this->get_container()); + } + private: struct members : public detail::select_constptr diff --git a/include/boost/intrusive/detail/utilities.hpp b/include/boost/intrusive/detail/utilities.hpp index e8b3bb3..743f329 100644 --- a/include/boost/intrusive/detail/utilities.hpp +++ b/include/boost/intrusive/detail/utilities.hpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace boost { namespace intrusive { @@ -55,6 +56,24 @@ struct internal_base_hook_bool_is_true static const bool value = internal_base_hook_bool::value > sizeof(one)*2; }; +template +struct internal_any_hook_bool +{ + template + struct two_or_three {one _[2 + Add];}; + template static one test(...); + template static two_or_three + test (detail::bool_* = 0); + static const std::size_t value = sizeof(test(0)); +}; + +template +struct internal_any_hook_bool_is_true +{ + static const bool value = internal_any_hook_bool::value > sizeof(one)*2; +}; + + template struct external_value_traits_bool { @@ -235,16 +254,9 @@ struct node_cloner node_cloner(F f, const Container *cont) : base_t(f), cont_(cont) {} - + node_ptr operator()(node_ptr p) - { - node_ptr n = cont_->get_real_value_traits().to_node_ptr - (*base_t::get()(*cont_->get_real_value_traits().to_value_ptr(p))); - //Cloned node must be in default mode if the linking mode requires it - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); - return n; - } + { return this->operator()(*p); } node_ptr operator()(const node &to_clone) { @@ -396,16 +408,20 @@ template struct link_dispatch {}; -template -void destructor_impl(Container &cont, detail::link_dispatch) -{ (void)cont; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!cont.is_linked()); } +template +void destructor_impl(Hook &hook, detail::link_dispatch) +{ //If this assertion raises, you might have destroyed an object + //while it was still inserted in a container that is alive. + //If so, remove the object from the container before destroying it. + (void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked()); +} -template -void destructor_impl(Container &cont, detail::link_dispatch) -{ cont.unlink(); } +template +void destructor_impl(Hook &hook, detail::link_dispatch) +{ hook.unlink(); } -template -void destructor_impl(Container &, detail::link_dispatch) +template +void destructor_impl(Hook &, detail::link_dispatch) {} template @@ -548,6 +564,62 @@ inline std::size_t sqrt2_pow_2xplus1 (std::size_t x) return (value >> (pow - x)) + 1; } +template +class exception_disposer +{ + Container *cont_; + Disposer &disp_; + + exception_disposer(const exception_disposer&); + exception_disposer &operator=(const exception_disposer&); + + public: + exception_disposer(Container &cont, Disposer &disp) + : cont_(&cont), disp_(disp) + {} + + void release() + { cont_ = 0; } + + ~exception_disposer() + { + if(cont_){ + cont_->clear_and_dispose(disp_); + } + } +}; + +template +class exception_array_disposer +{ + Container *cont_; + Disposer &disp_; + typename Container::size_type &constructed_; + + exception_array_disposer(const exception_array_disposer&); + exception_array_disposer &operator=(const exception_array_disposer&); + + public: + typedef typename Container::size_type size_type; + exception_array_disposer + (Container &cont, Disposer &disp, size_type &constructed) + : cont_(&cont), disp_(disp), constructed_(constructed) + {} + + void release() + { cont_ = 0; } + + ~exception_array_disposer() + { + size_type n = constructed_; + if(cont_){ + while(n--){ + cont_[n].clear_and_dispose(disp_); + } + } + } +}; + } //namespace detail } //namespace intrusive } //namespace boost diff --git a/include/boost/intrusive/hashtable.hpp b/include/boost/intrusive/hashtable.hpp index 6947427..2d51e79 100644 --- a/include/boost/intrusive/hashtable.hpp +++ b/include/boost/intrusive/hashtable.hpp @@ -14,15 +14,15 @@ #include //std C++ -#include -#include -#include -#include +#include //std::equal_to +#include //std::pair +#include //std::swap, std::lower_bound, std::upper_bound +#include //std::size_t +#include //std::iterator_traits //boost #include #include #include -#include //General intrusive utilities #include #include @@ -34,13 +34,107 @@ #include #include #include +#include namespace boost { namespace intrusive { /// @cond -namespace detail{ +namespace detail { + +template +struct hash_reduced_slist_node_traits +{ + template static detail::one test(...); + template static detail::two test(typename U::reduced_slist_node_traits* = 0); + static const bool value = sizeof(test(0)) == sizeof(detail::two); +}; + +template +struct apply_reduced_slist_node_traits +{ + typedef typename NodeTraits::reduced_slist_node_traits type; +}; + +template +struct reduced_slist_node_traits +{ + typedef typename detail::eval_if_c + < hash_reduced_slist_node_traits::value + , apply_reduced_slist_node_traits + , detail::identity + >::type type; +}; + +template +struct get_slist_impl +{ + typedef trivial_value_traits trivial_traits; + + //Reducing symbol length + struct type : make_slist + < typename NodeTraits::node + , boost::intrusive::value_traits + , boost::intrusive::constant_time_size + , boost::intrusive::size_type + >::type + {}; +}; + +template +struct real_from_supposed_value_traits +{ + typedef typename detail::eval_if_c + < detail::external_value_traits_is_true + ::value + , detail::eval_value_traits + + , detail::identity + + >::type type; +}; + +template +struct get_slist_impl_from_supposed_value_traits +{ + typedef typename + real_from_supposed_value_traits + < SupposedValueTraits>::type real_value_traits; + typedef typename detail::get_node_traits + ::type node_traits; + typedef typename get_slist_impl + ::type + >::type type; +}; + + +template +struct unordered_bucket_impl +{ + /// @cond + typedef typename + get_slist_impl_from_supposed_value_traits + ::type slist_impl; + typedef detail::bucket_impl implementation_defined; + /// @endcond + typedef implementation_defined type; +}; + +template +struct unordered_bucket_ptr_impl +{ + /// @cond + typedef typename detail::get_node_traits + ::type::node_ptr node_ptr; + typedef typename unordered_bucket_impl + ::type bucket_type; + typedef typename boost::pointer_to_other + ::type implementation_defined; + /// @endcond + typedef implementation_defined type; +}; template struct store_hash_bool @@ -59,6 +153,23 @@ struct store_hash_is_true static const bool value = store_hash_bool::value > sizeof(one)*2; }; +template +struct optimize_multikey_bool +{ + template + struct two_or_three {one _[2 + Add];}; + template static one test(...); + template static two_or_three + test (detail::bool_* = 0); + static const std::size_t value = sizeof(test(0)); +}; + +template +struct optimize_multikey_is_true +{ + static const bool value = optimize_multikey_bool::value > sizeof(one)*2; +}; + template struct bucket_plus_size : public detail::size_holder @@ -92,7 +203,7 @@ struct bucket_hash_t : public detail::ebo_functor_holder bucket_plus_size bucket_plus_size_; }; -template +template struct bucket_hash_equal_t : public detail::ebo_functor_holder { typedef typename Config::equal equal; @@ -105,22 +216,42 @@ struct bucket_hash_equal_t : public detail::ebo_functor_holder bucket_hash; }; +template //cache_begin == true version +struct bucket_hash_equal_t + : public detail::ebo_functor_holder +{ + typedef typename Config::equal equal; + typedef typename Config::hash hasher; + typedef typename Config::bucket_traits bucket_traits; + typedef typename unordered_bucket_ptr_impl + ::type bucket_ptr; + + bucket_hash_equal_t(const bucket_traits &b_traits, const hasher & h, const equal &e) + : detail::ebo_functor_holder(e), bucket_hash(b_traits, h) + {} + bucket_hash_t bucket_hash; + bucket_ptr cached_begin_; +}; + template -struct data_t : public Config::value_traits +struct hashtable_data_t : public Config::value_traits { typedef typename Config::value_traits value_traits; typedef typename Config::equal equal; typedef typename Config::hash hasher; typedef typename Config::bucket_traits bucket_traits; - data_t( const bucket_traits &b_traits, const hasher & h - , const equal &e, const value_traits &val_traits) + hashtable_data_t( const bucket_traits &b_traits, const hasher & h + , const equal &e, const value_traits &val_traits) : Config::value_traits(val_traits), bucket_hash_equal_(b_traits, h, e) {} - bucket_hash_equal_t bucket_hash_equal_; + bucket_hash_equal_t bucket_hash_equal_; }; -} //namespace detail { +struct insert_commit_data_impl +{ + std::size_t hash; +}; template struct internal_default_uset_hook @@ -130,6 +261,49 @@ struct internal_default_uset_hook static const bool value = sizeof(test(0)) == sizeof(detail::two); }; +} //namespace detail { + +//!This metafunction will obtain the type of a bucket +//!from the value_traits or hook option to be used with +//!a hash container. +template +struct unordered_bucket + : public detail::unordered_bucket_impl + ::value_traits + > +{}; + +//!This metafunction will obtain the type of a bucket pointer +//!from the value_traits or hook option to be used with +//!a hash container. +template +struct unordered_bucket_ptr + : public detail::unordered_bucket_ptr_impl + ::value_traits + > +{}; + +//!This metafunction will obtain the type of the default bucket traits +//!(when the user does not specify the bucket_traits<> option) from the +//!value_traits or hook option to be used with +//!a hash container. +template +struct unordered_default_bucket_traits +{ + /// @cond + typedef typename ValueTraitsOrHookOption:: + template pack::value_traits supposed_value_traits; + typedef typename detail:: + get_slist_impl_from_supposed_value_traits + ::type slist_impl; + typedef detail::bucket_traits_impl + implementation_defined; + /// @endcond + typedef implementation_defined type; +}; + template struct get_default_uset_hook { @@ -137,12 +311,15 @@ struct get_default_uset_hook }; template < class ValueTraits + , bool UniqueKeys , class Hash , class Equal , class SizeType , bool ConstantTimeSize , class BucketTraits , bool Power2Buckets + , bool CacheBegin + , bool CompareHash > struct usetopt { @@ -153,6 +330,9 @@ struct usetopt typedef BucketTraits bucket_traits; static const bool constant_time_size = ConstantTimeSize; static const bool power_2_buckets = Power2Buckets; + static const bool unique_keys = UniqueKeys; + static const bool cache_begin = CacheBegin; + static const bool compare_hash = CompareHash; }; struct default_bucket_traits; @@ -163,7 +343,7 @@ struct uset_defaults < none , base_hook < typename detail::eval_if_c - < internal_default_uset_hook::value + < detail::internal_default_uset_hook::value , get_default_uset_hook , detail::identity >::type @@ -174,80 +354,18 @@ struct uset_defaults , hash > , bucket_traits , power_2_buckets + , cache_begin + , compare_hash >::type {}; -template -struct get_slist_impl -{ - typedef trivial_value_traits trivial_traits; - - //Reducing symbol length - struct type : make_slist - < typename NodeTraits::node - , boost::intrusive::value_traits - , boost::intrusive::constant_time_size - , boost::intrusive::size_type - >::type - {}; -}; - /// @endcond -template -struct unordered_bucket -{ - /// @cond - typedef typename ValueTraitsOrHookOption:: - template pack::value_traits supposed_value_traits; - - typedef typename detail::eval_if_c - < detail::external_value_traits_is_true - ::value - , detail::eval_value_traits - - , detail::identity - - >::type real_value_traits; - - typedef typename detail::get_node_traits - ::type node_traits; - typedef typename get_slist_impl - ::type slist_impl; - typedef detail::bucket_impl implementation_defined; - /// @endcond - typedef implementation_defined type; -}; - -template -struct unordered_bucket_ptr -{ - /// @cond - typedef typename ValueTraitsOrHookOption:: - template pack::value_traits supposed_value_traits; - typedef typename detail::eval_if_c - < detail::external_value_traits_is_true - ::value - , detail::eval_value_traits - - , detail::identity - - >::type real_value_traits; - typedef typename detail::get_node_traits - ::type::node_ptr node_ptr; - typedef typename unordered_bucket - ::type bucket_type; - typedef typename boost::pointer_to_other - ::type implementation_defined; - /// @endcond - typedef implementation_defined type; -}; - //! The class template hashtable is an intrusive hash table container, that //! is used to construct intrusive unordered_set and unordered_multiset containers. The //! no-throw guarantee holds only, if the Equal object and Hasher don't throw. //! -//! hashtable is a pseudo-intrusive container: each object to be stored in the +//! hashtable is a semi-intrusive container: each object to be stored in the //! container must contain a proper hook, but the container also needs //! additional auxiliary memory to work: hashtable needs a pointer to an array //! of type `bucket_type` to be passed in the constructor. This bucket array must @@ -261,7 +379,8 @@ struct unordered_bucket_ptr //! //! The container supports the following options: //! \c base_hook<>/member_hook<>/value_traits<>, -//! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<> . +//! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<> +//! \c bucket_traits<>, power_2_buckets<> and cache_begin<>. //! //! hashtable only provides forward iterators but it provides 4 iterator types: //! iterator and const_iterator to navigate through the whole container and @@ -284,13 +403,12 @@ template template #endif class hashtable_impl - : private detail::data_t + : private detail::hashtable_data_t { public: typedef typename Config::value_traits value_traits; /// @cond - static const bool external_value_traits = detail::external_value_traits_is_true::value; typedef typename detail::eval_if_c @@ -306,8 +424,10 @@ class hashtable_impl , detail::eval_bucket_traits , detail::identity >::type real_bucket_traits; - typedef typename get_slist_impl - ::type slist_impl; + typedef typename detail::get_slist_impl + ::type + >::type slist_impl; /// @endcond typedef typename real_value_traits::pointer pointer; @@ -327,7 +447,7 @@ class hashtable_impl typedef typename slist_impl::const_iterator const_siterator; typedef detail::hashtable_iterator iterator; typedef detail::hashtable_iterator const_iterator; - typedef typename real_value_traits::node_traits node_traits; + typedef typename real_value_traits::node_traits node_traits; typedef typename node_traits::node node; typedef typename boost::pointer_to_other ::type node_ptr; @@ -338,19 +458,71 @@ class hashtable_impl static const bool constant_time_size = Config::constant_time_size; static const bool stateful_value_traits = detail::store_cont_ptr_on_it::value; static const bool store_hash = detail::store_hash_is_true::value; + static const bool unique_keys = Config::unique_keys; + static const bool optimize_multikey + = detail::optimize_multikey_is_true::value && !unique_keys; + static const bool power_2_buckets = Config::power_2_buckets; + static const bool cache_begin = Config::cache_begin; + static const bool compare_hash = Config::compare_hash; /// @cond private: - typedef detail::bool_ store_hash_t; - typedef detail::size_holder size_traits; - typedef detail::data_t base_type; - typedef detail::transform_iterator - < typename slist_impl::iterator - , detail::node_to_value > local_iterator_impl; - typedef detail::transform_iterator - < typename slist_impl::iterator - , detail::node_to_value > const_local_iterator_impl; + //Configuration error: compare_hash<> can't be specified without store_hash<> + //See documentation for more explanations + BOOST_STATIC_ASSERT((!compare_hash || store_hash)); + typedef typename slist_impl::node_ptr slist_node_ptr; + typedef typename boost::pointer_to_other + ::type void_pointer; + //We'll define group traits, but these won't be instantiated if + //optimize_multikey is not true + typedef unordered_group_adapter group_traits; + typedef circular_slist_algorithms group_algorithms; + typedef detail::bool_ store_hash_t; + typedef detail::bool_ optimize_multikey_t; + typedef detail::bool_ cache_begin_t; + typedef detail::bool_ power_2_buckets_t; + typedef detail::size_holder size_traits; + typedef detail::hashtable_data_t base_type; + + template + struct downcast_node_to_value + : public detail::node_to_value + { + typedef detail::node_to_value base_t; + typedef typename base_t::result_type result_type; + typedef typename detail::add_const_if_c + ::type &first_argument_type; + typedef typename detail::add_const_if_c + ::type &intermediate_argument_type; + + downcast_node_to_value(const hashtable_impl *cont) + : base_t(cont) + {} + + result_type operator()(first_argument_type arg) const + { return this->base_t::operator()(static_cast(arg)); } + }; + + template + struct node_cast_adaptor + : private detail::ebo_functor_holder + { + typedef detail::ebo_functor_holder base_t; + + template + node_cast_adaptor(const ConvertibleToF &c2f, const hashtable_impl *cont) + : base_t(base_t(c2f, cont)) + {} + + typename base_t::node_ptr operator()(const typename slist_impl::node &to_clone) + { return base_t::operator()(static_cast(to_clone)); } + + void operator()(typename slist_impl::node_ptr to_clone) + { base_t::operator()(node_ptr(&static_cast(*to_clone))); } + }; + + private: //noncopyable hashtable_impl (const hashtable_impl&); hashtable_impl operator =(const hashtable_impl&); @@ -362,103 +534,23 @@ class hashtable_impl //Constant-time size is incompatible with auto-unlink hooks! BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink))); - static const bool power_2_buckets = Config::power_2_buckets; + template + node_cast_adaptor > + make_node_disposer(const Disposer &disposer) const + { return node_cast_adaptor >(disposer, this); } - std::size_t from_hash_to_bucket(std::size_t hash_value) const - { return from_hash_to_bucket(hash_value, detail::bool_()); } - - std::size_t from_hash_to_bucket(std::size_t hash_value, detail::bool_) const - { return hash_value % this->get_real_bucket_traits().bucket_count(); } - - std::size_t from_hash_to_bucket(std::size_t hash_value, detail::bool_) const - { return hash_value & (this->get_real_bucket_traits().bucket_count() - 1); } - - const key_equal &priv_equal() const - { return static_cast(this->bucket_hash_equal_.get()); } - - key_equal &priv_equal() - { return static_cast(this->bucket_hash_equal_.get()); } - - const real_bucket_traits &get_real_bucket_traits(detail::bool_) const - { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; } - - const real_bucket_traits &get_real_bucket_traits(detail::bool_) const - { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_.get_bucket_traits(*this); } - - real_bucket_traits &get_real_bucket_traits(detail::bool_) - { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; } - - real_bucket_traits &get_real_bucket_traits(detail::bool_) - { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_.get_bucket_traits(*this); } - - const real_bucket_traits &get_real_bucket_traits() const - { return this->get_real_bucket_traits(detail::bool_()); } - - real_bucket_traits &get_real_bucket_traits() - { return this->get_real_bucket_traits(detail::bool_()); } - - const hasher &priv_hasher() const - { return static_cast(this->bucket_hash_equal_.bucket_hash.get()); } - - hasher &priv_hasher() - { return static_cast(this->bucket_hash_equal_.bucket_hash.get()); } - - bucket_ptr priv_buckets() const - { return this->get_real_bucket_traits().bucket_begin(); } - - size_type priv_buckets_len() const - { return this->get_real_bucket_traits().bucket_count(); } - - static node_ptr uncast(const_node_ptr ptr) - { - return node_ptr(const_cast(detail::get_pointer(ptr))); - } - - node &from_value_to_node(value_type &v) - { return *this->get_real_value_traits().to_node_ptr(v); } - - const node &from_value_to_node(const value_type &v) const - { return *this->get_real_value_traits().to_node_ptr(v); } - - size_traits &priv_size_traits() - { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_; } - - const size_traits &priv_size_traits() const - { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_; } - - struct insert_commit_data_impl - { - size_type hash; - }; /// @endcond public: + typedef detail::insert_commit_data_impl insert_commit_data; - class local_iterator - : public local_iterator_impl - { - public: - local_iterator() - {} + typedef detail::transform_iterator + < typename slist_impl::iterator + , downcast_node_to_value > local_iterator; - local_iterator(siterator sit, const hashtable_impl *cont) - : local_iterator_impl(sit, cont) - {} - }; - - class const_local_iterator - : public const_local_iterator_impl - { - public: - const_local_iterator() - {} - - const_local_iterator(siterator sit, const hashtable_impl *cont) - : const_local_iterator_impl(sit, cont) - {} - }; - - typedef insert_commit_data_impl insert_commit_data; + typedef detail::transform_iterator + < typename slist_impl::iterator + , downcast_node_to_value > const_local_iterator; /// @cond @@ -503,7 +595,7 @@ class hashtable_impl , const value_traits &v_traits = value_traits()) : base_type(b_traits, hash_func, equal_func, v_traits) { - priv_clear_buckets(); + priv_initialize_buckets(); this->priv_size_traits().set_size(size_type(0)); BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_buckets_len() != 0); //Check power of two bucket array if the option is activated @@ -562,7 +654,7 @@ class hashtable_impl //! //! Throws: Nothing. iterator end() - { return iterator(invalid_local_it(this->get_real_bucket_traits()), 0); } + { return iterator(priv_invalid_local_it(), 0); } //! Effects: Returns a const_iterator pointing to the end of the unordered_set. //! @@ -578,7 +670,7 @@ class hashtable_impl //! //! Throws: Nothing. const_iterator cend() const - { return const_iterator(invalid_local_it(this->get_real_bucket_traits()), 0); } + { return const_iterator(priv_invalid_local_it(), 0); } //! Effects: Returns the hasher object used by the unordered_set. //! @@ -598,8 +690,8 @@ class hashtable_impl //! Effects: Returns true is the container is empty. //! - //! Complexity: if constant_time_size is false, average constant time - //! (worst case, with empty() == true): O(this->bucket_count()). + //! Complexity: if constant-time size and cache_last options are disabled, + //! average constant time (worst case, with empty() == true: O(this->bucket_count()). //! Otherwise constant. //! //! Throws: Nothing. @@ -608,6 +700,9 @@ class hashtable_impl if(constant_time_size){ return !this->size(); } + else if(cache_begin){ + return this->begin() == this->end(); + } else{ size_type buckets_len = this->priv_buckets_len(); const bucket_type *b = detail::get_pointer(this->priv_buckets()); @@ -658,7 +753,8 @@ class hashtable_impl swap(this->priv_equal(), other.priv_equal()); swap(this->priv_hasher(), other.priv_hasher()); //These can't throw - swap(this->get_real_bucket_traits(), other.get_real_bucket_traits()); + swap(this->priv_real_bucket_traits(), other.priv_real_bucket_traits()); + priv_swap_cache(cache_begin_t(), other); if(constant_time_size){ size_type backup = this->priv_size_traits().get_size(); this->priv_size_traits().set_size(other.priv_size_traits().get_size()); @@ -698,75 +794,75 @@ class hashtable_impl const bucket_ptr src_buckets = src.priv_buckets(); const bucket_ptr dst_buckets = this->priv_buckets(); size_type constructed; - BOOST_INTRUSIVE_TRY{ - for( constructed = 0 - ; constructed < dst_bucket_count + typedef node_cast_adaptor > NodeDisposer; + typedef node_cast_adaptor > NodeCloner; + NodeDisposer node_disp(disposer, this); + + detail::exception_array_disposer + rollback(dst_buckets[0], node_disp, constructed); + for( constructed = 0 + ; constructed < dst_bucket_count + ; ++constructed){ + dst_buckets[constructed].clone_from + ( src_buckets[constructed] + , NodeCloner(cloner, this), node_disp); + } + if(src_bucket_count != dst_bucket_count){ + //Now insert the remaining ones using the modulo trick + for(//"constructed" comes from the previous loop + ; constructed < src_bucket_count ; ++constructed){ - dst_buckets[constructed].clone_from - ( src_buckets[constructed] - , detail::node_cloner(cloner, this) - , detail::node_disposer(disposer, this) - ); - } - if(src_bucket_count != dst_bucket_count){ - //Now insert the remaining ones using the modulo trick - for(//"constructed" comes from the previous loop - ; constructed < src_bucket_count - ; ++constructed){ - bucket_type &dst_b = (power_2_buckets) - ? dst_buckets[constructed & (dst_bucket_count-1)] - : dst_buckets[constructed % dst_bucket_count]; - bucket_type &src_b = src_buckets[constructed]; - for( siterator b(src_b.begin()), e(src_b.end()) - ; b != e - ; ++b){ - dst_b.push_front(*detail::node_cloner - (cloner, this)(b.pointed_node())); - } + bucket_type &dst_b = + dst_buckets[priv_hash_to_bucket(constructed, dst_bucket_count)]; + bucket_type &src_b = src_buckets[constructed]; + for( siterator b(src_b.begin()), e(src_b.end()) + ; b != e + ; ++b){ + dst_b.push_front(*(NodeCloner(cloner, this)(*b.pointed_node()))); } } } - BOOST_INTRUSIVE_CATCH(...){ - while(constructed--){ - dst_buckets[constructed].clear_and_dispose - (detail::node_disposer(disposer, this)); - } - BOOST_INTRUSIVE_RETHROW; - } - BOOST_INTRUSIVE_CATCH_END + rollback.release(); this->priv_size_traits().set_size(src.priv_size_traits().get_size()); + priv_insertion_update_cache(0u); + priv_erasure_update_cache(); } else{ //Unlike previous cloning algorithm, this can throw //if cloner, the hasher or comparison functor throw const_iterator b(src.begin()), e(src.end()); - BOOST_INTRUSIVE_TRY{ - for(; b != e; ++b){ - this->insert_equal(*cloner(*b)); - } + detail::exception_disposer + rollback(*this, disposer); + for(; b != e; ++b){ + this->insert_equal(*cloner(*b)); } - BOOST_INTRUSIVE_CATCH(...){ - this->clear_and_dispose(disposer); - BOOST_INTRUSIVE_RETHROW; - } - BOOST_INTRUSIVE_CATCH_END + rollback.release(); } } } iterator insert_equal(reference value) { - size_type bucket_num, hash_value; + size_type bucket_num; + std::size_t hash_value; + siterator prev; siterator it = this->priv_find - (value, this->priv_hasher(), this->priv_equal(), bucket_num, hash_value); + (value, this->priv_hasher(), this->priv_equal(), bucket_num, hash_value, prev); bucket_type &b = this->priv_buckets()[bucket_num]; - if(it == invalid_local_it(this->get_real_bucket_traits())){ - it = b.before_begin(); - } - node_ptr n = node_ptr(&from_value_to_node(value)); + bool found_equal = it != priv_invalid_local_it(); + node_ptr n = node_ptr(&priv_value_to_node(value)); this->priv_store_hash(n, hash_value, store_hash_t()); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); + if(!found_equal){ + it = b.before_begin(); + } + if(optimize_multikey){ + node_ptr first_in_group = found_equal ? + dcast_bucket_ptr(it.pointed_node()) : node_ptr(0); + this->priv_insert_in_group(first_in_group, n, optimize_multikey_t()); + } + priv_insertion_update_cache(bucket_num); this->priv_size_traits().increment(); return iterator(b.insert_after(it, *n), this); } @@ -867,9 +963,10 @@ class hashtable_impl , insert_commit_data &commit_data) { size_type bucket_num; + siterator prev; siterator prev_pos = - this->priv_find(key, hash_func, equal_func, bucket_num, commit_data.hash); - bool success = prev_pos == invalid_local_it(this->get_real_bucket_traits()); + this->priv_find(key, hash_func, equal_func, bucket_num, commit_data.hash, prev); + bool success = prev_pos == priv_invalid_local_it(); if(success){ prev_pos = this->priv_buckets()[bucket_num].before_begin(); } @@ -897,14 +994,16 @@ class hashtable_impl //! After a successful rehashing insert_commit_data remains valid. iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) { - size_type bucket_num = from_hash_to_bucket(commit_data.hash); + size_type bucket_num = priv_hash_to_bucket(commit_data.hash); bucket_type &b = this->priv_buckets()[bucket_num]; this->priv_size_traits().increment(); - node_ptr n = node_ptr(&from_value_to_node(value)); + node_ptr n = node_ptr(&priv_value_to_node(value)); this->priv_store_hash(n, commit_data.hash, store_hash_t()); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); - return iterator( b.insert_after(b.before_begin(), *n), this); + priv_insertion_update_cache(bucket_num); + this->priv_insert_in_group(node_ptr(0), n, optimize_multikey_t()); + return iterator(b.insert_after(b.before_begin(), *n), this); } //! Effects: Erases the element pointed to by i. @@ -983,12 +1082,9 @@ class hashtable_impl template void erase_and_dispose(const_iterator i, Disposer disposer) { - siterator to_erase(i.slist_it()); - bucket_ptr f(priv_buckets()), l(f + priv_buckets_len()); - bucket_type &b = this->priv_buckets()[bucket_type::get_bucket_num(to_erase, *f, *l)]; - b.erase_after_and_dispose - (b.previous(to_erase), detail::node_disposer(disposer, this)); + priv_erase(i, disposer, optimize_multikey_t()); this->priv_size_traits().decrement(); + priv_erasure_update_cache(); } //! Requires: Disposer::operator()(pointer) shouldn't throw. @@ -1009,66 +1105,26 @@ class hashtable_impl if(b == e) return; //Get the bucket number and local iterator for both iterators - bucket_ptr f(priv_buckets()), l(f + priv_buckets_len()); - size_type first_bucket_num = bucket_type::get_bucket_num(b.slist_it(), *f, *l); + siterator first_local_it(b.slist_it()); + size_type first_bucket_num = this->priv_get_bucket_num(first_local_it); siterator before_first_local_it - = priv_buckets()[first_bucket_num].previous(b.slist_it()); + = priv_get_previous(priv_buckets()[first_bucket_num], first_local_it); size_type last_bucket_num; siterator last_local_it; //For the end iterator, we will assign the end iterator //of the last bucket - if(e == end()){ + if(e == this->end()){ last_bucket_num = this->bucket_count() - 1; last_local_it = priv_buckets()[last_bucket_num].end(); } else{ last_local_it = e.slist_it(); - last_bucket_num = bucket_type::get_bucket_num(last_local_it, *f, *l); - } - - const bucket_ptr buckets = priv_buckets(); - //First erase the nodes of the first bucket - { - bucket_type &first_b = buckets[first_bucket_num]; - siterator nxt(before_first_local_it); ++nxt; - siterator end = first_b.end(); - while(nxt != end){ - nxt = first_b.erase_after_and_dispose - ( before_first_local_it - , detail::node_disposer(disposer, this)); - this->priv_size_traits().decrement(); - } - } - - //Now fully clear the intermediate buckets - for(size_type i = first_bucket_num+1; i < last_bucket_num; ++i){ - bucket_type &b = buckets[i]; - if(b.empty()) - continue; - siterator b_begin(b.before_begin()); - siterator nxt(b_begin); ++nxt; - siterator end = b.end(); - while(nxt != end){ - nxt = b.erase_after_and_dispose - (b_begin, detail::node_disposer(disposer, this)); - this->priv_size_traits().decrement(); - } - } - - //Now erase nodes from the last bucket - { - bucket_type &last_b = buckets[last_bucket_num]; - siterator b_begin(last_b.before_begin()); - siterator nxt(b_begin); ++nxt; - while(nxt != last_local_it){ - nxt = last_b.erase_after_and_dispose - (b_begin, detail::node_disposer - (disposer, this)); - this->priv_size_traits().decrement(); - } + last_bucket_num = this->priv_get_bucket_num(last_local_it); } + priv_erase_range(before_first_local_it, first_bucket_num, last_local_it, last_bucket_num, disposer); + priv_erasure_update_cache(first_bucket_num, last_bucket_num); } //! Requires: Disposer::operator()(pointer) shouldn't throw. @@ -1109,40 +1165,42 @@ class hashtable_impl size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func ,KeyValueEqual equal_func, Disposer disposer) { + size_type bucket_num; + std::size_t h; + siterator prev; + siterator it = + this->priv_find(key, hash_func, equal_func, bucket_num, h, prev); + bool success = it != priv_invalid_local_it(); size_type count(0); - - if(constant_time_size && this->empty()){ + if(!success){ return 0; } - - bucket_type &b = this->priv_buckets()[from_hash_to_bucket(hash_func(key))]; - siterator it = b.begin(); - siterator prev = b.before_begin(); - - bool found = false; - //Find equal value - while(it != b.end()){ - const value_type &v = - *this->get_real_value_traits().to_value_ptr(it.pointed_node()); - if(equal_func(key, v)){ - found = true; - break; + else if(optimize_multikey){ + siterator last = bucket_type::s_iterator_to + (*node_traits::get_next(priv_get_last_in_group + (dcast_bucket_ptr(it.pointed_node())))); + this->priv_erase_range_impl(bucket_num, prev, last, disposer, count); + } + else{ + //If found erase all equal values + bucket_type &b = this->priv_buckets()[bucket_num]; + for(siterator end = b.end(); it != end; ++count, ++it){ + slist_node_ptr n(it.pointed_node()); + const value_type &v = priv_value_from_slist_node(n); + if(compare_hash){ + std::size_t vh = this->priv_stored_hash(v, store_hash_t()); + if(h != vh || !equal_func(key, v)){ + break; + } + } + else if(!equal_func(key, v)){ + break; + } + this->priv_size_traits().decrement(); } - ++prev; - ++it; - } - - if(!found) - return 0; - - //If found erase all equal values - for(siterator end = b.end(); it != end && - equal_func(key, *this->get_real_value_traits().to_value_ptr(it.pointed_node())) - ; ++count){ - it = b.erase_after_and_dispose - (prev, detail::node_disposer(disposer, this)); - this->priv_size_traits().decrement(); + b.erase_after_and_dispose(prev, it, make_node_disposer(disposer)); } + priv_erasure_update_cache(); return count; } @@ -1179,11 +1237,11 @@ class hashtable_impl size_type num_buckets = this->bucket_count(); bucket_ptr b = this->priv_buckets(); for(; num_buckets--; ++b){ - b->clear_and_dispose - (detail::node_disposer(disposer, this)); + b->clear_and_dispose(make_node_disposer(disposer)); } this->priv_size_traits().set_size(size_type(0)); } + priv_initialize_cache(); } //! Effects: Returns the number of contained elements with the given value @@ -1246,8 +1304,10 @@ class hashtable_impl template iterator find(const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) { - size_type bucket_n, hash; - siterator local_it = this->priv_find(key, hash_func, equal_func, bucket_n, hash); + size_type bucket_n; + std::size_t hash; + siterator prev; + siterator local_it = this->priv_find(key, hash_func, equal_func, bucket_n, hash, prev); return iterator(local_it, this); } @@ -1283,8 +1343,10 @@ class hashtable_impl const_iterator find (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) const { - size_type bucket_n, hash_value; - siterator sit = this->priv_find(key, hash_func, equal_func, bucket_n, hash_value); + size_type bucket_n; + std::size_t hash_value; + siterator prev; + siterator sit = this->priv_find(key, hash_func, equal_func, bucket_n, hash_value, prev); return const_iterator(sit, this); } @@ -1382,7 +1444,7 @@ class hashtable_impl //! Throws: If the internal hash function throws. iterator iterator_to(reference value) { - return iterator(bucket_type::s_iterator_to(from_value_to_node(value)), this); + return iterator(bucket_type::s_iterator_to(priv_value_to_node(value)), this); } //! Requires: value must be an lvalue and shall be in a unordered_set of @@ -1396,12 +1458,9 @@ class hashtable_impl //! Throws: If the internal hash function throws. const_iterator iterator_to(const_reference value) const { - return const_iterator(bucket_type::s_iterator_to(from_value_to_node(const_cast(value))), this); + return const_iterator(bucket_type::s_iterator_to(priv_value_to_node(const_cast(value))), this); } - - - //! Requires: value must be an lvalue and shall be in a unordered_set of //! appropriate type. Otherwise the behavior is undefined. //! @@ -1417,7 +1476,7 @@ class hashtable_impl static local_iterator s_local_iterator_to(reference value) { BOOST_STATIC_ASSERT((!stateful_value_traits)); - siterator sit = bucket_type::s_iterator_to(((hashtable_impl*)0)->from_value_to_node(value)); + siterator sit = bucket_type::s_iterator_to(((hashtable_impl*)0)->priv_value_to_node(value)); return local_iterator(sit, (hashtable_impl*)0); } @@ -1436,7 +1495,7 @@ class hashtable_impl static const_local_iterator s_local_iterator_to(const_reference value) { BOOST_STATIC_ASSERT((!stateful_value_traits)); - siterator sit = bucket_type::s_iterator_to(((hashtable_impl*)0)->from_value_to_node(const_cast(value))); + siterator sit = bucket_type::s_iterator_to(((hashtable_impl*)0)->priv_value_to_node(const_cast(value))); return const_local_iterator(sit, (hashtable_impl*)0); } @@ -1451,7 +1510,7 @@ class hashtable_impl //! Throws: Nothing. local_iterator local_iterator_to(reference value) { - siterator sit = bucket_type::s_iterator_to(this->from_value_to_node(value)); + siterator sit = bucket_type::s_iterator_to(this->priv_value_to_node(value)); return local_iterator(sit, this); } @@ -1467,7 +1526,7 @@ class hashtable_impl const_local_iterator local_iterator_to(const_reference value) const { siterator sit = bucket_type::s_iterator_to - (const_cast(this->from_value_to_node(value))); + (const_cast(this->priv_value_to_node(value))); return const_local_iterator(sit, this); } @@ -1515,7 +1574,7 @@ class hashtable_impl //! Note: the return value is in the range [0, this->bucket_count()). template size_type bucket(const KeyType& k, const KeyHasher &hash_func) const - { return from_hash_to_bucket(hash_func(k)); } + { return priv_hash_to_bucket(hash_func(k)); } //! Effects: Returns the bucket array pointer passed in the constructor //! or the last rehash function. @@ -1630,75 +1689,87 @@ class hashtable_impl size_type new_buckets_len = new_bucket_traits.bucket_count(); bucket_ptr old_buckets = this->priv_buckets(); size_type old_buckets_len = this->priv_buckets_len(); + //Check power of two bucket array if the option is activated BOOST_INTRUSIVE_INVARIANT_ASSERT (!power_2_buckets || (0 == (new_buckets_len & (new_buckets_len-1u)))); - BOOST_INTRUSIVE_TRY{ - size_type n = 0; - const bool same_buffer = old_buckets == new_buckets; - //If the new bucket length is a common factor - //of the old one we can avoid hash calculations. - const bool fast_shrink = (old_buckets_len > new_buckets_len) && - (power_2_buckets ||(old_buckets_len % new_buckets_len) == 0); - //If we are shrinking the same bucket array and it's - //is a fast shrink, just rehash the last nodes - if(same_buffer && fast_shrink){ - n = new_buckets_len; - } + size_type n = priv_get_cache_bucket_num(); + const bool same_buffer = old_buckets == new_buckets; + //If the new bucket length is a common factor + //of the old one we can avoid hash calculations. + const bool fast_shrink = (old_buckets_len > new_buckets_len) && + (power_2_buckets ||(old_buckets_len % new_buckets_len) == 0); + //If we are shrinking the same bucket array and it's + //is a fast shrink, just rehash the last nodes + size_type new_first_bucket_num = new_buckets_len; + if(same_buffer && fast_shrink && (n < new_buckets_len)){ + n = new_buckets_len; + new_first_bucket_num = priv_get_cache_bucket_num(); + } - //Iterate through nodes - for(; n < old_buckets_len; ++n){ - bucket_type &old_bucket = old_buckets[n]; + //Anti-exception stuff: they destroy the elements if something goes wrong + typedef detail::init_disposer NodeDisposer; + NodeDisposer node_disp; + detail::exception_array_disposer + rollback1(new_buckets[0], node_disp, new_buckets_len); + detail::exception_array_disposer + rollback2(old_buckets[0], node_disp, old_buckets_len); - if(!fast_shrink){ - siterator before_i(old_bucket.before_begin()); - siterator end(old_bucket.end()); - siterator i(old_bucket.begin()); - for(;i != end; ++i){ - const value_type &v = *this->get_real_value_traits().to_value_ptr(i.pointed_node()); - const std::size_t hash_value = this->priv_hash_when_rehashing(v, store_hash_t()); - const size_type new_n = (power_2_buckets) - ? (hash_value & (new_buckets_len-1)) : (hash_value % new_buckets_len); - //If this is a buffer expansion don't move if it's not necessary - if(same_buffer && new_n == n){ - ++before_i; - } - else{ - bucket_type &new_b = new_buckets[new_n]; - new_b.splice_after(new_b.before_begin(), old_bucket, before_i); - i = before_i; - } + //Put size in a safe value for rollback exception + size_type size_backup = this->priv_size_traits().get_size(); + this->priv_size_traits().set_size(0); + //Put cache to safe position + priv_initialize_cache(); + priv_insertion_update_cache(size_type(0u)); + + //Iterate through nodes + for(; n < old_buckets_len; ++n){ + bucket_type &old_bucket = old_buckets[n]; + + if(!fast_shrink){ + siterator before_i(old_bucket.before_begin()); + siterator end(old_bucket.end()); + siterator i(old_bucket.begin()); + for(;i != end; ++i){ + const value_type &v = priv_value_from_slist_node(i.pointed_node()); + const std::size_t hash_value = this->priv_stored_hash(v, store_hash_t()); + const size_type new_n = priv_hash_to_bucket(hash_value, new_buckets_len); + if(cache_begin && new_n < new_first_bucket_num) + new_first_bucket_num = new_n; + siterator last = bucket_type::s_iterator_to + (*priv_get_last_in_group(dcast_bucket_ptr(i.pointed_node()))); + if(same_buffer && new_n == n){ + before_i = last; } - } - else{ - const size_type new_n = (power_2_buckets) - ? (n & (new_buckets_len-1)) - : (n % new_buckets_len); - bucket_type &new_b = new_buckets[new_n]; - new_b.splice_after(new_b.before_begin(), old_bucket); + else{ + bucket_type &new_b = new_buckets[new_n]; + new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last); + } + i = before_i; } } + else{ + const size_type new_n = priv_hash_to_bucket(n, new_buckets_len); + if(cache_begin && new_n < new_first_bucket_num) + new_first_bucket_num = new_n; + bucket_type &new_b = new_buckets[new_n]; + if(!old_bucket.empty()){ + new_b.splice_after( new_b.before_begin() + , old_bucket + , old_bucket.before_begin() + , priv_get_last(old_bucket)); + } + } + } - this->get_real_bucket_traits()= new_bucket_traits; - } - BOOST_INTRUSIVE_CATCH(...){ - for(size_type n = 0; n < new_buckets_len; ++n){ - if(safemode_or_autounlink){ - new_buckets[n].clear_and_dispose - (detail::init_disposer()); - old_buckets[n].clear_and_dispose - (detail::init_disposer()); - } - else{ - new_buckets[n].clear(); - old_buckets[n].clear(); - } - } - this->priv_size_traits().set_size(size_type(0)); - BOOST_INTRUSIVE_RETHROW; - } - BOOST_INTRUSIVE_CATCH_END + this->priv_size_traits().set_size(size_backup); + this->priv_real_bucket_traits() = new_bucket_traits; + priv_initialize_cache(); + priv_insertion_update_cache(new_first_bucket_num); + //priv_erasure_update_cache(); + rollback1.release(); + rollback2.release(); } //! Effects: Returns the nearest new bucket count optimized for @@ -1714,8 +1785,7 @@ class hashtable_impl { const std::size_t *primes = &detail::prime_list_holder<0>::prime_list[0]; const std::size_t *primes_end = primes + detail::prime_list_holder<0>::prime_list_size; - size_type const* bound = - std::lower_bound(primes, primes_end, n); + size_type const* bound = std::lower_bound(primes, primes_end, n); if(bound == primes_end) bound--; return size_type(*bound); @@ -1734,8 +1804,7 @@ class hashtable_impl { const std::size_t *primes = &detail::prime_list_holder<0>::prime_list[0]; const std::size_t *primes_end = primes + detail::prime_list_holder<0>::prime_list_size; - size_type const* bound = - std::upper_bound(primes, primes_end, n); + size_type const* bound = std::upper_bound(primes, primes_end, n); if(bound != primes_end) bound--; return size_type(*bound); @@ -1743,72 +1812,672 @@ class hashtable_impl /// @cond private: + std::size_t priv_hash_to_bucket(std::size_t hash_value) const + { return priv_hash_to_bucket(hash_value, power_2_buckets_t()); } - std::size_t priv_hash_when_rehashing(const value_type &v, detail::true_) - { return node_traits::get_hash(this->get_real_value_traits().to_node_ptr(v)); } + std::size_t priv_hash_to_bucket(std::size_t hash_value, detail::bool_) const + { return hash_value % this->priv_real_bucket_traits().bucket_count(); } - std::size_t priv_hash_when_rehashing(const value_type &v, detail::false_) - { return priv_hasher()(v); } + std::size_t priv_hash_to_bucket(std::size_t hash_value, detail::bool_) const + { return hash_value & (this->priv_real_bucket_traits().bucket_count() - 1); } - void priv_store_hash(node_ptr p, std::size_t h, detail::true_) - { return node_traits::set_hash(p, h); } + std::size_t priv_hash_to_bucket(std::size_t hash_value, std::size_t bucket_len) const + { return priv_hash_to_bucket(hash_value, bucket_len, power_2_buckets_t()); } - void priv_store_hash(node_ptr, std::size_t, detail::false_) - {} - - static siterator invalid_local_it(const real_bucket_traits &b) - { return b.bucket_begin()->end(); } + std::size_t priv_hash_to_bucket(std::size_t hash_value, std::size_t bucket_len, detail::bool_) const + { return hash_value % bucket_len; } - siterator priv_begin(size_type &bucket_num) const + std::size_t priv_hash_to_bucket(std::size_t hash_value, std::size_t bucket_len, detail::bool_) const + { return hash_value & (bucket_len - 1); } + + const key_equal &priv_equal() const + { return static_cast(this->bucket_hash_equal_.get()); } + + key_equal &priv_equal() + { return static_cast(this->bucket_hash_equal_.get()); } + + value_type &priv_value_from_slist_node(slist_node_ptr n) + { return *this->get_real_value_traits().to_value_ptr(dcast_bucket_ptr(n)); } + + const value_type &priv_value_from_slist_node(slist_node_ptr n) const + { return *this->get_real_value_traits().to_value_ptr(dcast_bucket_ptr(n)); } + + const real_bucket_traits &priv_real_bucket_traits(detail::bool_) const + { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; } + + const real_bucket_traits &priv_real_bucket_traits(detail::bool_) const + { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_.get_bucket_traits(*this); } + + real_bucket_traits &priv_real_bucket_traits(detail::bool_) + { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; } + + real_bucket_traits &priv_real_bucket_traits(detail::bool_) + { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_.get_bucket_traits(*this); } + + const real_bucket_traits &priv_real_bucket_traits() const + { return this->priv_real_bucket_traits(detail::bool_()); } + + real_bucket_traits &priv_real_bucket_traits() + { return this->priv_real_bucket_traits(detail::bool_()); } + + const hasher &priv_hasher() const + { return static_cast(this->bucket_hash_equal_.bucket_hash.get()); } + + hasher &priv_hasher() + { return static_cast(this->bucket_hash_equal_.bucket_hash.get()); } + + bucket_ptr priv_buckets() const + { return this->priv_real_bucket_traits().bucket_begin(); } + + size_type priv_buckets_len() const + { return this->priv_real_bucket_traits().bucket_count(); } + + static node_ptr uncast(const_node_ptr ptr) + { return node_ptr(const_cast(detail::get_pointer(ptr))); } + + node &priv_value_to_node(value_type &v) + { return *this->get_real_value_traits().to_node_ptr(v); } + + const node &priv_value_to_node(const value_type &v) const + { return *this->get_real_value_traits().to_node_ptr(v); } + + size_traits &priv_size_traits() + { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_; } + + const size_traits &priv_size_traits() const + { return this->bucket_hash_equal_.bucket_hash.bucket_plus_size_; } + + template + void priv_erase_range_impl + (size_type bucket_num, siterator before_first_it, siterator end, Disposer disposer, size_type &num_erased) { - size_type buckets_len = this->priv_buckets_len(); - for (bucket_num = 0; bucket_num < buckets_len; ++bucket_num){ - bucket_type &b = this->priv_buckets()[bucket_num]; - if(!b.empty()) - return b.begin(); + const bucket_ptr buckets = priv_buckets(); + bucket_type &b = buckets[bucket_num]; + + if(before_first_it == b.before_begin() && end == b.end()){ + priv_erase_range_impl(bucket_num, 1, disposer, num_erased); + } + else{ + num_erased = 0; + siterator to_erase(before_first_it); + ++to_erase; + slist_node_ptr end_ptr = end.pointed_node(); + while(to_erase != end){ + priv_erase_from_group(end_ptr, dcast_bucket_ptr(to_erase.pointed_node()), optimize_multikey_t()); + to_erase = b.erase_after_and_dispose(before_first_it, make_node_disposer(disposer)); + ++num_erased; + } + this->priv_size_traits().set_size(this->priv_size_traits().get_size()-num_erased); } - return invalid_local_it(this->get_real_bucket_traits()); } - void priv_clear_buckets() - { priv_clear_buckets(this->priv_buckets(), this->priv_buckets_len()); } + template + void priv_erase_range_impl + (size_type first_bucket_num, size_type num_buckets, Disposer disposer, size_type &num_erased) + { + //Now fully clear the intermediate buckets + const bucket_ptr buckets = priv_buckets(); + num_erased = 0; + for(size_type i = first_bucket_num; i < (num_buckets + first_bucket_num); ++i){ + bucket_type &b = buckets[i]; + siterator b_begin(b.before_begin()); + siterator nxt(b_begin); + ++nxt; + siterator end(b.end()); + while(nxt != end){ + priv_init_group(nxt.pointed_node(), optimize_multikey_t()); + nxt = b.erase_after_and_dispose + (b_begin, make_node_disposer(disposer)); + this->priv_size_traits().decrement(); + ++num_erased; + } + } + } - static void priv_clear_buckets(bucket_ptr buckets_ptr, size_type buckets_len) + template + void priv_erase_range( siterator before_first_it, size_type first_bucket + , siterator last_it, size_type last_bucket + , Disposer disposer) + { + size_type num_erased; + if (first_bucket == last_bucket){ + priv_erase_range_impl(first_bucket, before_first_it, last_it, disposer, num_erased); + } + else { + bucket_type *b = (&this->priv_buckets()[0]); + priv_erase_range_impl(first_bucket, before_first_it, b[first_bucket].end(), disposer, num_erased); + if(size_type n = (last_bucket - first_bucket - 1)) + priv_erase_range_impl(first_bucket + 1, n, disposer, num_erased); + priv_erase_range_impl(last_bucket, b[last_bucket].before_begin(), last_it, disposer, num_erased); + } + } + + static node_ptr dcast_bucket_ptr(typename slist_impl::node_ptr p) + { return node_ptr(&static_cast(*p)); } + + std::size_t priv_stored_hash(const value_type &v, detail::true_) const + { return node_traits::get_hash(this->get_real_value_traits().to_node_ptr(v)); } + + std::size_t priv_stored_hash(const value_type &v, detail::false_) const + { return priv_hasher()(v); } + + std::size_t priv_stored_hash(slist_node_ptr n, detail::true_) const + { return node_traits::get_hash(dcast_bucket_ptr(n)); } + + std::size_t priv_stored_hash(slist_node_ptr, detail::false_) const + { + //This code should never be reached! + BOOST_INTRUSIVE_INVARIANT_ASSERT(0); + return 0; + } + + static void priv_store_hash(node_ptr p, std::size_t h, detail::true_) + { return node_traits::set_hash(p, h); } + + static void priv_store_hash(node_ptr, std::size_t, detail::false_) + {} + + static void priv_clear_group_nodes(bucket_type &b, detail::true_) + { + siterator it(b.begin()), itend(b.end()); + while(it != itend){ + node_ptr to_erase(dcast_bucket_ptr(it.pointed_node())); + ++it; + group_algorithms::init(to_erase); + } + } + + static void priv_clear_group_nodes(bucket_type &, detail::false_) + {} + + std::size_t priv_get_bucket_num(siterator it) + { return priv_get_bucket_num_hash_dispatch(it, store_hash_t()); } + + std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::true_) + { + return this->priv_hash_to_bucket + (this->priv_stored_hash(it.pointed_node(), store_hash_t())); + } + + std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::false_) + { return priv_get_bucket_num_no_hash_store(it, optimize_multikey_t()); } + + std::size_t priv_get_bucket_num_no_hash_store( siterator it, detail::true_) + { + bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1); + slist_node_ptr bb = priv_get_bucket_before_begin + ( f->end().pointed_node() + , l->end().pointed_node() + , dcast_bucket_ptr(it.pointed_node())); + //Now get the bucket_impl from the iterator + const bucket_type &b = static_cast + (bucket_type::slist_type::container_from_end_iterator(bucket_type::s_iterator_to(*bb))); + //Now just calculate the index b has in the bucket array + return static_cast(&b - &*f); + } + + std::size_t priv_get_bucket_num_no_hash_store( siterator it, detail::false_) + { + bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1); + slist_node_ptr first_ptr(f->cend().pointed_node()) + , last_ptr(l->cend().pointed_node()); + + //The end node is embedded in the singly linked list: + //iterate until we reach it. + while(!(first_ptr <= it.pointed_node() && it.pointed_node() <= last_ptr)){ + ++it; + } + //Now get the bucket_impl from the iterator + const bucket_type &b = static_cast + (bucket_type::container_from_end_iterator(it)); + + //Now just calculate the index b has in the bucket array + return static_cast(&b - &*f); + } + + void priv_erase_from_group(slist_node_ptr end_ptr, node_ptr to_erase_ptr, detail::true_) + { + node_ptr nxt_ptr(node_traits::get_next(to_erase_ptr)); + node_ptr prev_in_group_ptr(group_traits::get_next(to_erase_ptr)); + bool last_in_group = (end_ptr == nxt_ptr) || + (group_traits::get_next(nxt_ptr) != to_erase_ptr); + bool first_in_group = node_traits::get_next(prev_in_group_ptr) != to_erase_ptr; + + if(first_in_group && last_in_group){ + group_algorithms::init(to_erase_ptr); + } + else if(first_in_group){ + group_algorithms::unlink_after(nxt_ptr); + } + else if(last_in_group){ + node_ptr first_in_group = //possible_first_in_group ? possible_first_in_group : + priv_get_first_in_group_of_last_in_group(to_erase_ptr); + group_algorithms::unlink_after(first_in_group); + //possible_first_in_group = 0; + } + else{ + group_algorithms::unlink_after(nxt_ptr); + } + } + + void priv_erase_from_group(slist_node_ptr, node_ptr, detail::false_) + {} + + void priv_init_group(slist_node_ptr n, detail::true_) + { group_algorithms::init(dcast_bucket_ptr(n)); } + + void priv_init_group(slist_node_ptr, detail::false_) + {} + + void priv_insert_in_group(node_ptr first_in_group, node_ptr n, detail::true_) + { + if(first_in_group){ + if(group_algorithms::unique(first_in_group)) + group_algorithms::link_after(first_in_group, n); + else{ + group_algorithms::link_after(node_traits::get_next(first_in_group), n); + } + } + else{ + group_algorithms::init_header(n); + } + } + + static slist_node_ptr priv_get_bucket_before_begin + (slist_node_ptr bucket_beg, slist_node_ptr bucket_end, node_ptr p) + { + //First find the last node of p's group. + //This requires checking the first node of the next group or + //the bucket node. + node_ptr prev_node = p; + node_ptr nxt(node_traits::get_next(p)); + while(!(bucket_beg <= nxt && nxt <= bucket_end) && + (group_traits::get_next(nxt) == prev_node)){ + prev_node = nxt; + nxt = node_traits::get_next(nxt); + } + + //If we've reached the bucket node just return it. + if(bucket_beg <= nxt && nxt <= bucket_end){ + return nxt; + } + + //Otherwise, iterate using group links until the bucket node + node_ptr first_node_of_group = nxt; + node_ptr last_node_group = group_traits::get_next(first_node_of_group); + slist_node_ptr possible_end = node_traits::get_next(last_node_group); + + while(!(bucket_beg <= possible_end && possible_end <= bucket_end)){ + first_node_of_group = dcast_bucket_ptr(possible_end); + last_node_group = group_traits::get_next(first_node_of_group); + possible_end = node_traits::get_next(last_node_group); + } + return possible_end; + } + + static node_ptr priv_get_prev_to_first_in_group(slist_node_ptr bucket_node, node_ptr first_in_group) + { + //Just iterate using group links and obtain the node + //before "first_in_group)" + node_ptr prev_node = dcast_bucket_ptr(bucket_node); + node_ptr nxt(node_traits::get_next(prev_node)); + while(nxt != first_in_group){ + prev_node = group_traits::get_next(nxt); + nxt = node_traits::get_next(prev_node); + } + return prev_node; + } + + static node_ptr priv_get_first_in_group_of_last_in_group(node_ptr last_in_group) + { + //Just iterate using group links and obtain the node + //before "last_in_group" + node_ptr possible_first = group_traits::get_next(last_in_group); + node_ptr possible_first_prev = group_traits::get_next(possible_first); + // The deleted node is at the end of the group, so the + // node in the group pointing to it is at the beginning + // of the group. Find that to change its pointer. + while(possible_first_prev != last_in_group){ + possible_first = possible_first_prev; + possible_first_prev = group_traits::get_next(possible_first); + } + return possible_first; + } + + void priv_insert_in_group(node_ptr, node_ptr, detail::false_) + {} + + static node_ptr priv_get_last_in_group(node_ptr first_in_group) + { return priv_get_last_in_group(first_in_group, optimize_multikey_t()); } + + static node_ptr priv_get_last_in_group(node_ptr first_in_group, detail::true_) + { return group_traits::get_next(first_in_group); } + + static node_ptr priv_get_last_in_group(node_ptr n, detail::false_) + { return n; } + + siterator priv_get_previous + (bucket_type &b, siterator i) + { return priv_get_previous(b, i, optimize_multikey_t()); } + + siterator priv_get_previous + (bucket_type &b, siterator i, detail::true_) + { + node_ptr elem(dcast_bucket_ptr(i.pointed_node())); + node_ptr prev_in_group(group_traits::get_next(elem)); + bool first_in_group = node_traits::get_next(prev_in_group) != elem; + + typename bucket_type::node &n = first_in_group + ? *priv_get_prev_to_first_in_group(b.end().pointed_node(), elem) + : *group_traits::get_next(elem) + ; + return bucket_type::s_iterator_to(n); + } + + siterator priv_get_previous + (bucket_type &b, siterator i, detail::false_) + { return b.previous(i); } + + static siterator priv_get_last(bucket_type &b) + { return priv_get_last(b, optimize_multikey_t()); } + + static siterator priv_get_last(bucket_type &b, detail::true_) + { + //First find the last node of p's group. + //This requires checking the first node of the next group or + //the bucket node. + slist_node_ptr end_ptr(b.end().pointed_node()); + node_ptr possible_end(node_traits::get_next( dcast_bucket_ptr(end_ptr))); + node_ptr last_node_group(possible_end); + + while(end_ptr != possible_end){ + last_node_group = group_traits::get_next(dcast_bucket_ptr(possible_end)); + possible_end = node_traits::get_next(last_node_group); + } + return bucket_type::s_iterator_to(*last_node_group); + } + + static siterator priv_get_last(bucket_type &b, detail::false_) + { return b.previous(b.end()); } + + siterator priv_get_previous_and_next_in_group + (siterator i, node_ptr &nxt_in_group) + { + siterator prev; + node_ptr elem(dcast_bucket_ptr(i.pointed_node())); + bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1); + + slist_node_ptr first_end_ptr(f->cend().pointed_node()); + slist_node_ptr last_end_ptr (l->cend().pointed_node()); + + node_ptr nxt(node_traits::get_next(elem)); + node_ptr prev_in_group(group_traits::get_next(elem)); + bool last_in_group = (first_end_ptr <= nxt && nxt <= last_end_ptr) || + (group_traits::get_next(nxt) != elem); + bool first_in_group = node_traits::get_next(prev_in_group) != elem; + + if(first_in_group){ + node_ptr start_pos; + if(last_in_group){ + start_pos = elem; + nxt_in_group = 0; + } + else{ + start_pos = prev_in_group; + nxt_in_group = node_traits::get_next(elem); + } + slist_node_ptr bucket_node; + if(store_hash){ + bucket_node = this->priv_buckets() + [this->priv_hash_to_bucket + (this->priv_stored_hash(elem, store_hash_t())) + ].before_begin().pointed_node(); + } + else{ + bucket_node = priv_get_bucket_before_begin + (first_end_ptr, last_end_ptr, start_pos); + } + prev = bucket_type::s_iterator_to + (*priv_get_prev_to_first_in_group(bucket_node, elem)); + } + else{ + if(last_in_group){ + nxt_in_group = priv_get_first_in_group_of_last_in_group(elem); + } + else{ + nxt_in_group = node_traits::get_next(elem); + } + prev = bucket_type::s_iterator_to(*group_traits::get_next(elem)); + } + return prev; + } + + template + void priv_erase(const_iterator i, Disposer disposer, detail::true_) + { + siterator elem(i.slist_it()); + node_ptr nxt_in_group; + siterator prev = priv_get_previous_and_next_in_group(elem, nxt_in_group); + bucket_type::s_erase_after_and_dispose(prev, make_node_disposer(disposer)); + if(nxt_in_group) + group_algorithms::unlink_after(nxt_in_group); + if(safemode_or_autounlink) + group_algorithms::init(dcast_bucket_ptr(elem.pointed_node())); + } + + template + void priv_erase(const_iterator i, Disposer disposer, detail::false_) + { + siterator to_erase(i.slist_it()); + bucket_type &b = this->priv_buckets()[this->priv_get_bucket_num(to_erase)]; + siterator prev(priv_get_previous(b, to_erase)); + b.erase_after_and_dispose(prev, make_node_disposer(disposer)); + } + + bucket_ptr priv_invalid_bucket() const + { + const real_bucket_traits &rbt = this->priv_real_bucket_traits(); + return rbt.bucket_begin() + rbt.bucket_count(); + } + + siterator priv_invalid_local_it() const + { return priv_invalid_bucket()->end(); } + + siterator priv_begin(size_type &bucket_num) const + { return priv_begin(bucket_num, cache_begin_t()); } + + siterator priv_begin(size_type &bucket_num, detail::bool_) const + { + size_type n = 0; + size_type buckets_len = this->priv_buckets_len(); + for (n = 0; n < buckets_len; ++n){ + bucket_type &b = this->priv_buckets()[n]; + if(!b.empty()){ + bucket_num = n; + return b.begin(); + } + } + bucket_num = n; + return priv_invalid_local_it(); + } + + siterator priv_begin(size_type &bucket_num, detail::bool_) const + { + bucket_num = this->bucket_hash_equal_.cached_begin_ - this->priv_buckets(); + if(this->bucket_hash_equal_.cached_begin_ == priv_invalid_bucket()){ + return priv_invalid_local_it(); + } + else{ + return this->bucket_hash_equal_.cached_begin_->begin(); + } + } + + void priv_initialize_cache() + { priv_initialize_cache(cache_begin_t()); } + + void priv_initialize_cache(detail::bool_) + { this->bucket_hash_equal_.cached_begin_ = priv_invalid_bucket(); } + + void priv_initialize_cache(detail::bool_) + {} + + void priv_insertion_update_cache(size_type insertion_bucket) + { priv_insertion_update_cache(insertion_bucket, cache_begin_t()); } + + void priv_insertion_update_cache(size_type insertion_bucket, detail::bool_) + { + bucket_ptr p = priv_buckets() + insertion_bucket; + if(p < this->bucket_hash_equal_.cached_begin_){ + this->bucket_hash_equal_.cached_begin_ = p; + } + } + + void priv_insertion_update_cache(size_type, detail::bool_) + {} + + void priv_erasure_update_cache(size_type first_bucket, size_type last_bucket) + { priv_erasure_update_cache(first_bucket, last_bucket, cache_begin_t()); } + + void priv_erasure_update_cache(size_type first_bucket_num, size_type last_bucket_num, detail::bool_) + { + //If the last bucket is the end, the cache must be updated + //to the last position if all + if(priv_get_cache_bucket_num() == first_bucket_num && + priv_buckets()[first_bucket_num].empty() ){ + priv_set_cache(priv_buckets() + last_bucket_num); + priv_erasure_update_cache(); + } + } + + void priv_erasure_update_cache(size_type, size_type, detail::bool_) + {} + + void priv_erasure_update_cache() + { priv_erasure_update_cache(cache_begin_t()); } + + void priv_erasure_update_cache(detail::bool_) + { + if(constant_time_size && !size()){ + priv_initialize_cache(); + } + else{ + size_type current_n = this->bucket_hash_equal_.cached_begin_ - priv_buckets(); + for( const size_type num_buckets = this->priv_buckets_len() + ; current_n < num_buckets + ; ++current_n, ++this->bucket_hash_equal_.cached_begin_){ + if(!this->bucket_hash_equal_.cached_begin_->empty()){ + return; + } + } + priv_initialize_cache(); + } + } + + void priv_erasure_update_cache(detail::bool_) + {} + + void priv_swap_cache(detail::bool_, hashtable_impl &other) + { + std::swap( this->bucket_hash_equal_.cached_begin_ + , other.bucket_hash_equal_.cached_begin_); + } + + void priv_swap_cache(detail::bool_, hashtable_impl &) + {} + + bucket_ptr priv_get_cache() + { return priv_get_cache(cache_begin_t()); } + + bucket_ptr priv_get_cache(detail::bool_) + { return this->bucket_hash_equal_.cached_begin_; } + + bucket_ptr priv_get_cache(detail::bool_) + { return this->priv_buckets(); } + + void priv_set_cache(bucket_ptr p) + { priv_set_cache(p, cache_begin_t()); } + + void priv_set_cache(bucket_ptr p, detail::bool_) + { this->bucket_hash_equal_.cached_begin_ = p; } + + void priv_set_cache(bucket_ptr, detail::bool_) + {} + + size_type priv_get_cache_bucket_num() + { return priv_get_cache_bucket_num(cache_begin_t()); } + + size_type priv_get_cache_bucket_num(detail::bool_) + { return this->bucket_hash_equal_.cached_begin_ - this->priv_buckets(); } + + size_type priv_get_cache_bucket_num(detail::bool_) + { return 0u; } + + void priv_clear_buckets() + { + this->priv_clear_buckets + ( priv_get_cache() + , this->priv_buckets_len() - (priv_get_cache() - priv_buckets())); + } + + void priv_initialize_buckets() + { + this->priv_clear_buckets + ( priv_buckets(), this->priv_buckets_len()); + } + + void priv_clear_buckets(bucket_ptr buckets_ptr, size_type buckets_len) { for(; buckets_len--; ++buckets_ptr){ if(safemode_or_autounlink){ + priv_clear_group_nodes(*buckets_ptr, optimize_multikey_t()); buckets_ptr->clear_and_dispose(detail::init_disposer()); } else{ buckets_ptr->clear(); } } + priv_initialize_cache(); } template siterator priv_find ( const KeyType &key, KeyHasher hash_func - , KeyValueEqual equal_func, size_type &bucket_number, size_type &h) const + , KeyValueEqual equal_func, size_type &bucket_number, std::size_t &h, siterator &previt) const { - bucket_number = from_hash_to_bucket((h = hash_func(key))); + bucket_number = priv_hash_to_bucket((h = hash_func(key))); if(constant_time_size && this->empty()){ - return invalid_local_it(this->get_real_bucket_traits()); + return priv_invalid_local_it(); } bucket_type &b = this->priv_buckets()[bucket_number]; - siterator it = b.begin(); + previt = b.before_begin(); + siterator it = previt; + ++it; while(it != b.end()){ - const value_type &v = - *this->get_real_value_traits().to_value_ptr(it.pointed_node()); - if(equal_func(key, v)){ + const value_type &v = priv_value_from_slist_node(it.pointed_node()); + if(compare_hash){ + std::size_t vh = this->priv_stored_hash(v, store_hash_t()); + if(h == vh && equal_func(key, v)){ + return it; + } + } + else if(equal_func(key, v)){ return it; } + if(optimize_multikey){ + previt = bucket_type::s_iterator_to + (*priv_get_last_in_group(dcast_bucket_ptr(it.pointed_node()))); + it = previt; + } + else{ + previt = it; + } ++it; } - return invalid_local_it(this->get_real_bucket_traits()); + return priv_invalid_local_it(); } template @@ -1820,33 +2489,52 @@ class hashtable_impl , size_type &bucket_number_second , size_type &count) const { - size_type h; + std::size_t h; count = 0; + siterator prev; //Let's see if the element is present std::pair to_return - ( priv_find(key, hash_func, equal_func, bucket_number_first, h) - , invalid_local_it(this->get_real_bucket_traits())); + ( priv_find(key, hash_func, equal_func, bucket_number_first, h, prev) + , priv_invalid_local_it()); if(to_return.first == to_return.second){ bucket_number_second = bucket_number_first; return to_return; } - ++count; //If it's present, find the first that it's not equal in //the same bucket bucket_type &b = this->priv_buckets()[bucket_number_first]; siterator it = to_return.first; - ++it; - - while(it != b.end()){ - const value_type &v = - *this->get_real_value_traits().to_value_ptr(it.pointed_node()); - if(!equal_func(key, v)){ - to_return.second = it; + if(optimize_multikey){ + to_return.second = bucket_type::s_iterator_to + (*node_traits::get_next(priv_get_last_in_group + (dcast_bucket_ptr(it.pointed_node())))); + count = std::distance(it, to_return.second); + if(to_return.second != b.end()){ bucket_number_second = bucket_number_first; return to_return; } - ++it; + } + else{ ++count; + ++it; + while(it != b.end()){ + const value_type &v = priv_value_from_slist_node(it.pointed_node()); + if(compare_hash){ + std::size_t hv = this->priv_stored_hash(v, store_hash_t()); + if(hv != h || !equal_func(key, v)){ + to_return.second = it; + bucket_number_second = bucket_number_first; + return to_return; + } + } + else if(!equal_func(key, v)){ + to_return.second = it; + bucket_number_second = bucket_number_first; + return to_return; + } + ++it; + ++count; + } } //If we reached the end, find the first, non-empty bucket @@ -1861,22 +2549,25 @@ class hashtable_impl } //Otherwise, return the end node - to_return.second = invalid_local_it(this->get_real_bucket_traits()); + to_return.second = priv_invalid_local_it(); return to_return; } /// @endcond }; /// @cond -template +template < class T + , bool UniqueKeys + , class O1 = none, class O2 = none + , class O3 = none, class O4 = none + , class O5 = none, class O6 = none + , class O7 = none, class O8 = none + , class O9 = none + > struct make_hashtable_opt { typedef typename pack_options - < uset_defaults, O1, O2, O3, O4, O5, O6, O7>::type packed_options; + < uset_defaults, O1, O2, O3, O4, O5, O6, O7, O8, O9>::type packed_options; //Real value traits must be calculated from options typedef typename detail::get_value_traits @@ -1891,9 +2582,13 @@ struct make_hashtable_opt >::type real_value_traits; typedef typename packed_options::bucket_traits specified_bucket_traits; /// @endcond - //Real bucket traits must be calculated from options and calculated valute_traits - typedef typename get_slist_impl - ::type slist_impl; + + //Real bucket traits must be calculated from options and calculated value_traits + typedef typename detail::get_slist_impl + ::type + >::type slist_impl; + typedef typename detail::if_c< detail::is_same < specified_bucket_traits @@ -1905,12 +2600,15 @@ struct make_hashtable_opt typedef usetopt < value_traits + , UniqueKeys , typename packed_options::hash , typename packed_options::equal , typename packed_options::size_type , packed_options::constant_time_size , real_bucket_traits , packed_options::power_2_buckets + , packed_options::cache_begin + , packed_options::compare_hash > type; }; /// @endcond @@ -1923,7 +2621,8 @@ template template #endif struct make_hashtable @@ -1931,7 +2630,7 @@ struct make_hashtable /// @cond typedef hashtable_impl < typename make_hashtable_opt - ::type + ::type > implementation_defined; /// @endcond @@ -1939,12 +2638,12 @@ struct make_hashtable }; #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED -template +template class hashtable - : public make_hashtable::type + : public make_hashtable::type { typedef typename make_hashtable - ::type Base; + ::type Base; public: typedef typename Base::value_traits value_traits; diff --git a/include/boost/intrusive/intrusive_fwd.hpp b/include/boost/intrusive/intrusive_fwd.hpp index 9228bcb..0642fff 100644 --- a/include/boost/intrusive/intrusive_fwd.hpp +++ b/include/boost/intrusive/intrusive_fwd.hpp @@ -283,8 +283,7 @@ template > class bs_set_member_hook; -//hash/unordered -//rbtree/set/multiset +//hashtable/unordered_set/unordered_multiset template < class T , class O1 = none @@ -294,6 +293,8 @@ template , class O5 = none , class O6 = none , class O7 = none + , class O8 = none + , class O9 = none > class hashtable; @@ -306,6 +307,8 @@ template , class O5 = none , class O6 = none , class O7 = none + , class O8 = none + , class O9 = none > class unordered_set; @@ -318,6 +321,8 @@ template , class O5 = none , class O6 = none , class O7 = none + , class O8 = none + , class O9 = none > class unordered_multiset; @@ -337,6 +342,20 @@ template > class unordered_set_member_hook; +template + < class O1 = none + , class O2 = none + , class O3 = none + > +class any_base_hook; + +template + < class O1 = none + , class O2 = none + , class O3 = none + > +class any_member_hook; + } //namespace intrusive { } //namespace boost { diff --git a/include/boost/intrusive/linear_slist_algorithms.hpp b/include/boost/intrusive/linear_slist_algorithms.hpp index 681c13b..b52a7ba 100644 --- a/include/boost/intrusive/linear_slist_algorithms.hpp +++ b/include/boost/intrusive/linear_slist_algorithms.hpp @@ -53,6 +53,7 @@ class linear_slist_algorithms typedef detail::common_slist_algorithms base_t; /// @endcond public: + typedef typename NodeTraits::node node; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; typedef NodeTraits node_traits; @@ -136,7 +137,7 @@ class linear_slist_algorithms //! //! Throws: Nothing. static void init_header(node_ptr this_node) - { NodeTraits::set_next(this_node, 0); } + { NodeTraits::set_next(this_node, node_ptr(0)); } //! Requires: this_node and prev_init_node must be in the same linear list. //! @@ -195,7 +196,7 @@ class linear_slist_algorithms //! Complexity: This function is linear to the contained elements. static node_ptr reverse(node_ptr p) { - if(!p) return 0; + if(!p) return node_ptr(0); node_ptr i = NodeTraits::get_next(p); node_ptr first(p); while(i){ @@ -218,7 +219,7 @@ class linear_slist_algorithms //! Complexity: Linear to the number of elements plus the number moved positions. static std::pair move_first_n_backwards(node_ptr p, std::size_t n) { - std::pair ret(0, 0); + std::pair ret(node_ptr(0), node_ptr(0)); //Null shift, or count() == 0 or 1, nothing to do if(!n || !p || !NodeTraits::get_next(p)){ return ret; @@ -252,12 +253,12 @@ class linear_slist_algorithms //If the p has not been found in the previous loop, find it //starting in the new first node and unlink it if(!end_found){ - old_last = base_t::get_previous_node(first, 0); + old_last = base_t::get_previous_node(first, node_ptr(0)); } //Now link p after the new last node NodeTraits::set_next(old_last, p); - NodeTraits::set_next(new_last, 0); + NodeTraits::set_next(new_last, node_ptr(0)); ret.first = first; ret.second = new_last; return ret; @@ -273,7 +274,7 @@ class linear_slist_algorithms //! Complexity: Linear to the number of elements plus the number moved positions. static std::pair move_first_n_forward(node_ptr p, std::size_t n) { - std::pair ret(0, 0); + std::pair ret(node_ptr(0), node_ptr(0)); //Null shift, or count() == 0 or 1, nothing to do if(!n || !p || !NodeTraits::get_next(p)) return ret; @@ -311,7 +312,7 @@ class linear_slist_algorithms node_ptr new_first(node_traits::get_next(new_last)); //Now put the old beginning after the old end NodeTraits::set_next(old_last, p); - NodeTraits::set_next(new_last, 0); + NodeTraits::set_next(new_last, node_ptr(0)); ret.first = new_first; ret.second = new_last; return ret; diff --git a/include/boost/intrusive/list.hpp b/include/boost/intrusive/list.hpp index 5968dd2..2b28923 100644 --- a/include/boost/intrusive/list.hpp +++ b/include/boost/intrusive/list.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -586,7 +586,7 @@ class list_impl iterator erase(iterator i) { return this->erase_and_dispose(i, detail::null_disposer()); } - //! Requires: first and last must be valid iterator to elements in *this. + //! Requires: b and e must be valid iterators to elements in *this. //! //! Effects: Erases the element range pointed by b and e //! No destructors are called. @@ -596,8 +596,8 @@ class list_impl //! //! Throws: Nothing. //! - //! Complexity: Linear to the number of elements erased if it's a safe-mode - //! or auto-unlink value. Constant time otherwise. + //! Complexity: Linear to the number of erased elements if it's a safe-mode + //! or auto-unlink value, or constant-time size is enabled. Constant-time otherwise. //! //! Note: Invalidates the iterators (but not the references) to the //! erased elements. @@ -612,6 +612,37 @@ class list_impl } } + //! Requires: b and e must be valid iterators to elements in *this. + //! n must be std::distance(b, e). + //! + //! Effects: Erases the element range pointed by b and e + //! No destructors are called. + //! + //! Returns: the first element remaining beyond the removed elements, + //! or end() if no such element exists. + //! + //! Throws: Nothing. + //! + //! Complexity: Linear to the number of erased elements if it's a safe-mode + //! or auto-unlink value is enabled. Constant-time otherwise. + //! + //! Note: Invalidates the iterators (but not the references) to the + //! erased elements. + iterator erase(iterator b, iterator e, difference_type n) + { + BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(b, e) == difference_type(n)); + if(safemode_or_autounlink || constant_time_size){ + return this->erase_and_dispose(b, e, detail::null_disposer()); + } + else{ + if(constant_time_size){ + this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n); + } + node_algorithms::unlink(b.pointed_node(), e.pointed_node()); + return e; + } + } + //! Requires: Disposer::operator()(pointer) shouldn't throw. //! //! Effects: Erases the element pointed by i of the list. @@ -732,17 +763,13 @@ class list_impl void clone_from(const list_impl &src, Cloner cloner, Disposer disposer) { this->clear_and_dispose(disposer); - BOOST_INTRUSIVE_TRY{ - const_iterator b(src.begin()), e(src.end()); - for(; b != e; ++b){ - this->push_back(*cloner(*b)); - } + detail::exception_disposer + rollback(*this, disposer); + const_iterator b(src.begin()), e(src.end()); + for(; b != e; ++b){ + this->push_back(*cloner(*b)); } - BOOST_INTRUSIVE_CATCH(...){ - this->clear_and_dispose(disposer); - BOOST_INTRUSIVE_RETHROW; - } - BOOST_INTRUSIVE_CATCH_END + rollback.release(); } //! Requires: value must be an lvalue and p must be a valid iterator of *this. diff --git a/include/boost/intrusive/options.hpp b/include/boost/intrusive/options.hpp index ab1f3dc..ab9535a 100644 --- a/include/boost/intrusive/options.hpp +++ b/include/boost/intrusive/options.hpp @@ -49,15 +49,56 @@ struct eval_bucket_traits typedef typename BucketTraits::bucket_traits type; }; +template +struct concrete_hook_base_value_traits +{ + typedef typename BaseHook::boost_intrusive_tags tags; + typedef detail::base_hook_traits + < T + , typename tags::node_traits + , tags::link_mode + , typename tags::tag + , tags::hook_type> type; +}; + +template +struct concrete_hook_base_node_traits +{ typedef typename BaseHook::boost_intrusive_tags::node_traits type; }; + +template +struct any_hook_base_value_traits +{ + typedef typename BaseHook::boost_intrusive_tags tags; + typedef detail::base_hook_traits + < T + , typename BaseHook::node_traits + , tags::link_mode + , typename tags::tag + , tags::hook_type> type; +}; + +template +struct any_hook_base_node_traits +{ typedef typename BaseHook::node_traits type; }; + template struct get_base_value_traits { - typedef detail::base_hook_traits - < T - , typename BaseHook::boost_intrusive_tags::node_traits - , BaseHook::boost_intrusive_tags::link_mode - , typename BaseHook::boost_intrusive_tags::tag - , BaseHook::boost_intrusive_tags::hook_type> type; + typedef typename detail::eval_if_c + < internal_any_hook_bool_is_true::value + , any_hook_base_value_traits + , concrete_hook_base_value_traits + >::type type; +}; + +template +struct get_base_node_traits +{ + typedef typename detail::eval_if_c + < internal_any_hook_bool_is_true::value + , any_hook_base_node_traits + , concrete_hook_base_node_traits + >::type type; }; template @@ -66,6 +107,12 @@ struct get_member_value_traits typedef typename MemberHook::member_value_traits type; }; +template +struct get_member_node_traits +{ + typedef typename MemberHook::member_value_traits::node_traits type; +}; + template struct get_value_traits { @@ -86,25 +133,12 @@ struct get_value_traits >::type type; }; -template -struct get_base_node_traits -{ - typedef typename BaseHook::boost_intrusive_tags::node_traits type; -}; - -template -struct get_member_node_traits -{ - typedef typename MemberHook::member_value_traits::node_traits type; -}; - template struct get_explicit_node_traits { typedef typename ValueTraits::node_traits type; }; - template struct get_node_traits { @@ -125,7 +159,6 @@ struct get_node_traits >::type type; }; - } //namespace detail{ @@ -258,7 +291,6 @@ template< typename Parent struct member_hook { /// @cond - typedef char Parent::* GenericPtrToMember; typedef detail::member_hook_traits < Parent , MemberHook @@ -272,6 +304,7 @@ struct member_hook /// @endcond }; + //!This option setter specifies that the container //!must use the specified base hook template @@ -406,6 +439,24 @@ struct store_hash /// @endcond }; +//!This option setter specifies if the unordered hook +//!should offer room to store another link to another node +//!with the same key. +//!Storing this link will speed up lookups and insertions on +//!unordered_multiset containers with a great number of elements +//!with the same key. +template +struct optimize_multikey +{ +/// @cond + template + struct pack : Base + { + static const bool optimize_multikey = Enabled; + }; +/// @endcond +}; + //!This option setter specifies if the bucket array will be always power of two. //!This allows using masks instead of the default modulo operation to determine //!the bucket number from the hash value, leading to better performance. @@ -423,6 +474,41 @@ struct power_2_buckets /// @endcond }; +//!This option setter specifies if the container will cache a pointer to the first +//!non-empty bucket so that begin() is always constant-time. +//!This is specially helpful when we can have containers with a few elements +//!but with big bucket arrays (that is, hashtables with low load factors). +template +struct cache_begin +{ +/// @cond + template + struct pack : Base + { + static const bool cache_begin = Enabled; + }; +/// @endcond +}; + + +//!This option setter specifies if the container will compare the hash value +//!before comparing objects. This option can't be specified if store_hash<> +//!is not true. +//!This is specially helpful when we have containers with a high load factor. +//!and the comparison function is much more expensive that comparing already +//!stored hash values. +template +struct compare_hash +{ +/// @cond + template + struct pack : Base + { + static const bool compare_hash = Enabled; + }; +/// @endcond +}; + /// @cond template @@ -500,6 +586,7 @@ struct hook_defaults , optimize_size , store_hash , linear + , optimize_multikey >::type {}; diff --git a/include/boost/intrusive/pointer_plus_2_bits.hpp b/include/boost/intrusive/pointer_plus_2_bits.hpp deleted file mode 100644 index c7d9592..0000000 --- a/include/boost/intrusive/pointer_plus_2_bits.hpp +++ /dev/null @@ -1,82 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2007 -// -// 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. -// -///////////////////////////////////////////////////////////////////////////// - -#ifndef BOOST_INTRUSIVE_POINTER_PLUS_2_BIT_HPP -#define BOOST_INTRUSIVE_POINTER_PLUS_2_BIT_HPP - -namespace boost { -namespace intrusive { - -//!This trait class is used to know if a pointer -//!can embed 2 extra bits of information if -//!it's going to be used to point to objects -//!with an alignment of "Alignment" bytes. -template -struct has_pointer_plus_2_bits -{ - static const bool value = false; -}; - -//!This is an specialization for raw pointers. -//!Raw pointers can embed two extra bits in the lower bits -//!if the alignment is multiple of 4. -template -struct has_pointer_plus_2_bits -{ - static const bool value = (N % 4u == 0); -}; - -//!This is class that is supposed to have static methods -//!to embed 2 extra bits of information in a pointer. -//! -//!This is a declaration and there is no default implementation, -//!because operations to embed bits change with every pointer type. -//! -//!An implementation that detects that a pointer type whose -//!has_pointer_plus_2_bits<>::value is non-zero can make use of these -//!operations to embed bits in the pointer. -template -struct pointer_plus_2_bits -{ - static const bool value = false; -}; - -//!This is the specialization to embed 2 extra bits of information -//!in a raw pointer. Extra bits are stored in the lower bits of the pointer. -template -struct pointer_plus_2_bits -{ - typedef T* pointer; - - static pointer get_pointer(pointer n) - { return pointer(std::size_t(n) & ~std::size_t(3u)); } - - static void set_pointer(pointer &n, pointer p) - { - assert(0 == (std::size_t(p) & std::size_t(3u))); - n = pointer(std::size_t(p) | (std::size_t(n) & std::size_t(3u))); - } - - static std::size_t get_bits(pointer n) - { return (std::size_t(n) & std::size_t(3u)); } - - static void set_bits(pointer &n, std::size_t c) - { - assert(c < 4); - n = pointer(std::size_t(get_pointer(n)) | c); - } -}; - -} //namespace intrusive -} //namespace boost - -#endif //BOOST_INTRUSIVE_POINTER_PLUS_2_BIT_HPP diff --git a/include/boost/intrusive/pointer_plus_bit.hpp b/include/boost/intrusive/pointer_plus_bit.hpp deleted file mode 100644 index 863f5f8..0000000 --- a/include/boost/intrusive/pointer_plus_bit.hpp +++ /dev/null @@ -1,78 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2007 -// -// 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. -// -///////////////////////////////////////////////////////////////////////////// - -#ifndef BOOST_INTRUSIVE_POINTER_PLUS_BIT_HPP -#define BOOST_INTRUSIVE_POINTER_PLUS_BIT_HPP - -namespace boost { -namespace intrusive { - -//!This trait class is used to know if a pointer -//!can embed an extra bit of information if -//!it's going to be used to point to objects -//!with an alignment of "Alignment" bytes. -template -struct has_pointer_plus_bit -{ - static const bool value = false; -}; - -//!This is an specialization for raw pointers. -//!Raw pointers can embed an extra bit in the lower bit -//!if the alignment is multiple of 2. -template -struct has_pointer_plus_bit -{ - static const bool value = (N % 2u == 0); -}; - -//!This is class that is supposed to have static methods -//!to embed an extra bit of information in a pointer. -//!This is a declaration and there is no default implementation, -//!because operations to embed the bit change with every pointer type. -//! -//!An implementation that detects that a pointer type whose -//!has_pointer_plus_bit<>::value is non-zero can make use of these -//!operations to embed the bit in the pointer. -template -struct pointer_plus_bit -{ - static const bool value = false; -}; - -//!This is the specialization to embed an extra bit of information -//!in a raw pointer. The extra bit is stored in the lower bit of the pointer. -template -struct pointer_plus_bit -{ - typedef T* pointer; - - static pointer get_pointer(pointer n) - { return pointer(std::size_t(n) & ~std::size_t(1u)); } - - static void set_pointer(pointer &n, pointer p) - { - assert(0 == (std::size_t(p) & std::size_t(1u))); - n = pointer(std::size_t(p) | (std::size_t(n) & std::size_t(1u))); - } - - static bool get_bit(pointer n) - { return (std::size_t(n) & std::size_t(1u)) != 0; } - - static void set_bit(pointer &n, bool c) - { n = pointer(std::size_t(get_pointer(n)) | std::size_t(c)); } -}; - -} //namespace intrusive -} //namespace boost - -#endif //BOOST_INTRUSIVE_POINTER_PLUS_BIT_HPP diff --git a/include/boost/intrusive/pointer_plus_bits.hpp b/include/boost/intrusive/pointer_plus_bits.hpp new file mode 100644 index 0000000..7c77e90 --- /dev/null +++ b/include/boost/intrusive/pointer_plus_bits.hpp @@ -0,0 +1,81 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2007 +// +// 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. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP +#define BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP + +#include //ls_zeros + +namespace boost { +namespace intrusive { + +//!This trait class is used to know if a pointer +//!can embed extra bits of information if +//!it's going to be used to point to objects +//!with an alignment of "Alignment" bytes. +template +struct max_pointer_plus_bits +{ + static const std::size_t value = 0; +}; + +//!This is an specialization for raw pointers. +//!Raw pointers can embed extra bits in the lower bits +//!if the alignment is multiple of 2pow(NumBits). +template +struct max_pointer_plus_bits +{ + static const std::size_t value = detail::ls_zeros::value; +}; + +//!This is class that is supposed to have static methods +//!to embed extra bits of information in a pointer. +//!This is a declaration and there is no default implementation, +//!because operations to embed the bits change with every pointer type. +//! +//!An implementation that detects that a pointer type whose +//!has_pointer_plus_bits<>::value is non-zero can make use of these +//!operations to embed the bits in the pointer. +template +struct pointer_plus_bits; + +//!This is the specialization to embed extra bits of information +//!in a raw pointer. The extra bits are stored in the lower bit of the pointer. +template +struct pointer_plus_bits +{ + static const std::size_t Mask = ((std::size_t(1u) << NumBits) - 1); + typedef T* pointer; + + static pointer get_pointer(pointer n) + { return pointer(std::size_t(n) & ~Mask); } + + static void set_pointer(pointer &n, pointer p) + { + assert(0 == (std::size_t(p) & Mask)); + n = pointer(std::size_t(p) | (std::size_t(n) & Mask)); + } + + static std::size_t get_bits(pointer n) + { return (std::size_t(n) & Mask); } + + static void set_bits(pointer &n, std::size_t c) + { + assert(c <= Mask); + n = pointer(std::size_t(get_pointer(n)) | c); + } +}; + +} //namespace intrusive +} //namespace boost + +#endif //BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP diff --git a/include/boost/intrusive/rbtree.hpp b/include/boost/intrusive/rbtree.hpp index 1682a35..4ec26ab 100644 --- a/include/boost/intrusive/rbtree.hpp +++ b/include/boost/intrusive/rbtree.hpp @@ -379,7 +379,7 @@ class rbtree_impl //! Precondition: end_iterator must be a valid end const_iterator //! of rbtree. //! - //! Effects: Returns a const reference to the rbtree associated to the end iterator + //! Effects: Returns a const reference to the rbtree associated to the iterator //! //! Throws: Nothing. //! @@ -387,6 +387,28 @@ class rbtree_impl static const rbtree_impl &container_from_end_iterator(const_iterator end_iterator) { return priv_container_from_end_iterator(end_iterator); } + //! Precondition: it must be a valid iterator + //! of rbtree. + //! + //! Effects: Returns a const reference to the tree associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static rbtree_impl &container_from_iterator(iterator it) + { return priv_container_from_iterator(it); } + + //! Precondition: it must be a valid end const_iterator + //! of rbtree. + //! + //! Effects: Returns a const reference to the tree associated to the end iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const rbtree_impl &container_from_iterator(const_iterator it) + { return priv_container_from_iterator(it); } + //! Effects: Returns the value_compare object used by the tree. //! //! Complexity: Constant. @@ -1176,33 +1198,26 @@ class rbtree_impl static void init_node(reference value) { node_algorithms::init(value_traits::to_node_ptr(value)); } -/* - //! Effects: removes x from a tree of the appropriate type. It has no effect, - //! if x is not in such a tree. + //! Effects: removes "value" from the container. //! //! Throws: Nothing. //! - //! Complexity: Constant time. + //! Complexity: Logarithmic time. //! - //! Note: This static function is only usable with the "safe mode" - //! hook and non-constant time size lists. Otherwise, the user must use - //! the non-static "erase(reference )" member. If the user calls - //! this function with a non "safe mode" or constant time size list - //! a compilation error will be issued. - template - static void remove_node(T& value) + //! Note: This static function is only usable with non-constant + //! time size containers that have stateless comparison functors. + //! + //! If the user calls + //! this function with a constant time size container or stateful comparison + //! functor a compilation error will be issued. + static void remove_node(reference value) { - //This function is only usable for safe mode hooks and non-constant - //time lists. - //BOOST_STATIC_ASSERT((!(safemode_or_autounlink && constant_time_size))); BOOST_STATIC_ASSERT((!constant_time_size)); - BOOST_STATIC_ASSERT((boost::is_convertible::value)); node_ptr to_remove(value_traits::to_node_ptr(value)); - node_algorithms::unlink_and_rebalance(to_remove); + node_algorithms::unlink(to_remove); if(safemode_or_autounlink) node_algorithms::init(to_remove); } -*/ /// @cond private: @@ -1233,6 +1248,9 @@ class rbtree_impl rbtree_impl *rb = detail::parent_from_member(d, &rbtree_impl::data_); return *rb; } + + static rbtree_impl &priv_container_from_iterator(const const_iterator &it) + { return priv_container_from_end_iterator(it.end_iterator_from_it()); } }; #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED @@ -1426,6 +1444,12 @@ class rbtree static const rbtree &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static rbtree &container_from_it(iterator it) + { return static_cast(Base::container_from_iterator(it)); } + + static const rbtree &container_from_it(const_iterator it) + { return static_cast(Base::container_from_iterator(it)); } }; #endif diff --git a/include/boost/intrusive/rbtree_algorithms.hpp b/include/boost/intrusive/rbtree_algorithms.hpp index c5fae2a..c408193 100644 --- a/include/boost/intrusive/rbtree_algorithms.hpp +++ b/include/boost/intrusive/rbtree_algorithms.hpp @@ -54,7 +54,6 @@ #include #include -#include #include #include @@ -117,6 +116,7 @@ class rbtree_algorithms { public: typedef NodeTraits node_traits; + typedef typename NodeTraits::node node; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; typedef typename NodeTraits::color color; @@ -124,7 +124,6 @@ class rbtree_algorithms /// @cond private: - typedef typename NodeTraits::node node; typedef detail::tree_algorithms tree_algorithms; template @@ -695,6 +694,16 @@ class rbtree_algorithms rebalance_after_insertion(header, new_value); } + //! Requires: "n" must be a node inserted in a tree. + //! + //! Effects: Returns a pointer to the header node of the tree. + //! + //! Complexity: Logarithmic. + //! + //! Throws: Nothing. + static node_ptr get_header(node_ptr n) + { return tree_algorithms::get_header(n); } + /// @cond private: diff --git a/include/boost/intrusive/set.hpp b/include/boost/intrusive/set.hpp index 03c52ab..de0b6c7 100644 --- a/include/boost/intrusive/set.hpp +++ b/include/boost/intrusive/set.hpp @@ -226,7 +226,7 @@ class set_impl //! Precondition: end_iterator must be a valid end iterator //! of set. //! - //! Effects: Returns a const reference to the set associated to the end iterator + //! Effects: Returns a reference to the set associated to the end iterator //! //! Throws: Nothing. //! @@ -253,6 +253,34 @@ class set_impl , &set_impl::tree_); } + //! Precondition: it must be a valid iterator of set. + //! + //! Effects: Returns a reference to the set associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static set_impl &container_from_iterator(iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &set_impl::tree_); + } + + //! Precondition: it must be a valid const_iterator of set. + //! + //! Effects: Returns a const reference to the set associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const set_impl &container_from_iterator(const_iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &set_impl::tree_); + } + //! Effects: Returns the key_compare object used by the set. //! //! Complexity: Constant. @@ -1086,6 +1114,12 @@ class set static const set &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static set &container_from_iterator(iterator it) + { return static_cast(Base::container_from_iterator(it)); } + + static const set &container_from_iterator(const_iterator it) + { return static_cast(Base::container_from_iterator(it)); } }; #endif @@ -1318,6 +1352,34 @@ class multiset_impl , &multiset_impl::tree_); } + //! Precondition: it must be a valid iterator of multiset. + //! + //! Effects: Returns a const reference to the multiset associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + static multiset_impl &container_from_iterator(iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &multiset_impl::tree_); + } + + //! Precondition: it must be a valid const_iterator of multiset. + //! + //! Effects: Returns a const reference to the multiset associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + static const multiset_impl &container_from_iterator(const_iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &multiset_impl::tree_); + } + //! Effects: Returns the key_compare object used by the multiset. //! //! Complexity: Constant. @@ -1932,6 +1994,21 @@ class multiset_impl void replace_node(iterator replace_this, reference with_this) { tree_.replace_node(replace_this, with_this); } + //! Effects: removes "value" from the container. + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic time. + //! + //! Note: This static function is only usable with non-constant + //! time size containers that have stateless comparison functors. + //! + //! If the user calls + //! this function with a constant time size container or stateful comparison + //! functor a compilation error will be issued. + static void remove_node(reference value) + { tree_type::remove_node(value); } + /// @cond friend bool operator==(const multiset_impl &x, const multiset_impl &y) { return x.tree_ == y.tree_; } @@ -2058,6 +2135,12 @@ class multiset static const multiset &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static multiset &container_from_iterator(iterator it) + { return static_cast(Base::container_from_iterator(it)); } + + static const multiset &container_from_iterator(const_iterator it) + { return static_cast(Base::container_from_iterator(it)); } }; #endif diff --git a/include/boost/intrusive/sg_set.hpp b/include/boost/intrusive/sg_set.hpp index 2ef7799..66d461d 100644 --- a/include/boost/intrusive/sg_set.hpp +++ b/include/boost/intrusive/sg_set.hpp @@ -252,6 +252,34 @@ class sg_set_impl , &sg_set_impl::tree_); } + //! Precondition: it must be a valid iterator of set. + //! + //! Effects: Returns a reference to the set associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static sg_set_impl &container_from_iterator(iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &sg_set_impl::tree_); + } + + //! Precondition: it must be a valid const_iterator of set. + //! + //! Effects: Returns a const reference to the set associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const sg_set_impl &container_from_iterator(const_iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &sg_set_impl::tree_); + } + //! Effects: Returns the key_compare object used by the sg_set. //! //! Complexity: Constant. @@ -1124,6 +1152,12 @@ class sg_set static const sg_set &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static sg_set &container_from_iterator(iterator it) + { return static_cast(Base::container_from_iterator(it)); } + + static const sg_set &container_from_iterator(const_iterator it) + { return static_cast(Base::container_from_iterator(it)); } }; #endif @@ -1356,6 +1390,34 @@ class sg_multiset_impl , &sg_multiset_impl::tree_); } + //! Precondition: it must be a valid iterator of multiset. + //! + //! Effects: Returns a const reference to the multiset associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + static sg_multiset_impl &container_from_iterator(iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &sg_multiset_impl::tree_); + } + + //! Precondition: it must be a valid const_iterator of multiset. + //! + //! Effects: Returns a const reference to the multiset associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + static const sg_multiset_impl &container_from_iterator(const_iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &sg_multiset_impl::tree_); + } + //! Effects: Returns the key_compare object used by the sg_multiset. //! //! Complexity: Constant. @@ -2135,6 +2197,12 @@ class sg_multiset static const sg_multiset &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static sg_multiset &container_from_iterator(iterator it) + { return static_cast(Base::container_from_iterator(it)); } + + static const sg_multiset &container_from_iterator(const_iterator it) + { return static_cast(Base::container_from_iterator(it)); } }; #endif diff --git a/include/boost/intrusive/sgtree.hpp b/include/boost/intrusive/sgtree.hpp index d62851f..44ba705 100644 --- a/include/boost/intrusive/sgtree.hpp +++ b/include/boost/intrusive/sgtree.hpp @@ -527,6 +527,28 @@ class sgtree_impl static const sgtree_impl &container_from_end_iterator(const_iterator end_iterator) { return priv_container_from_end_iterator(end_iterator); } + //! Precondition: it must be a valid iterator + //! of rbtree. + //! + //! Effects: Returns a const reference to the tree associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static sgtree_impl &container_from_iterator(iterator it) + { return priv_container_from_iterator(it); } + + //! Precondition: it must be a valid end const_iterator + //! of rbtree. + //! + //! Effects: Returns a const reference to the tree associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const sgtree_impl &container_from_iterator(const_iterator it) + { return priv_container_from_iterator(it); } + //! Effects: Returns the value_compare object used by the tree. //! //! Complexity: Constant. @@ -1442,6 +1464,9 @@ class sgtree_impl sgtree_impl *scapegoat = detail::parent_from_member(d, &sgtree_impl::data_); return *scapegoat; } + + static sgtree_impl &priv_container_from_iterator(const const_iterator &it) + { return priv_container_from_end_iterator(it.end_iterator_from_it()); } }; #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED diff --git a/include/boost/intrusive/sgtree_algorithms.hpp b/include/boost/intrusive/sgtree_algorithms.hpp index 4f2a9c7..18c0884 100644 --- a/include/boost/intrusive/sgtree_algorithms.hpp +++ b/include/boost/intrusive/sgtree_algorithms.hpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -59,6 +58,7 @@ template class sgtree_algorithms { public: + typedef typename NodeTraits::node node; typedef NodeTraits node_traits; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; @@ -66,7 +66,6 @@ class sgtree_algorithms /// @cond private: - typedef typename NodeTraits::node node; typedef detail::tree_algorithms tree_algorithms; static node_ptr uncast(const_node_ptr ptr) @@ -640,6 +639,16 @@ class sgtree_algorithms static node_ptr rebalance_subtree(node_ptr old_root) { return tree_algorithms::rebalance_subtree(old_root); } + //! Requires: "n" must be a node inserted in a tree. + //! + //! Effects: Returns a pointer to the header node of the tree. + //! + //! Complexity: Logarithmic. + //! + //! Throws: Nothing. + static node_ptr get_header(node_ptr n) + { return tree_algorithms::get_header(n); } + /// @cond private: diff --git a/include/boost/intrusive/slist.hpp b/include/boost/intrusive/slist.hpp index 232ab7e..14c614f 100644 --- a/include/boost/intrusive/slist.hpp +++ b/include/boost/intrusive/slist.hpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -25,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -183,10 +183,12 @@ class slist_impl BOOST_STATIC_ASSERT(!(cache_last && ((int)real_value_traits::link_mode == (int)auto_unlink))); node_ptr get_end_node() - { return node_ptr(linear ? 0 : this->get_root_node()); } + { return node_ptr(linear ? node_ptr(0) : this->get_root_node()); } const_node_ptr get_end_node() const - { return const_node_ptr(linear ? 0 : this->get_root_node()); } + { + return const_node_ptr + (linear ? const_node_ptr(0) : this->get_root_node()); } node_ptr get_root_node() { return node_ptr(&data_.root_plus_size_.root_); } @@ -203,13 +205,10 @@ class slist_impl void set_last_node(node_ptr n) { return this->set_last_node(n, detail::bool_()); } - node_ptr get_last_node(detail::bool_) + static node_ptr get_last_node(detail::bool_) { return node_ptr(0); } - const_node_ptr get_last_node(detail::bool_) const - { return const_node_ptr(0); } - - void set_last_node(node_ptr, detail::bool_) + static void set_last_node(node_ptr, detail::bool_) {} node_ptr get_last_node(detail::bool_) @@ -667,18 +666,14 @@ class slist_impl void clone_from(const slist_impl &src, Cloner cloner, Disposer disposer) { this->clear_and_dispose(disposer); - BOOST_INTRUSIVE_TRY{ - iterator prev(this->before_begin()); - const_iterator b(src.begin()), e(src.end()); - for(; b != e; ++b){ - prev = this->insert_after(prev, *cloner(*b)); - } + detail::exception_disposer + rollback(*this, disposer); + iterator prev(this->before_begin()); + const_iterator b(src.begin()), e(src.end()); + for(; b != e; ++b){ + prev = this->insert_after(prev, *cloner(*b)); } - BOOST_INTRUSIVE_CATCH(...){ - this->clear_and_dispose(disposer); - BOOST_INTRUSIVE_RETHROW; - } - BOOST_INTRUSIVE_CATCH_END + rollback.release(); } //! Requires: value must be an lvalue and prev_p must point to an element @@ -783,12 +778,64 @@ class slist_impl //! //! Throws: Nothing. //! - //! Complexity: Lineal to the elements (last - before_first + 1). + //! Complexity: Linear to the number of erased elements if it's a safe-mode + //! , auto-unlink value or constant-time size is activated. Constant time otherwise. //! //! Note: Invalidates the iterators (but not the references) to the //! erased element. iterator erase_after(iterator before_first, iterator last) - { return this->erase_after_and_dispose(before_first, last, detail::null_disposer()); } + { + if(safemode_or_autounlink || constant_time_size){ + return this->erase_after_and_dispose(before_first, last, detail::null_disposer()); + } + else{ + node_ptr bfp = before_first.pointed_node(); + node_ptr lp = last.pointed_node(); + if(cache_last){ + if((lp == this->get_end_node())){ + this->set_last_node(bfp); + } + } + node_algorithms::unlink_after(bfp, lp); + return last; + } + } + + //! Effects: Erases the range (before_first, last) from + //! the list. n must be std::distance(before_first, last) - 1. + //! No destructors are called. + //! + //! Returns: the first element remaining beyond the removed elements, + //! or end() if no such element exists. + //! + //! Throws: Nothing. + //! + //! Complexity: constant-time if link_mode is normal_link. + //! Linear to the elements (last - before_first) otherwise. + //! + //! Note: Invalidates the iterators (but not the references) to the + //! erased element. + iterator erase_after(iterator before_first, iterator last, difference_type n) + { + BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(++iterator(before_first), last) == difference_type(n)); + if(safemode_or_autounlink){ + return this->erase_after(before_first, last); + } + else{ + node_ptr bfp = before_first.pointed_node(); + node_ptr lp = last.pointed_node(); + if(cache_last){ + if((lp == this->get_end_node())){ + this->set_last_node(bfp); + } + } + node_algorithms::unlink_after(bfp, lp); + if(constant_time_size){ + this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n); + } + return last; + } + } //! Effects: Erases the element pointed by i of the list. //! No destructors are called. @@ -815,14 +862,30 @@ class slist_impl //! //! Throws: Nothing. //! - //! Complexity: Linear to the number of elements erased plus linear - //! to the elements before first. + //! Complexity: Linear to the elements before last. //! //! Note: Invalidates the iterators (but not the references) to the //! erased elements. iterator erase(iterator first, iterator last) { return this->erase_after(this->previous(first), last); } + //! Effects: Erases the range [first, last) from + //! the list. n must be std::distance(first, last). + //! No destructors are called. + //! + //! Returns: the first element remaining beyond the removed elements, + //! or end() if no such element exists. + //! + //! Throws: Nothing. + //! + //! Complexity: linear to the elements before first if link_mode is normal_link + //! and constant_time_size is activated. Linear to the elements before last otherwise. + //! + //! Note: Invalidates the iterators (but not the references) to the + //! erased element. + iterator erase(iterator first, iterator last, difference_type n) + { return this->erase_after(this->previous(first), last, n); } + //! Requires: Disposer::operator()(pointer) shouldn't throw. //! //! Effects: Erases the element after the element pointed by prev of @@ -849,13 +912,36 @@ class slist_impl if(cache_last && (to_erase == this->get_last_node())){ this->set_last_node(prev_n); } - this->priv_size_traits().decrement(); if(safemode_or_autounlink) node_algorithms::init(to_erase); disposer(get_real_value_traits().to_value_ptr(to_erase)); + this->priv_size_traits().decrement(); return it; } + /// @cond + + template + static iterator s_erase_after_and_dispose(iterator prev, Disposer disposer) + { + BOOST_STATIC_ASSERT(((!cache_last)&&(!constant_time_size)&&(!stateful_value_traits))); + iterator it(prev); + ++it; + node_ptr to_erase(it.pointed_node()); + ++it; + node_ptr prev_n(prev.pointed_node()); + node_algorithms::unlink_after(prev_n); + if(safemode_or_autounlink) + node_algorithms::init(to_erase); + disposer(real_value_traits::to_value_ptr(to_erase)); + return it; + } + + static iterator s_erase_after(iterator prev) + { return s_erase_after_and_dispose(prev, detail::null_disposer()); } + + /// @endcond + //! Requires: Disposer::operator()(pointer) shouldn't throw. //! //! Effects: Erases the range (before_first, last) from @@ -867,7 +953,7 @@ class slist_impl //! //! Throws: Nothing. //! - //! Complexity: Lineal to the elements (last - before_first). + //! Complexity: Lineal to the elements (last - before_first + 1). //! //! Note: Invalidates the iterators to the erased element. template @@ -921,7 +1007,7 @@ class slist_impl //! //! Throws: Nothing. //! - //! Complexity: Linear to the number of elements erased plus linear + //! Complexity: Linear to the number of erased elements plus linear //! to the elements before first. //! //! Note: Invalidates the iterators (but not the references) to the @@ -997,8 +1083,11 @@ class slist_impl iterator last_x(x.previous(x.end())); //<- constant time if cache_last is active node_ptr prev_n(prev.pointed_node()); node_ptr last_x_n(last_x.pointed_node()); - if(cache_last && node_traits::get_next(prev_n) == this->get_end_node()){ - this->set_last_node(last_x_n); + if(cache_last){ + x.set_last_node(x.get_root_node()); + if(node_traits::get_next(prev_n) == this->get_end_node()){ + this->set_last_node(last_x_n); + } } node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n); this->priv_size_traits().set_size(this->priv_size_traits().get_size() + x.priv_size_traits().get_size()); @@ -1026,10 +1115,7 @@ class slist_impl void splice_after(iterator prev_pos, slist_impl &x, iterator prev_ele) { iterator elem = prev_ele; - ++elem; - if (elem != prev_pos && prev_ele != prev_pos){ - this->splice_after(prev_pos, x, prev_ele, elem, 1); - } + this->splice_after(prev_pos, x, prev_ele, ++elem, 1); } //! Requires: prev_pos must be a dereferenceable iterator in *this or be @@ -1567,15 +1653,18 @@ class slist_impl private: void priv_splice_after(node_ptr prev_pos_n, slist_impl &x, node_ptr before_first_n, node_ptr before_last_n) { - if(cache_last){ - if(node_traits::get_next(prev_pos_n) == this->get_end_node()){ - this->set_last_node(before_last_n); - } - if(node_traits::get_next(before_last_n) == x.get_end_node()){ - x.set_last_node(before_first_n); + if (before_first_n != before_last_n && prev_pos_n != before_first_n && prev_pos_n != before_last_n) + { + if(cache_last){ + if(node_traits::get_next(prev_pos_n) == this->get_end_node()){ + this->set_last_node(before_last_n); + } + if(node_traits::get_next(before_last_n) == x.get_end_node()){ + x.set_last_node(before_first_n); + } } + node_algorithms::transfer_after(prev_pos_n, before_first_n, before_last_n); } - node_algorithms::transfer_after(prev_pos_n, before_first_n, before_last_n); } void priv_reverse(detail::bool_) diff --git a/include/boost/intrusive/splay_set.hpp b/include/boost/intrusive/splay_set.hpp index 82aa409..104063a 100644 --- a/include/boost/intrusive/splay_set.hpp +++ b/include/boost/intrusive/splay_set.hpp @@ -252,6 +252,34 @@ class splay_set_impl , &splay_set_impl::tree_); } + //! Precondition: it must be a valid iterator of set. + //! + //! Effects: Returns a reference to the set associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + static splay_set_impl &container_from_iterator(iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &splay_set_impl::tree_); + } + + //! Precondition: it must be a valid const_iterator of set. + //! + //! Effects: Returns a const reference to the set associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const splay_set_impl &container_from_iterator(const_iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &splay_set_impl::tree_); + } + //! Effects: Returns the key_compare object used by the splay_set. //! //! Complexity: Constant. @@ -1161,6 +1189,12 @@ class splay_set static const splay_set &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static splay_set &container_from_iterator(iterator it) + { return static_cast(Base::container_from_iterator(it)); } + + static const splay_set &container_from_iterator(const_iterator it) + { return static_cast(Base::container_from_iterator(it)); } }; #endif @@ -1393,6 +1427,34 @@ class splay_multiset_impl , &splay_multiset_impl::tree_); } + //! Precondition: it must be a valid iterator of multiset. + //! + //! Effects: Returns a const reference to the multiset associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static splay_multiset_impl &container_from_iterator(iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &splay_multiset_impl::tree_); + } + + //! Precondition: it must be a valid const_iterator of multiset. + //! + //! Effects: Returns a const reference to the multiset associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + static const splay_multiset_impl &container_from_iterator(const_iterator it) + { + return *detail::parent_from_member + ( &tree_type::container_from_iterator(it) + , &splay_multiset_impl::tree_); + } + //! Effects: Returns the key_compare object used by the splay_multiset. //! //! Complexity: Constant. @@ -2209,6 +2271,12 @@ class splay_multiset static const splay_multiset &container_from_end_iterator(const_iterator end_iterator) { return static_cast(Base::container_from_end_iterator(end_iterator)); } + + static splay_multiset &container_from_iterator(iterator it) + { return static_cast(Base::container_from_iterator(it)); } + + static const splay_multiset &container_from_iterator(const_iterator it) + { return static_cast(Base::container_from_iterator(it)); } }; #endif diff --git a/include/boost/intrusive/splaytree.hpp b/include/boost/intrusive/splaytree.hpp index d733f50..e356963 100644 --- a/include/boost/intrusive/splaytree.hpp +++ b/include/boost/intrusive/splaytree.hpp @@ -387,6 +387,28 @@ class splaytree_impl static const splaytree_impl &container_from_end_iterator(const_iterator end_iterator) { return priv_container_from_end_iterator(end_iterator); } + //! Precondition: it must be a valid iterator + //! of rbtree. + //! + //! Effects: Returns a const reference to the tree associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static splaytree_impl &container_from_iterator(iterator it) + { return priv_container_from_iterator(it); } + + //! Precondition: it must be a valid end const_iterator + //! of rbtree. + //! + //! Effects: Returns a const reference to the tree associated to the iterator + //! + //! Throws: Nothing. + //! + //! Complexity: Logarithmic. + static const splaytree_impl &container_from_iterator(const_iterator it) + { return priv_container_from_iterator(it); } + //! Effects: Returns the value_compare object used by the tree. //! //! Complexity: Constant. @@ -1312,6 +1334,9 @@ class splaytree_impl splaytree_impl *rb = detail::parent_from_member(d, &splaytree_impl::data_); return *rb; } + + static splaytree_impl &priv_container_from_iterator(const const_iterator &it) + { return priv_container_from_end_iterator(it.end_iterator_from_it()); } }; #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED diff --git a/include/boost/intrusive/splaytree_algorithms.hpp b/include/boost/intrusive/splaytree_algorithms.hpp index 2fbcb92..409449f 100644 --- a/include/boost/intrusive/splaytree_algorithms.hpp +++ b/include/boost/intrusive/splaytree_algorithms.hpp @@ -50,13 +50,48 @@ #include #include #include -#include #include #include namespace boost { namespace intrusive { +/// @cond +namespace detail { + +template +struct splaydown_rollback +{ + typedef typename NodeTraits::node_ptr node_ptr; + splaydown_rollback( const node_ptr *pcur_subtree, node_ptr header + , node_ptr leftmost , node_ptr rightmost) + : pcur_subtree_(pcur_subtree) , header_(header) + , leftmost_(leftmost) , rightmost_(rightmost) + {} + + void release() + { pcur_subtree_ = 0; } + + ~splaydown_rollback() + { + if(pcur_subtree_){ + //Exception can only be thrown by comp, but + //tree invariants still hold. *pcur_subtree is the current root + //so link it to the header. + NodeTraits::set_parent(*pcur_subtree_, header_); + NodeTraits::set_parent(header_, *pcur_subtree_); + //Recover leftmost/rightmost pointers + NodeTraits::set_left (header_, leftmost_); + NodeTraits::set_right(header_, rightmost_); + } + } + const node_ptr *pcur_subtree_; + node_ptr header_, leftmost_, rightmost_; +}; + +} //namespace detail { +/// @endcond + //! A splay tree is an implementation of a binary search tree. The tree is //! self balancing using the splay algorithm as described in //! @@ -95,11 +130,11 @@ class splaytree_algorithms { /// @cond private: - typedef typename NodeTraits::node node; typedef detail::tree_algorithms tree_algorithms; /// @endcond public: + typedef typename NodeTraits::node node; typedef NodeTraits node_traits; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; @@ -656,7 +691,8 @@ class splaytree_algorithms node_ptr leftmost = NodeTraits::get_left(header); node_ptr rightmost = NodeTraits::get_right(header); - try{ + { + detail::splaydown_rollback rollback(&t, header, leftmost, rightmost); node_ptr null = header; node_ptr l = null; node_ptr r = null; @@ -712,18 +748,9 @@ class splaytree_algorithms } assemble(t, l, r, null); + rollback.release(); } - catch(...){ - //Exception can only be thrown by comp, but - //tree invariants still hold. t is the current root - //so link it to the header. - NodeTraits::set_parent(t, header); - NodeTraits::set_parent(header, t); - //Recover leftmost/rightmost pointers - NodeTraits::set_left (header, leftmost); - NodeTraits::set_right(header, rightmost); - throw; - } + //t is the current root NodeTraits::set_parent(header, t); NodeTraits::set_parent(t, header); @@ -755,6 +782,17 @@ class splaytree_algorithms static node_ptr rebalance_subtree(node_ptr old_root) { return tree_algorithms::rebalance_subtree(old_root); } + + //! Requires: "n" must be a node inserted in a tree. + //! + //! Effects: Returns a pointer to the header node of the tree. + //! + //! Complexity: Logarithmic. + //! + //! Throws: Nothing. + static node_ptr get_header(node_ptr n) + { return tree_algorithms::get_header(n); } + private: /// @cond diff --git a/include/boost/intrusive/unordered_set.hpp b/include/boost/intrusive/unordered_set.hpp index 780fb46..6ec56fc 100644 --- a/include/boost/intrusive/unordered_set.hpp +++ b/include/boost/intrusive/unordered_set.hpp @@ -24,7 +24,7 @@ namespace intrusive { //! The class template unordered_set is an intrusive container, that mimics most of //! the interface of std::tr1::unordered_set as described in the C++ TR1. //! -//! unordered_set is a pseudo-intrusive container: each object to be stored in the +//! unordered_set is a semi-intrusive container: each object to be stored in the //! container must contain a proper hook, but the container also needs //! additional auxiliary memory to work: unordered_set needs a pointer to an array //! of type `bucket_type` to be passed in the constructor. This bucket array must @@ -38,7 +38,8 @@ namespace intrusive { //! //! The container supports the following options: //! \c base_hook<>/member_hook<>/value_traits<>, -//! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<> . +//! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<> +//! \c bucket_traits<>, power_2_buckets<> and cache_begin<>. //! //! unordered_set only provides forward iterators but it provides 4 iterator types: //! iterator and const_iterator to navigate through the whole container and @@ -167,8 +168,8 @@ class unordered_set_impl //! Effects: Returns an iterator pointing to the beginning of the unordered_set. //! - //! Complexity: Amortized constant time. - //! Worst case (empty unordered_set): O(this->bucket_count()) + //! Complexity: Constant time if `cache_begin<>` is true. Amortized + //! constant time with worst case (empty unordered_set) O(this->bucket_count()) //! //! Throws: Nothing. iterator begin() @@ -177,8 +178,8 @@ class unordered_set_impl //! Effects: Returns a const_iterator pointing to the beginning //! of the unordered_set. //! - //! Complexity: Amortized constant time. - //! Worst case (empty unordered_set): O(this->bucket_count()) + //! Complexity: Constant time if `cache_begin<>` is true. Amortized + //! constant time with worst case (empty unordered_set) O(this->bucket_count()) //! //! Throws: Nothing. const_iterator begin() const @@ -187,8 +188,8 @@ class unordered_set_impl //! Effects: Returns a const_iterator pointing to the beginning //! of the unordered_set. //! - //! Complexity: Amortized constant time. - //! Worst case (empty unordered_set): O(this->bucket_count()) + //! Complexity: Constant time if `cache_begin<>` is true. Amortized + //! constant time with worst case (empty unordered_set) O(this->bucket_count()) //! //! Throws: Nothing. const_iterator cbegin() const @@ -236,8 +237,8 @@ class unordered_set_impl //! Effects: Returns true is the container is empty. //! - //! Complexity: if constant-time size option is disabled, average constant time - //! (worst case, with empty() == true): O(this->bucket_count()). + //! Complexity: if constant-time size and cache_last options are disabled, + //! average constant time (worst case, with empty() == true: O(this->bucket_count()). //! Otherwise constant. //! //! Throws: Nothing. @@ -959,7 +960,8 @@ template template #endif struct make_unordered_set @@ -967,19 +969,19 @@ struct make_unordered_set /// @cond typedef unordered_set_impl < typename make_hashtable_opt - ::type + ::type > implementation_defined; /// @endcond typedef implementation_defined type; }; #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED -template +template class unordered_set - : public make_unordered_set::type + : public make_unordered_set::type { typedef typename make_unordered_set - ::type Base; + ::type Base; //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same::value)); @@ -1018,7 +1020,7 @@ class unordered_set //! The class template unordered_multiset is an intrusive container, that mimics most of //! the interface of std::tr1::unordered_multiset as described in the C++ TR1. //! -//! unordered_multiset is a pseudo-intrusive container: each object to be stored in the +//! unordered_multiset is a semi-intrusive container: each object to be stored in the //! container must contain a proper hook, but the container also needs //! additional auxiliary memory to work: unordered_multiset needs a pointer to an array //! of type `bucket_type` to be passed in the constructor. This bucket array must @@ -1032,7 +1034,8 @@ class unordered_set //! //! The container supports the following options: //! \c base_hook<>/member_hook<>/value_traits<>, -//! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<> . +//! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<> +//! \c bucket_traits<>, power_2_buckets<> and cache_begin<>. //! //! unordered_multiset only provides forward iterators but it provides 4 iterator types: //! iterator and const_iterator to navigate through the whole container and @@ -1161,8 +1164,8 @@ class unordered_multiset_impl //! Effects: Returns an iterator pointing to the beginning of the unordered_multiset. //! - //! Complexity: Amortized constant time. - //! Worst case (empty unordered_multiset): O(this->bucket_count()) + //! Complexity: Constant time if `cache_begin<>` is true. Amortized + //! constant time with worst case (empty unordered_set) O(this->bucket_count()) //! //! Throws: Nothing. iterator begin() @@ -1171,8 +1174,8 @@ class unordered_multiset_impl //! Effects: Returns a const_iterator pointing to the beginning //! of the unordered_multiset. //! - //! Complexity: Amortized constant time. - //! Worst case (empty unordered_multiset): O(this->bucket_count()) + //! Complexity: Constant time if `cache_begin<>` is true. Amortized + //! constant time with worst case (empty unordered_set) O(this->bucket_count()) //! //! Throws: Nothing. const_iterator begin() const @@ -1181,8 +1184,8 @@ class unordered_multiset_impl //! Effects: Returns a const_iterator pointing to the beginning //! of the unordered_multiset. //! - //! Complexity: Amortized constant time. - //! Worst case (empty unordered_multiset): O(this->bucket_count()) + //! Complexity: Constant time if `cache_begin<>` is true. Amortized + //! constant time with worst case (empty unordered_set) O(this->bucket_count()) //! //! Throws: Nothing. const_iterator cbegin() const @@ -1230,8 +1233,8 @@ class unordered_multiset_impl //! Effects: Returns true is the container is empty. //! - //! Complexity: if constant-time size option is disabled, average constant time - //! (worst case, with empty() == true): O(this->bucket_count()). + //! Complexity: if constant-time size and cache_last options are disabled, + //! average constant time (worst case, with empty() == true: O(this->bucket_count()). //! Otherwise constant. //! //! Throws: Nothing. @@ -1891,7 +1894,8 @@ template template #endif struct make_unordered_multiset @@ -1899,19 +1903,19 @@ struct make_unordered_multiset /// @cond typedef unordered_multiset_impl < typename make_hashtable_opt - ::type + ::type > implementation_defined; /// @endcond typedef implementation_defined type; }; #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED -template +template class unordered_multiset - : public make_unordered_multiset::type + : public make_unordered_multiset::type { typedef typename make_unordered_multiset - ::type Base; + ::type Base; //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same::value)); diff --git a/include/boost/intrusive/unordered_set_hook.hpp b/include/boost/intrusive/unordered_set_hook.hpp index ffac564..7f6f5bd 100644 --- a/include/boost/intrusive/unordered_set_hook.hpp +++ b/include/boost/intrusive/unordered_set_hook.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -26,35 +27,66 @@ namespace intrusive { /// @cond -template -struct slist_node_plus_hash +template +struct unordered_node + : public slist_node { typedef typename boost::pointer_to_other - ::type node_ptr; - node_ptr next_; + < VoidPointer + , unordered_node + >::type node_ptr; + node_ptr prev_in_group_; std::size_t hash_; }; -// slist_node_traits can be used with circular_slist_algorithms and supplies -// a slist_node holding the pointers needed for a singly-linked list -// it is used by slist_base_hook and slist_member_hook template -struct slist_node_traits_plus_hash +struct unordered_node + : public slist_node { - typedef slist_node_plus_hash node; + typedef typename boost::pointer_to_other + < VoidPointer + , unordered_node + >::type node_ptr; + node_ptr prev_in_group_; +}; + +template +struct unordered_node + : public slist_node +{ + typedef typename boost::pointer_to_other + < VoidPointer + , unordered_node + >::type node_ptr; + std::size_t hash_; +}; + +template +struct unordered_node_traits + : public slist_node_traits +{ + typedef slist_node_traits reduced_slist_node_traits; + typedef unordered_node node; typedef typename boost::pointer_to_other ::type node_ptr; typedef typename boost::pointer_to_other ::type const_node_ptr; - static const bool store_hash = true; + static const bool store_hash = StoreHash; + static const bool optimize_multikey = OptimizeMultiKey; static node_ptr get_next(const_node_ptr n) - { return n->next_; } + { return node_ptr(&static_cast(*n->next_)); } static void set_next(node_ptr n, node_ptr next) { n->next_ = next; } + static node_ptr get_prev_in_group(const_node_ptr n) + { return n->prev_in_group_; } + + static void set_prev_in_group(node_ptr n, node_ptr prev) + { n->prev_in_group_ = prev; } + static std::size_t get_hash(const_node_ptr n) { return n->hash_; } @@ -62,15 +94,60 @@ struct slist_node_traits_plus_hash { n->hash_ = h; } }; -template +template +struct unordered_group_adapter +{ + typedef typename NodeTraits::node node; + typedef typename NodeTraits::node_ptr node_ptr; + typedef typename NodeTraits::const_node_ptr const_node_ptr; + + static node_ptr get_next(const_node_ptr n) + { return NodeTraits::get_prev_in_group(n); } + + static void set_next(node_ptr n, node_ptr next) + { NodeTraits::set_prev_in_group(n, next); } +}; + +template +struct unordered_algorithms + : public circular_slist_algorithms +{ + typedef circular_slist_algorithms base_type; + typedef unordered_group_adapter group_traits; + typedef circular_slist_algorithms group_algorithms; + + static void init(typename base_type::node_ptr n) + { + base_type::init(n); + group_algorithms::init(n); + } + + static void init_header(typename base_type::node_ptr n) + { + base_type::init_header(n); + group_algorithms::init_header(n); + } + + static void unlink(typename base_type::node_ptr n) + { + base_type::unlink(n); + group_algorithms::unlink(n); + } +}; + +template struct get_uset_node_algo { typedef typename detail::if_c - < StoreHash - , slist_node_traits_plus_hash + < (StoreHash || OptimizeMultiKey) + , unordered_node_traits , slist_node_traits >::type node_traits_type; - typedef circular_slist_algorithms type; + typedef typename detail::if_c + < OptimizeMultiKey + , unordered_algorithms + , circular_slist_algorithms + >::type type; }; /// @endcond @@ -90,6 +167,7 @@ struct make_unordered_set_base_hook typedef detail::generic_hook < get_uset_node_algo , typename packed_options::tag , packed_options::link_mode @@ -104,7 +182,7 @@ struct make_unordered_set_base_hook //! the unordered_set/unordered_multi_set and provides an appropriate value_traits class for unordered_set/unordered_multi_set. //! //! The hook admits the following options: \c tag<>, \c void_pointer<>, -//! \c link_mode<> and \c store_hash<>. +//! \c link_mode<>, \c store_hash<> and \c optimize_multikey<>. //! //! \c tag<> defines a tag to identify the node. //! The same tag value can be used in different classes, but if a class is @@ -119,6 +197,10 @@ struct make_unordered_set_base_hook //! //! \c store_hash<> will tell the hook to store the hash of the value //! to speed up rehashings. +//! +//! \c optimize_multikey<> will tell the hook to store a link to form a group +//! with other value with the same value to speed up searches and insertions +//! in unordered_multisets with a great number of with equivalent keys. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED template #else @@ -211,6 +293,7 @@ struct make_unordered_set_member_hook typedef detail::generic_hook < get_uset_node_algo< typename packed_options::void_pointer , packed_options::store_hash + , packed_options::optimize_multikey > , member_tag , packed_options::link_mode diff --git a/index.html b/index.html index 23984f2..8c018f9 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,6 @@ Automatic redirection failed, please go to -../../doc/html/intrusive.html +../../doc/html/intrusive diff --git a/perf/Jamfile.v2 b/perf/Jamfile.v2 index 3c9f3d6..bb6a612 100644 --- a/perf/Jamfile.v2 +++ b/perf/Jamfile.v2 @@ -1,6 +1,6 @@ # Boost Intrusive Library Performance test Jamfile -# (C) Copyright Ion Gaztañaga 2006-2007. +# (C) Copyright Ion Gaztanaga 2006-2007. # Use, modification and distribution are subject to 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) diff --git a/perf/perf_list.cpp b/perf/perf_list.cpp index 99f3b25..5bf8012 100644 --- a/perf/perf_list.cpp +++ b/perf/perf_list.cpp @@ -23,7 +23,7 @@ using namespace boost::posix_time; //[perf_list_value_type //Iteration and element count defines const int NumIter = 100; -const int NumElements = 100000; +const int NumElements = 50000; using namespace boost::intrusive; diff --git a/proj/vc7ide/Intrusive.sln b/proj/vc7ide/Intrusive.sln index 8767b1e..eca4acc 100644 --- a/proj/vc7ide/Intrusive.sln +++ b/proj/vc7ide/Intrusive.sln @@ -1,175 +1,361 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "list", "list\list.vcproj", "{977B61B4-9968-497C-9F0B-24A8145473B8}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slist", "slist\slist.vcproj", "{5A02061D-3728-4C49-AFC8-0130C1F161C0}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multiset", "multiset\multiset.vcproj", "{961F0E06-C092-4AF7-ABC5-2A49999F3B79}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_intrusivelib", "_intrusivelib\_intrusivelib.vcproj", "{90F3C5BD-8E6C-4629-BC71-A1009EC88059}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "set", "set\set.vcproj", "{960E01F6-92C1-F74A-BCA5-2A9F3B994979}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unordered_set", "unordered_set\unordered_set.vcproj", "{90E701E6-2C91-F4A7-BA6C-A9F3B0949279}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unordered_multiset", "unordered_multiset\unordered_multiset.vcproj", "{9101EE76-BB6C-2C91-F4B7-A9F3B9490279}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perf_test", "perf_test\perf_test.vcproj", "{910E70E6-2C91-AA67-BF4C-A9C74A309927}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "default_hook", "default_hook\default_hook.vcproj", "{761A79B4-9968-CB81-F02B-2A4497345475}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stateful_value_traits", "stateful_value_traits\stateful_value_traits.vcproj", "{9571A7B4-9968-B9C1-17FB-134547B46975}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "virtual_base", "virtual_base\virtual_base.vcproj", "{3579B1A4-9894-02AB-CB81-297B46154345}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_functions", "make_functions\make_functions.vcproj", "{7679B41B-F2B4-9176-CB81-35449467B435}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "custom_bucket_traits", "custom_bucket_traits\custom_bucket_traits.vcproj", "{31C77B84-0B2C-9481-CB81-27A149F33825}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "external_value_traits", "external_value_traits\external_value_traits.vcproj", "{97B69A72-B9D3-7389-17FB-74612F4A9543}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "splay_multiset", "splay_multiset\splay_multiset.vcproj", "{01E70176-B6C5-BF47-2C91-A949077BA323}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "splay_set", "splay_set\splay_set.vcproj", "{1E6909E7-C971-F24A-6C7B-A92094B71B59}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "avl_multiset", "avl_multiset\avl_multiset.vcproj", "{0AE70176-5B8C-4BC7-392C-A4A312B07893}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "avl_set", "avl_set\avl_set.vcproj", "{16909EE7-24AF-97C1-C76B-204B971BA959}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sg_multiset", "sg_multiset\sg_multiset.vcproj", "{07022E76-6CB5-92C1-B47F-A10772A79B43}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sg_set", "sg_set\sg_set.vcproj", "{1690A9E7-DB57-971C-F24A-09B752A942F7}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release - EndGlobalSection - GlobalSection(ProjectDependencies) = postSolution - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {977B61B4-9968-497C-9F0B-24A8145473B8}.Debug.ActiveCfg = Debug|Win32 - {977B61B4-9968-497C-9F0B-24A8145473B8}.Debug.Build.0 = Debug|Win32 - {977B61B4-9968-497C-9F0B-24A8145473B8}.Release.ActiveCfg = Release|Win32 - {977B61B4-9968-497C-9F0B-24A8145473B8}.Release.Build.0 = Release|Win32 - {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Debug.ActiveCfg = Debug|Win32 - {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Debug.Build.0 = Debug|Win32 - {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Release.ActiveCfg = Release|Win32 - {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Release.Build.0 = Release|Win32 - {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Debug.ActiveCfg = Debug|Win32 - {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Debug.Build.0 = Debug|Win32 - {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Release.ActiveCfg = Release|Win32 - {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Release.Build.0 = Release|Win32 - {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Debug.ActiveCfg = Debug|Win32 - {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Debug.Build.0 = Debug|Win32 - {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Release.ActiveCfg = Release|Win32 - {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Release.Build.0 = Release|Win32 - {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Debug.ActiveCfg = Debug|Win32 - {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Debug.Build.0 = Debug|Win32 - {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Release.ActiveCfg = Release|Win32 - {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Release.Build.0 = Release|Win32 - {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Debug.ActiveCfg = Debug|Win32 - {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Debug.Build.0 = Debug|Win32 - {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Release.ActiveCfg = Release|Win32 - {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Release.Build.0 = Release|Win32 - {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Debug.ActiveCfg = Debug|Win32 - {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Debug.Build.0 = Debug|Win32 - {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Release.ActiveCfg = Release|Win32 - {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Release.Build.0 = Release|Win32 - {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Debug.ActiveCfg = Debug|Win32 - {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Debug.Build.0 = Debug|Win32 - {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Release.ActiveCfg = Release|Win32 - {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Release.Build.0 = Release|Win32 - {761A79B4-9968-CB81-F02B-2A4497345475}.Debug.ActiveCfg = Debug|Win32 - {761A79B4-9968-CB81-F02B-2A4497345475}.Debug.Build.0 = Debug|Win32 - {761A79B4-9968-CB81-F02B-2A4497345475}.Release.ActiveCfg = Release|Win32 - {761A79B4-9968-CB81-F02B-2A4497345475}.Release.Build.0 = Release|Win32 - {9571A7B4-9968-B9C1-17FB-134547B46975}.Debug.ActiveCfg = Debug|Win32 - {9571A7B4-9968-B9C1-17FB-134547B46975}.Debug.Build.0 = Debug|Win32 - {9571A7B4-9968-B9C1-17FB-134547B46975}.Release.ActiveCfg = Release|Win32 - {9571A7B4-9968-B9C1-17FB-134547B46975}.Release.Build.0 = Release|Win32 - {3579B1A4-9894-02AB-CB81-297B46154345}.Debug.ActiveCfg = Debug|Win32 - {3579B1A4-9894-02AB-CB81-297B46154345}.Debug.Build.0 = Debug|Win32 - {3579B1A4-9894-02AB-CB81-297B46154345}.Release.ActiveCfg = Release|Win32 - {3579B1A4-9894-02AB-CB81-297B46154345}.Release.Build.0 = Release|Win32 - {7679B41B-F2B4-9176-CB81-35449467B435}.Debug.ActiveCfg = Debug|Win32 - {7679B41B-F2B4-9176-CB81-35449467B435}.Debug.Build.0 = Debug|Win32 - {7679B41B-F2B4-9176-CB81-35449467B435}.Release.ActiveCfg = Release|Win32 - {7679B41B-F2B4-9176-CB81-35449467B435}.Release.Build.0 = Release|Win32 - {31C77B84-0B2C-9481-CB81-27A149F33825}.Debug.ActiveCfg = Debug|Win32 - {31C77B84-0B2C-9481-CB81-27A149F33825}.Debug.Build.0 = Debug|Win32 - {31C77B84-0B2C-9481-CB81-27A149F33825}.Release.ActiveCfg = Release|Win32 - {31C77B84-0B2C-9481-CB81-27A149F33825}.Release.Build.0 = Release|Win32 - {97B69A72-B9D3-7389-17FB-74612F4A9543}.Debug.ActiveCfg = Debug|Win32 - {97B69A72-B9D3-7389-17FB-74612F4A9543}.Debug.Build.0 = Debug|Win32 - {97B69A72-B9D3-7389-17FB-74612F4A9543}.Release.ActiveCfg = Release|Win32 - {97B69A72-B9D3-7389-17FB-74612F4A9543}.Release.Build.0 = Release|Win32 - {01E70176-B6C5-BF47-2C91-A949077BA323}.Debug.ActiveCfg = Debug|Win32 - {01E70176-B6C5-BF47-2C91-A949077BA323}.Debug.Build.0 = Debug|Win32 - {01E70176-B6C5-BF47-2C91-A949077BA323}.Release.ActiveCfg = Release|Win32 - {01E70176-B6C5-BF47-2C91-A949077BA323}.Release.Build.0 = Release|Win32 - {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Debug.ActiveCfg = Debug|Win32 - {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Debug.Build.0 = Debug|Win32 - {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Release.ActiveCfg = Release|Win32 - {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Release.Build.0 = Release|Win32 - {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Debug.ActiveCfg = Debug|Win32 - {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Debug.Build.0 = Debug|Win32 - {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Release.ActiveCfg = Release|Win32 - {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Release.Build.0 = Release|Win32 - {16909EE7-24AF-97C1-C76B-204B971BA959}.Debug.ActiveCfg = Debug|Win32 - {16909EE7-24AF-97C1-C76B-204B971BA959}.Debug.Build.0 = Debug|Win32 - {16909EE7-24AF-97C1-C76B-204B971BA959}.Release.ActiveCfg = Release|Win32 - {16909EE7-24AF-97C1-C76B-204B971BA959}.Release.Build.0 = Release|Win32 - {07022E76-6CB5-92C1-B47F-A10772A79B43}.Debug.ActiveCfg = Debug|Win32 - {07022E76-6CB5-92C1-B47F-A10772A79B43}.Debug.Build.0 = Debug|Win32 - {07022E76-6CB5-92C1-B47F-A10772A79B43}.Release.ActiveCfg = Release|Win32 - {07022E76-6CB5-92C1-B47F-A10772A79B43}.Release.Build.0 = Release|Win32 - {1690A9E7-DB57-971C-F24A-09B752A942F7}.Debug.ActiveCfg = Debug|Win32 - {1690A9E7-DB57-971C-F24A-09B752A942F7}.Debug.Build.0 = Debug|Win32 - {1690A9E7-DB57-971C-F24A-09B752A942F7}.Release.ActiveCfg = Release|Win32 - {1690A9E7-DB57-971C-F24A-09B752A942F7}.Release.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal +<<<<<<< .working +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "list", "list\list.vcproj", "{977B61B4-9968-497C-9F0B-24A8145473B8}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slist", "slist\slist.vcproj", "{5A02061D-3728-4C49-AFC8-0130C1F161C0}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multiset", "multiset\multiset.vcproj", "{961F0E06-C092-4AF7-ABC5-2A49999F3B79}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_intrusivelib", "_intrusivelib\_intrusivelib.vcproj", "{90F3C5BD-8E6C-4629-BC71-A1009EC88059}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "set", "set\set.vcproj", "{960E01F6-92C1-F74A-BCA5-2A9F3B994979}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unordered_set", "unordered_set\unordered_set.vcproj", "{90E701E6-2C91-F4A7-BA6C-A9F3B0949279}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unordered_multiset", "unordered_multiset\unordered_multiset.vcproj", "{9101EE76-BB6C-2C91-F4B7-A9F3B9490279}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perf_test", "perf_test\perf_test.vcproj", "{910E70E6-2C91-AA67-BF4C-A9C74A309927}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "default_hook", "default_hook\default_hook.vcproj", "{761A79B4-9968-CB81-F02B-2A4497345475}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stateful_value_traits", "stateful_value_traits\stateful_value_traits.vcproj", "{9571A7B4-9968-B9C1-17FB-134547B46975}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "virtual_base", "virtual_base\virtual_base.vcproj", "{3579B1A4-9894-02AB-CB81-297B46154345}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_functions", "make_functions\make_functions.vcproj", "{7679B41B-F2B4-9176-CB81-35449467B435}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "custom_bucket_traits", "custom_bucket_traits\custom_bucket_traits.vcproj", "{31C77B84-0B2C-9481-CB81-27A149F33825}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "external_value_traits", "external_value_traits\external_value_traits.vcproj", "{97B69A72-B9D3-7389-17FB-74612F4A9543}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "splay_multiset", "splay_multiset\splay_multiset.vcproj", "{01E70176-B6C5-BF47-2C91-A949077BA323}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "splay_set", "splay_set\splay_set.vcproj", "{1E6909E7-C971-F24A-6C7B-A92094B71B59}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "avl_multiset", "avl_multiset\avl_multiset.vcproj", "{0AE70176-5B8C-4BC7-392C-A4A312B07893}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "avl_set", "avl_set\avl_set.vcproj", "{16909EE7-24AF-97C1-C76B-204B971BA959}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sg_multiset", "sg_multiset\sg_multiset.vcproj", "{07022E76-6CB5-92C1-B47F-A10772A79B43}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sg_set", "sg_set\sg_set.vcproj", "{1690A9E7-DB57-971C-F24A-09B752A942F7}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {977B61B4-9968-497C-9F0B-24A8145473B8}.Debug.ActiveCfg = Debug|Win32 + {977B61B4-9968-497C-9F0B-24A8145473B8}.Debug.Build.0 = Debug|Win32 + {977B61B4-9968-497C-9F0B-24A8145473B8}.Release.ActiveCfg = Release|Win32 + {977B61B4-9968-497C-9F0B-24A8145473B8}.Release.Build.0 = Release|Win32 + {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Debug.ActiveCfg = Debug|Win32 + {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Debug.Build.0 = Debug|Win32 + {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Release.ActiveCfg = Release|Win32 + {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Release.Build.0 = Release|Win32 + {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Debug.ActiveCfg = Debug|Win32 + {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Debug.Build.0 = Debug|Win32 + {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Release.ActiveCfg = Release|Win32 + {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Release.Build.0 = Release|Win32 + {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Debug.ActiveCfg = Debug|Win32 + {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Debug.Build.0 = Debug|Win32 + {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Release.ActiveCfg = Release|Win32 + {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Release.Build.0 = Release|Win32 + {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Debug.ActiveCfg = Debug|Win32 + {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Debug.Build.0 = Debug|Win32 + {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Release.ActiveCfg = Release|Win32 + {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Release.Build.0 = Release|Win32 + {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Debug.ActiveCfg = Debug|Win32 + {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Debug.Build.0 = Debug|Win32 + {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Release.ActiveCfg = Release|Win32 + {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Release.Build.0 = Release|Win32 + {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Debug.ActiveCfg = Debug|Win32 + {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Debug.Build.0 = Debug|Win32 + {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Release.ActiveCfg = Release|Win32 + {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Release.Build.0 = Release|Win32 + {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Debug.ActiveCfg = Debug|Win32 + {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Debug.Build.0 = Debug|Win32 + {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Release.ActiveCfg = Release|Win32 + {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Release.Build.0 = Release|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Debug.ActiveCfg = Debug|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Debug.Build.0 = Debug|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Release.ActiveCfg = Release|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Release.Build.0 = Release|Win32 + {9571A7B4-9968-B9C1-17FB-134547B46975}.Debug.ActiveCfg = Debug|Win32 + {9571A7B4-9968-B9C1-17FB-134547B46975}.Debug.Build.0 = Debug|Win32 + {9571A7B4-9968-B9C1-17FB-134547B46975}.Release.ActiveCfg = Release|Win32 + {9571A7B4-9968-B9C1-17FB-134547B46975}.Release.Build.0 = Release|Win32 + {3579B1A4-9894-02AB-CB81-297B46154345}.Debug.ActiveCfg = Debug|Win32 + {3579B1A4-9894-02AB-CB81-297B46154345}.Debug.Build.0 = Debug|Win32 + {3579B1A4-9894-02AB-CB81-297B46154345}.Release.ActiveCfg = Release|Win32 + {3579B1A4-9894-02AB-CB81-297B46154345}.Release.Build.0 = Release|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Debug.ActiveCfg = Debug|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Debug.Build.0 = Debug|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Release.ActiveCfg = Release|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Release.Build.0 = Release|Win32 + {31C77B84-0B2C-9481-CB81-27A149F33825}.Debug.ActiveCfg = Debug|Win32 + {31C77B84-0B2C-9481-CB81-27A149F33825}.Debug.Build.0 = Debug|Win32 + {31C77B84-0B2C-9481-CB81-27A149F33825}.Release.ActiveCfg = Release|Win32 + {31C77B84-0B2C-9481-CB81-27A149F33825}.Release.Build.0 = Release|Win32 + {97B69A72-B9D3-7389-17FB-74612F4A9543}.Debug.ActiveCfg = Debug|Win32 + {97B69A72-B9D3-7389-17FB-74612F4A9543}.Debug.Build.0 = Debug|Win32 + {97B69A72-B9D3-7389-17FB-74612F4A9543}.Release.ActiveCfg = Release|Win32 + {97B69A72-B9D3-7389-17FB-74612F4A9543}.Release.Build.0 = Release|Win32 + {01E70176-B6C5-BF47-2C91-A949077BA323}.Debug.ActiveCfg = Debug|Win32 + {01E70176-B6C5-BF47-2C91-A949077BA323}.Debug.Build.0 = Debug|Win32 + {01E70176-B6C5-BF47-2C91-A949077BA323}.Release.ActiveCfg = Release|Win32 + {01E70176-B6C5-BF47-2C91-A949077BA323}.Release.Build.0 = Release|Win32 + {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Debug.ActiveCfg = Debug|Win32 + {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Debug.Build.0 = Debug|Win32 + {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Release.ActiveCfg = Release|Win32 + {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Release.Build.0 = Release|Win32 + {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Debug.ActiveCfg = Debug|Win32 + {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Debug.Build.0 = Debug|Win32 + {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Release.ActiveCfg = Release|Win32 + {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Release.Build.0 = Release|Win32 + {16909EE7-24AF-97C1-C76B-204B971BA959}.Debug.ActiveCfg = Debug|Win32 + {16909EE7-24AF-97C1-C76B-204B971BA959}.Debug.Build.0 = Debug|Win32 + {16909EE7-24AF-97C1-C76B-204B971BA959}.Release.ActiveCfg = Release|Win32 + {16909EE7-24AF-97C1-C76B-204B971BA959}.Release.Build.0 = Release|Win32 + {07022E76-6CB5-92C1-B47F-A10772A79B43}.Debug.ActiveCfg = Debug|Win32 + {07022E76-6CB5-92C1-B47F-A10772A79B43}.Debug.Build.0 = Debug|Win32 + {07022E76-6CB5-92C1-B47F-A10772A79B43}.Release.ActiveCfg = Release|Win32 + {07022E76-6CB5-92C1-B47F-A10772A79B43}.Release.Build.0 = Release|Win32 + {1690A9E7-DB57-971C-F24A-09B752A942F7}.Debug.ActiveCfg = Debug|Win32 + {1690A9E7-DB57-971C-F24A-09B752A942F7}.Debug.Build.0 = Debug|Win32 + {1690A9E7-DB57-971C-F24A-09B752A942F7}.Release.ActiveCfg = Release|Win32 + {1690A9E7-DB57-971C-F24A-09B752A942F7}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal +======= +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "list", "list\list.vcproj", "{977B61B4-9968-497C-9F0B-24A8145473B8}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slist", "slist\slist.vcproj", "{5A02061D-3728-4C49-AFC8-0130C1F161C0}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multiset", "multiset\multiset.vcproj", "{961F0E06-C092-4AF7-ABC5-2A49999F3B79}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_intrusivelib", "_intrusivelib\_intrusivelib.vcproj", "{90F3C5BD-8E6C-4629-BC71-A1009EC88059}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "set", "set\set.vcproj", "{960E01F6-92C1-F74A-BCA5-2A9F3B994979}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unordered_set", "unordered_set\unordered_set.vcproj", "{90E701E6-2C91-F4A7-BA6C-A9F3B0949279}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unordered_multiset", "unordered_multiset\unordered_multiset.vcproj", "{9101EE76-BB6C-2C91-F4B7-A9F3B9490279}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perf_test", "perf_test\perf_test.vcproj", "{910E70E6-2C91-AA67-BF4C-A9C74A309927}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "default_hook", "default_hook\default_hook.vcproj", "{761A79B4-9968-CB81-F02B-2A4497345475}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stateful_value_traits", "stateful_value_traits\stateful_value_traits.vcproj", "{9571A7B4-9968-B9C1-17FB-134547B46975}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "virtual_base", "virtual_base\virtual_base.vcproj", "{3579B1A4-9894-02AB-CB81-297B46154345}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_functions", "make_functions\make_functions.vcproj", "{7679B41B-F2B4-9176-CB81-35449467B435}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "custom_bucket_traits", "custom_bucket_traits\custom_bucket_traits.vcproj", "{31C77B84-0B2C-9481-CB81-27A149F33825}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "external_value_traits", "external_value_traits\external_value_traits.vcproj", "{97B69A72-B9D3-7389-17FB-74612F4A9543}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "splay_multiset", "splay_multiset\splay_multiset.vcproj", "{01E70176-B6C5-BF47-2C91-A949077BA323}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "splay_set", "splay_set\splay_set.vcproj", "{1E6909E7-C971-F24A-6C7B-A92094B71B59}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "avl_multiset", "avl_multiset\avl_multiset.vcproj", "{0AE70176-5B8C-4BC7-392C-A4A312B07893}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "avl_set", "avl_set\avl_set.vcproj", "{16909EE7-24AF-97C1-C76B-204B971BA959}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sg_multiset", "sg_multiset\sg_multiset.vcproj", "{07022E76-6CB5-92C1-B47F-A10772A79B43}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sg_set", "sg_set\sg_set.vcproj", "{1690A9E7-DB57-971C-F24A-09B752A942F7}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "any_hook", "any_test\any_test.vcproj", "{97B61B24-4C97-9681-50BF-243175A813B6}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {977B61B4-9968-497C-9F0B-24A8145473B8}.Debug.ActiveCfg = Debug|Win32 + {977B61B4-9968-497C-9F0B-24A8145473B8}.Debug.Build.0 = Debug|Win32 + {977B61B4-9968-497C-9F0B-24A8145473B8}.Release.ActiveCfg = Release|Win32 + {977B61B4-9968-497C-9F0B-24A8145473B8}.Release.Build.0 = Release|Win32 + {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Debug.ActiveCfg = Debug|Win32 + {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Debug.Build.0 = Debug|Win32 + {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Release.ActiveCfg = Release|Win32 + {5A02061D-3728-4C49-AFC8-0130C1F161C0}.Release.Build.0 = Release|Win32 + {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Debug.ActiveCfg = Debug|Win32 + {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Debug.Build.0 = Debug|Win32 + {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Release.ActiveCfg = Release|Win32 + {961F0E06-C092-4AF7-ABC5-2A49999F3B79}.Release.Build.0 = Release|Win32 + {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Debug.ActiveCfg = Debug|Win32 + {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Debug.Build.0 = Debug|Win32 + {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Release.ActiveCfg = Release|Win32 + {90F3C5BD-8E6C-4629-BC71-A1009EC88059}.Release.Build.0 = Release|Win32 + {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Debug.ActiveCfg = Debug|Win32 + {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Debug.Build.0 = Debug|Win32 + {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Release.ActiveCfg = Release|Win32 + {960E01F6-92C1-F74A-BCA5-2A9F3B994979}.Release.Build.0 = Release|Win32 + {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Debug.ActiveCfg = Debug|Win32 + {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Debug.Build.0 = Debug|Win32 + {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Release.ActiveCfg = Release|Win32 + {90E701E6-2C91-F4A7-BA6C-A9F3B0949279}.Release.Build.0 = Release|Win32 + {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Debug.ActiveCfg = Debug|Win32 + {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Debug.Build.0 = Debug|Win32 + {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Release.ActiveCfg = Release|Win32 + {9101EE76-BB6C-2C91-F4B7-A9F3B9490279}.Release.Build.0 = Release|Win32 + {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Debug.ActiveCfg = Debug|Win32 + {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Debug.Build.0 = Debug|Win32 + {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Release.ActiveCfg = Release|Win32 + {910E70E6-2C91-AA67-BF4C-A9C74A309927}.Release.Build.0 = Release|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Debug.ActiveCfg = Debug|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Debug.Build.0 = Debug|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Release.ActiveCfg = Release|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Release.Build.0 = Release|Win32 + {9571A7B4-9968-B9C1-17FB-134547B46975}.Debug.ActiveCfg = Debug|Win32 + {9571A7B4-9968-B9C1-17FB-134547B46975}.Debug.Build.0 = Debug|Win32 + {9571A7B4-9968-B9C1-17FB-134547B46975}.Release.ActiveCfg = Release|Win32 + {9571A7B4-9968-B9C1-17FB-134547B46975}.Release.Build.0 = Release|Win32 + {3579B1A4-9894-02AB-CB81-297B46154345}.Debug.ActiveCfg = Debug|Win32 + {3579B1A4-9894-02AB-CB81-297B46154345}.Debug.Build.0 = Debug|Win32 + {3579B1A4-9894-02AB-CB81-297B46154345}.Release.ActiveCfg = Release|Win32 + {3579B1A4-9894-02AB-CB81-297B46154345}.Release.Build.0 = Release|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Debug.ActiveCfg = Debug|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Debug.Build.0 = Debug|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Release.ActiveCfg = Release|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Release.Build.0 = Release|Win32 + {31C77B84-0B2C-9481-CB81-27A149F33825}.Debug.ActiveCfg = Debug|Win32 + {31C77B84-0B2C-9481-CB81-27A149F33825}.Debug.Build.0 = Debug|Win32 + {31C77B84-0B2C-9481-CB81-27A149F33825}.Release.ActiveCfg = Release|Win32 + {31C77B84-0B2C-9481-CB81-27A149F33825}.Release.Build.0 = Release|Win32 + {97B69A72-B9D3-7389-17FB-74612F4A9543}.Debug.ActiveCfg = Debug|Win32 + {97B69A72-B9D3-7389-17FB-74612F4A9543}.Debug.Build.0 = Debug|Win32 + {97B69A72-B9D3-7389-17FB-74612F4A9543}.Release.ActiveCfg = Release|Win32 + {97B69A72-B9D3-7389-17FB-74612F4A9543}.Release.Build.0 = Release|Win32 + {01E70176-B6C5-BF47-2C91-A949077BA323}.Debug.ActiveCfg = Debug|Win32 + {01E70176-B6C5-BF47-2C91-A949077BA323}.Debug.Build.0 = Debug|Win32 + {01E70176-B6C5-BF47-2C91-A949077BA323}.Release.ActiveCfg = Release|Win32 + {01E70176-B6C5-BF47-2C91-A949077BA323}.Release.Build.0 = Release|Win32 + {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Debug.ActiveCfg = Debug|Win32 + {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Debug.Build.0 = Debug|Win32 + {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Release.ActiveCfg = Release|Win32 + {1E6909E7-C971-F24A-6C7B-A92094B71B59}.Release.Build.0 = Release|Win32 + {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Debug.ActiveCfg = Debug|Win32 + {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Debug.Build.0 = Debug|Win32 + {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Release.ActiveCfg = Release|Win32 + {0AE70176-5B8C-4BC7-392C-A4A312B07893}.Release.Build.0 = Release|Win32 + {16909EE7-24AF-97C1-C76B-204B971BA959}.Debug.ActiveCfg = Debug|Win32 + {16909EE7-24AF-97C1-C76B-204B971BA959}.Debug.Build.0 = Debug|Win32 + {16909EE7-24AF-97C1-C76B-204B971BA959}.Release.ActiveCfg = Release|Win32 + {16909EE7-24AF-97C1-C76B-204B971BA959}.Release.Build.0 = Release|Win32 + {07022E76-6CB5-92C1-B47F-A10772A79B43}.Debug.ActiveCfg = Debug|Win32 + {07022E76-6CB5-92C1-B47F-A10772A79B43}.Debug.Build.0 = Debug|Win32 + {07022E76-6CB5-92C1-B47F-A10772A79B43}.Release.ActiveCfg = Release|Win32 + {07022E76-6CB5-92C1-B47F-A10772A79B43}.Release.Build.0 = Release|Win32 + {1690A9E7-DB57-971C-F24A-09B752A942F7}.Debug.ActiveCfg = Debug|Win32 + {1690A9E7-DB57-971C-F24A-09B752A942F7}.Debug.Build.0 = Debug|Win32 + {1690A9E7-DB57-971C-F24A-09B752A942F7}.Release.ActiveCfg = Release|Win32 + {1690A9E7-DB57-971C-F24A-09B752A942F7}.Release.Build.0 = Release|Win32 + {97B61B24-4C97-9681-50BF-243175A813B6}.Debug.ActiveCfg = Debug|Win32 + {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 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal +>>>>>>> .merge-right.r46629 diff --git a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj index 587661c..b42d957 100644 --- a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj +++ b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj @@ -105,6 +105,9 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + + @@ -154,10 +157,7 @@ RelativePath="..\..\..\..\..\boost\intrusive\options.hpp"> - - + RelativePath="..\..\..\..\..\boost\intrusive\pointer_plus_bits.hpp"> @@ -210,6 +210,9 @@ + + @@ -240,9 +243,6 @@ - - @@ -322,6 +322,9 @@ + + diff --git a/proj/vc7ide/any_test/any_test.vcproj b/proj/vc7ide/any_test/any_test.vcproj new file mode 100644 index 0000000..b053349 --- /dev/null +++ b/proj/vc7ide/any_test/any_test.vcproj @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/proj/vc7ide/list/list.vcproj b/proj/vc7ide/list/list.vcproj index 17c3b6a..e5e510b 100644 --- a/proj/vc7ide/list/list.vcproj +++ b/proj/vc7ide/list/list.vcproj @@ -127,16 +127,6 @@ RelativePath="..\..\..\test\list_test.cpp"> - - - - diff --git a/proj/vc7ide/multiset/multiset.vcproj b/proj/vc7ide/multiset/multiset.vcproj index 4303b0c..8828607 100644 --- a/proj/vc7ide/multiset/multiset.vcproj +++ b/proj/vc7ide/multiset/multiset.vcproj @@ -121,16 +121,6 @@ RelativePath="..\..\..\test\multiset_test.cpp"> - - - - diff --git a/proj/vc7ide/perf_test/perf_test.vcproj b/proj/vc7ide/perf_test/perf_test.vcproj index e94844d..5e410b1 100644 --- a/proj/vc7ide/perf_test/perf_test.vcproj +++ b/proj/vc7ide/perf_test/perf_test.vcproj @@ -122,16 +122,6 @@ RelativePath="..\..\..\perf\perf_list.cpp"> - - - - diff --git a/proj/vc7ide/set/set.vcproj b/proj/vc7ide/set/set.vcproj index 6e96cd2..85dff59 100644 --- a/proj/vc7ide/set/set.vcproj +++ b/proj/vc7ide/set/set.vcproj @@ -121,16 +121,6 @@ RelativePath="..\..\..\test\set_test.cpp"> - - - - diff --git a/proj/vc7ide/slist/slist.vcproj b/proj/vc7ide/slist/slist.vcproj index d9138b2..3d118f5 100644 --- a/proj/vc7ide/slist/slist.vcproj +++ b/proj/vc7ide/slist/slist.vcproj @@ -121,16 +121,6 @@ RelativePath="..\..\..\test\slist_test.cpp"> - - - - diff --git a/proj/vc7ide/to-do.txt b/proj/vc7ide/to-do.txt new file mode 100644 index 0000000..747f679 --- /dev/null +++ b/proj/vc7ide/to-do.txt @@ -0,0 +1,37 @@ +Implement incremental hashing: + +bucket_len is power of two +cur_idx is always at least, half of bucket_len + +find bucket from value: + size_type bucket_num = hash(val) &(bucket_len - 1); + if (bucket_num >= cur_idx) + bucket_num -= bucket_len/2; + +incremental_rehash: + + iterator _Plist, _Where; + if (load_factor > LoadFactorLimit) + { // too dense, need to grow hash table + if (cur_idx >= (bucket_len - 1)) + { // table full, request doubling + return false; + } + else if (cur_idx >= bucket_len) + bucket_len*=2; + + size_type bucket_num = cur_idx - bucket_len/2; + // rehash elements from bucket_num + ++cur_idx; + } + +insert from value: + + size_type bucket_num = hash(val) & (bucket_len - 1); + if (bucket_num >= cur_idx) + bucket_num -= bucket_len/2; + insert in bucket + +rehash: + + diff --git a/proj/vc7ide/unordered_multiset/unordered_multiset.vcproj b/proj/vc7ide/unordered_multiset/unordered_multiset.vcproj index 2b9c6f3..2559e0c 100644 --- a/proj/vc7ide/unordered_multiset/unordered_multiset.vcproj +++ b/proj/vc7ide/unordered_multiset/unordered_multiset.vcproj @@ -122,16 +122,6 @@ RelativePath="..\..\..\test\unordered_multiset_test.cpp"> - - - - diff --git a/proj/vc7ide/unordered_set/unordered_set.vcproj b/proj/vc7ide/unordered_set/unordered_set.vcproj index 33c95ac..b7e9681 100644 --- a/proj/vc7ide/unordered_set/unordered_set.vcproj +++ b/proj/vc7ide/unordered_set/unordered_set.vcproj @@ -121,16 +121,6 @@ RelativePath="..\..\..\test\unordered_set_test.cpp"> - - - - diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 58db1e5..d56b50a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1,5 +1,5 @@ # Boost Intrusive Library Test Jamfile -# (C) Copyright Ion Gaztañaga 2006. +# (C) Copyright Ion Gaztanaga 2006. # Use, modification and distribution are subject to 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) diff --git a/test/any_test.cpp b/test/any_test.cpp new file mode 100644 index 0000000..9c24c56 --- /dev/null +++ b/test/any_test.cpp @@ -0,0 +1,178 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Olaf Krzikalla 2004-2006. +// (C) Copyright Ion Gaztanaga 2006-2007. +// +// 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 +#include +#include +#include +#include +#include +#include +#include +#include //std::vector +#include //std::size_t + +using namespace boost::intrusive; + +class MyClass : public any_base_hook<> +{ + int int_; + + public: + //This is a member hook + any_member_hook<> member_hook_; + + MyClass(int i = 0) + : int_(i) + {} + + int get() const + { return this->int_; } + + friend bool operator < (const MyClass &l, const MyClass &r) + { return l.int_ < r.int_; } + + friend bool operator == (const MyClass &l, const MyClass &r) + { return l.int_ == r.int_; } + + friend std::size_t hash_value(const MyClass &o) + { return boost::hash()(o.get()); } +}; + +void instantiation_test() +{ + typedef member_hook< MyClass, any_member_hook<>, &MyClass::member_hook_> MemberHook; + typedef base_hook< any_base_hook<> > BaseHook; + + MyClass myclass; + { + slist < MyClass, any_to_slist_hook< BaseHook > > slist_base; + slist_base.push_front(myclass); + } + { + slist < MyClass, any_to_slist_hook< MemberHook > > slist_member; + slist_member.push_front(myclass); + } + { + list < MyClass, any_to_list_hook< BaseHook > > list_base; + list_base.push_front(myclass); + } + { + list < MyClass, any_to_list_hook< MemberHook > > list_member; + list_member.push_front(myclass); + } + { + rbtree < MyClass, any_to_set_hook< BaseHook > > rbtree_base; + rbtree_base.insert_unique(myclass); + } + { + rbtree < MyClass, any_to_set_hook< MemberHook > > rbtree_member; + rbtree_member.insert_unique(myclass); + } + { + avltree < MyClass, any_to_avl_set_hook< BaseHook > > avltree_base; + avltree_base.insert_unique(myclass); + } + { + avltree < MyClass, any_to_avl_set_hook< MemberHook > > avltree_member; + avltree_member.insert_unique(myclass); + } + { + sgtree < MyClass, any_to_bs_set_hook< BaseHook > > sgtree_base; + sgtree_base.insert_unique(myclass); + } + { + sgtree < MyClass, any_to_bs_set_hook< MemberHook > > sgtree_member; + sgtree_member.insert_unique(myclass); + } + { + splaytree < MyClass, any_to_bs_set_hook< BaseHook > > splaytree_base; + splaytree_base.insert_unique(myclass); + } + { + splaytree < MyClass, any_to_bs_set_hook< MemberHook > > splaytree_member; + splaytree_member.insert_unique(myclass); + } + typedef unordered_bucket >::type bucket_type; + typedef unordered_default_bucket_traits >::type bucket_traits; + bucket_type buckets[2]; + { + hashtable < MyClass, any_to_unordered_set_hook< BaseHook > > + hashtable_base(bucket_traits(&buckets[0], 1)); + hashtable_base.insert_unique(myclass); + } + { + hashtable < MyClass, any_to_unordered_set_hook< MemberHook > > + hashtable_member(bucket_traits(&buckets[1], 1)); + hashtable_member.insert_unique(myclass); + } +} + +bool simple_slist_test() +{ + //Define an slist that will store MyClass using the public base hook + typedef any_to_slist_hook< base_hook< any_base_hook<> > >BaseOption; + typedef slist > BaseList; + + //Define an slist that will store MyClass using the public member hook + typedef any_to_slist_hook< member_hook, &MyClass::member_hook_> > MemberOption; + typedef slist MemberList; + + typedef std::vector::iterator VectIt; + typedef std::vector::reverse_iterator VectRit; + + //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)); + + BaseList baselist; + MemberList memberlist; + + //Now insert them in the reverse order in the base hook list + for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it) + baselist.push_front(*it); + + //Now insert them in the same order as in vector in the member hook list + for(BaseList::iterator it(baselist.begin()), itend(baselist.end()) + ; it != itend; ++it){ + memberlist.push_front(*it); + } + + //Now test lists + { + BaseList::iterator bit(baselist.begin()), bitend(baselist.end()); + MemberList::iterator mit(memberlist.begin()), mitend(memberlist.end()); + VectRit rit(values.rbegin()), ritend(values.rend()); + VectIt it(values.begin()), itend(values.end()); + + //Test the objects inserted in the base hook list + for(; rit != ritend; ++rit, ++bit) + if(&*bit != &*rit) return false; + + //Test the objects inserted in the member hook list + for(; it != itend; ++it, ++mit) + if(&*mit != &*it) return false; + } + return true; +} + +int main() +{ + if(!simple_slist_test()) + return 1; + instantiation_test(); + return 0; +} + +#include diff --git a/test/avl_set_test.cpp b/test/avl_set_test.cpp index 1f7150e..d53b56e 100644 --- a/test/avl_set_test.cpp +++ b/test/avl_set_test.cpp @@ -108,7 +108,6 @@ class test_main_template int main( int, char* [] ) { - test_main_template()(); test_main_template, false>()(); test_main_template()(); diff --git a/test/common_functors.hpp b/test/common_functors.hpp index 7a6d500..d3bc3fa 100644 --- a/test/common_functors.hpp +++ b/test/common_functors.hpp @@ -41,6 +41,14 @@ class new_cloner { return new T(t); } }; +template +class new_default_factory +{ + public: + T *operator()() + { return new T(); } +}; + } //namespace test { } //namespace intrusive { } //namespace boost { diff --git a/test/generic_assoc_test.hpp b/test/generic_assoc_test.hpp index 624fd60..5ee4720 100644 --- a/test/generic_assoc_test.hpp +++ b/test/generic_assoc_test.hpp @@ -52,8 +52,37 @@ struct test_generic_assoc static void test_rebalance(std::vector& values); static void test_rebalance(std::vector& values, boost::intrusive::detail::true_type); static void test_rebalance(std::vector& values, boost::intrusive::detail::false_type); + static void test_container_from_iterator(std::vector& values); }; +template class ContainerDefiner> +void test_generic_assoc:: + test_container_from_iterator(std::vector& values) +{ + typedef typename ContainerDefiner + < value_type + , value_traits + , constant_time_size + >::type assoc_type; + + assoc_type testset(values.begin(), values.end()); + typedef typename assoc_type::iterator it_type; + typedef typename assoc_type::const_iterator cit_type; + typedef typename assoc_type::size_type sz_type; + sz_type sz = testset.size(); + for(it_type b(testset.begin()), e(testset.end()); b != e; ++b) + { + assoc_type &s = assoc_type::container_from_iterator(b); + const assoc_type &cs = assoc_type::container_from_iterator(cit_type(b)); + BOOST_TEST(&s == &cs); + BOOST_TEST(&s == &testset); + s.erase(b); + BOOST_TEST(testset.size() == (sz-1)); + s.insert(*b); + BOOST_TEST(testset.size() == sz); + } +} + template class ContainerDefiner> void test_generic_assoc::test_insert_erase_burst() { @@ -103,12 +132,14 @@ void test_generic_assoc::test_insert_erase_burst( template class ContainerDefiner> void test_generic_assoc::test_all(std::vector& values) { + typedef typename ValueTraits::value_type value_type; test_clone(values); test_container_from_end(values); test_splay_up(values); test_splay_down(values); test_rebalance(values); test_insert_erase_burst(); + test_container_from_iterator(values); } template class ContainerDefiner> diff --git a/test/generic_set_test.hpp b/test/generic_set_test.hpp index db14008..0498759 100644 --- a/test/generic_set_test.hpp +++ b/test/generic_set_test.hpp @@ -35,6 +35,7 @@ struct test_generic_set static void test_impl(); }; + template class ContainerDefiner> void test_generic_set::test_all() { diff --git a/test/itestvalue.hpp b/test/itestvalue.hpp index d6338bb..b45bdd8 100644 --- a/test/itestvalue.hpp +++ b/test/itestvalue.hpp @@ -126,20 +126,30 @@ template struct uset_auto_base_hook_type { typedef unordered_set_base_hook - < link_mode, void_pointer - , tag, store_hash > type; + < link_mode + , void_pointer + , tag + , store_hash + > type; }; template struct uset_member_hook_type -{ typedef unordered_set_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 > type; + , store_hash + , optimize_multikey + > type; }; template @@ -318,6 +328,49 @@ struct testvalue slist_auto_node_.swap_nodes(other.slist_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(); + } + ~testvalue() {} diff --git a/test/list_test.cpp b/test/list_test.cpp index 3a000a9..37998be 100644 --- a/test/list_test.cpp +++ b/test/list_test.cpp @@ -229,6 +229,7 @@ void test_list TEST_INTRUSIVE_SEQUENCE( init_values, const_testlist.begin() ); } } + template void test_list ::test_shift(std::vector& values) diff --git a/test/slist_test.cpp b/test/slist_test.cpp index c8055c1..7ca0afc 100644 --- a/test/slist_test.cpp +++ b/test/slist_test.cpp @@ -315,7 +315,7 @@ void test_slist testlist.erase (++testlist.begin(), testlist.end()); BOOST_TEST (testlist.size() == 1); BOOST_TEST (testlist.front().value_ == 3); -} +} template void test_slist diff --git a/test/smart_ptr.hpp b/test/smart_ptr.hpp index 6ed0d07..dd945a8 100644 --- a/test/smart_ptr.hpp +++ b/test/smart_ptr.hpp @@ -12,8 +12,7 @@ #define BOOST_INTRUSIVE_SMART_PTR_HPP #include -#include -#include +#include #if (defined _MSC_VER) && (_MSC_VER >= 1200) # pragma once @@ -109,7 +108,7 @@ class smart_ptr public: //Public Functions //!Constructor from raw pointer (allows "0" pointer conversion). Never throws. - smart_ptr(pointer ptr = 0) + explicit smart_ptr(pointer ptr = 0) : m_ptr(ptr) {} @@ -351,67 +350,34 @@ namespace boost{ //for intrusive containers, saving space namespace intrusive { -template -struct has_pointer_plus_bit, N> +template +struct max_pointer_plus_bits, Alignment> { - static const bool value = has_pointer_plus_bit::value; + static const std::size_t value = max_pointer_plus_bits::value; }; -//Specialization -template -struct pointer_plus_bit > +template +struct pointer_plus_bits, NumBits> { typedef smart_ptr pointer; static pointer get_pointer(const pointer &n) - { return pointer_plus_bit::get_pointer(n.get()); } + { return pointer_plus_bits::get_pointer(n.get()); } static void set_pointer(pointer &n, pointer p) { T *raw_n = n.get(); - pointer_plus_bit::set_pointer(raw_n, p.get()); - n = raw_n; - } - - static bool get_bit(const pointer &n) - { return pointer_plus_bit::get_bit(n.get()); } - - static void set_bit(pointer &n, bool c) - { - T *raw_n = n.get(); - pointer_plus_bit::set_bit(raw_n, c); - n = raw_n; - } -}; - -template -struct has_pointer_plus_2_bits, N> -{ - static const bool value = has_pointer_plus_2_bits::value; -}; - -template -struct pointer_plus_2_bits > -{ - typedef smart_ptr pointer; - - static pointer get_pointer(const pointer &n) - { return pointer_plus_2_bits::get_pointer(n.get()); } - - static void set_pointer(pointer &n, pointer p) - { - T *raw_n = n.get(); - pointer_plus_2_bits::set_pointer(raw_n, p.get()); + pointer_plus_bits::set_pointer(raw_n, p.get()); n = raw_n; } static std::size_t get_bits(const pointer &n) - { return pointer_plus_2_bits::get_bits(n.get()); } + { return pointer_plus_bits::get_bits(n.get()); } static void set_bits(pointer &n, std::size_t c) { T *raw_n = n.get(); - pointer_plus_2_bits::set_bits(raw_n, c); + pointer_plus_bits::set_bits(raw_n, c); n = raw_n; } }; diff --git a/test/unordered_multiset_test.cpp b/test/unordered_multiset_test.cpp index ceb30ba..e10efd2 100644 --- a/test/unordered_multiset_test.cpp +++ b/test/unordered_multiset_test.cpp @@ -10,7 +10,6 @@ // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// - #include #include #include @@ -18,6 +17,7 @@ #include "smart_ptr.hpp" #include "common_functors.hpp" #include +#include //std::sort std::find #include #include #include "test_macros.hpp" @@ -27,7 +27,7 @@ using namespace boost::intrusive; static const std::size_t BucketSize = 11; -template +template struct test_unordered_multiset { typedef typename ValueTraits::value_type value_type; @@ -41,14 +41,16 @@ struct test_unordered_multiset static void test_clone(std::vector& values); }; -template -void test_unordered_multiset::test_all (std::vector& values) +template +void test_unordered_multiset::test_all (std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_multiset - , constant_time_size + , cache_begin + , compare_hash > unordered_multiset_type; { typedef typename unordered_multiset_type::bucket_traits bucket_traits; @@ -76,14 +78,16 @@ void test_unordered_multiset::test_all (std::vector -void test_unordered_multiset::test_impl() +template +void test_unordered_multiset::test_impl() { typedef typename ValueTraits::value_type value_type; typedef unordered_multiset , constant_time_size + , cache_begin + , compare_hash > unordered_multiset_type; typedef typename unordered_multiset_type::bucket_traits bucket_traits; @@ -106,14 +110,16 @@ void test_unordered_multiset::test_impl() } //test: constructor, iterator, clear, reverse_iterator, front, back, size: -template -void test_unordered_multiset::test_sort(std::vector& values) +template +void test_unordered_multiset::test_sort(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_multiset , constant_time_size + , cache_begin + , compare_hash > unordered_multiset_type; typedef typename unordered_multiset_type::bucket_traits bucket_traits; @@ -127,104 +133,190 @@ void test_unordered_multiset::test_sort(std::vector -void test_unordered_multiset::test_insert(std::vector& values) +template +void test_unordered_multiset::test_insert(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_multiset , constant_time_size + , cache_begin + , compare_hash > unordered_multiset_type; typedef typename unordered_multiset_type::bucket_traits bucket_traits; + typedef typename unordered_multiset_type::iterator iterator; + { + typename unordered_multiset_type::bucket_type buckets [BucketSize]; + unordered_multiset_type testset(bucket_traits(buckets, BucketSize)); - typename unordered_multiset_type::bucket_type buckets [BucketSize]; - unordered_multiset_type testset(bucket_traits(buckets, BucketSize)); + testset.insert(&values[0] + 2, &values[0] + 5); - testset.insert(&values[0] + 2, &values[0] + 5); + const unordered_multiset_type& const_testset = testset; + { int init_values [] = { 1, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, const_testset.begin() ); } - const unordered_multiset_type& const_testset = testset; - { int init_values [] = { 1, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, const_testset.begin() ); } + typename unordered_multiset_type::iterator i = testset.begin(); + BOOST_TEST (i->value_ == 1); - typename unordered_multiset_type::iterator i = testset.begin(); - BOOST_TEST (i->value_ == 1); + i = testset.insert (values[0]); + BOOST_TEST (&*i == &values[0]); + + i = testset.iterator_to (values[2]); + BOOST_TEST (&*i == &values[2]); + testset.erase(i); - i = testset.insert (values[0]); - BOOST_TEST (&*i == &values[0]); - - i = testset.iterator_to (values[2]); - BOOST_TEST (&*i == &values[2]); - testset.erase(i); + { int init_values [] = { 1, 3, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, const_testset.begin() ); } + testset.clear(); + testset.insert(&values[0], &values[0] + values.size()); - { int init_values [] = { 1, 3, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, const_testset.begin() ); } - testset.clear(); - testset.insert(&values[0], &values[0] + values.size()); + { int init_values [] = { 1, 2, 2, 3, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, const_testset.begin() ); } - { int init_values [] = { 1, 2, 2, 3, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, const_testset.begin() ); } + BOOST_TEST (testset.erase(1) == 1); + BOOST_TEST (testset.erase(2) == 2); + BOOST_TEST (testset.erase(3) == 1); + BOOST_TEST (testset.erase(4) == 1); + BOOST_TEST (testset.erase(5) == 1); + BOOST_TEST (testset.empty() == true); - BOOST_TEST (testset.erase(1) == 1); - BOOST_TEST (testset.erase(2) == 2); - BOOST_TEST (testset.erase(3) == 1); - BOOST_TEST (testset.erase(4) == 1); - BOOST_TEST (testset.erase(5) == 1); - BOOST_TEST (testset.empty() == true); + //Now with a single bucket + typename unordered_multiset_type::bucket_type single_bucket[1]; + unordered_multiset_type testset2(bucket_traits(single_bucket, 1)); + testset2.insert(&values[0], &values[0] + values.size()); + BOOST_TEST (testset2.erase(5) == 1); + BOOST_TEST (testset2.erase(2) == 2); + BOOST_TEST (testset2.erase(1) == 1); + BOOST_TEST (testset2.erase(4) == 1); + BOOST_TEST (testset2.erase(3) == 1); + BOOST_TEST (testset2.empty() == true); + } + { + //Now erase just one per loop + const int random_init[] = { 3, 2, 4, 1, 5, 2, 2 }; + const unsigned int random_size = sizeof(random_init)/sizeof(random_init[0]); + typename unordered_multiset_type::bucket_type single_bucket[1]; + for(unsigned int i = 0, max = random_size; i != max; ++i){ + std::vector data (random_size); + for (unsigned int j = 0; j < random_size; ++j) + data[j].value_ = random_init[j]; + unordered_multiset_type testset_new(bucket_traits(single_bucket, 1)); + testset_new.insert(&data[0], &data[0]+max); + testset_new.erase(testset_new.iterator_to(data[i])); + BOOST_TEST (testset_new.size() == (max -1)); + } + } + { + typename unordered_multiset_type::bucket_type buckets [BucketSize]; + const unsigned int NumBucketSize = BucketSize; + const unsigned int LoadFactor = 3; + const unsigned int NumIterations = NumBucketSize*LoadFactor; + std::vector random_init(NumIterations);//Preserve memory + std::vector set_tester; + set_tester.reserve(NumIterations); - //Now with a single bucket - typename unordered_multiset_type::bucket_type single_bucket[1]; - unordered_multiset_type testset2(bucket_traits(single_bucket, 1)); - testset2.insert(&values[0], &values[0] + values.size()); - BOOST_TEST (testset2.erase(5) == 1); - BOOST_TEST (testset2.erase(2) == 2); - BOOST_TEST (testset2.erase(1) == 1); - BOOST_TEST (testset2.erase(4) == 1); - BOOST_TEST (testset2.erase(3) == 1); - BOOST_TEST (testset2.empty() == true); + //Initialize values + for (unsigned int i = 0; i < NumIterations; ++i){ + random_init[i].value_ = i*2;//(i/LoadFactor)*LoadFactor; + } + + for(unsigned int initial_pos = 0; initial_pos != (NumIterations+1); ++initial_pos){ + for(unsigned int final_pos = initial_pos; final_pos != (NumIterations+1); ++final_pos){ + + //Create intrusive container inserting values + unordered_multiset_type testset + ( &random_init[0] + , &random_init[0] + random_init.size() + , bucket_traits(buckets, NumBucketSize)); + + BOOST_TEST (testset.size() == random_init.size()); + + //Obtain the iterator range to erase + iterator it_beg_pos = testset.begin(); + for(unsigned int it_beg_pos_num = 0; it_beg_pos_num != initial_pos; ++it_beg_pos_num){ + ++it_beg_pos; + } + iterator it_end_pos(it_beg_pos); + for(unsigned int it_end_pos_num = 0; it_end_pos_num != (final_pos - initial_pos); ++it_end_pos_num){ + ++it_end_pos; + } + + //Erase the same values in both the intrusive and original vector + std::size_t erased_cnt = std::distance(it_beg_pos, it_end_pos); + + //Erase values from the intrusive container + testset.erase(it_beg_pos, it_end_pos); + + BOOST_TEST (testset.size() == (random_init.size()-(final_pos - initial_pos))); + + //Now test... + BOOST_TEST ((random_init.size() - erased_cnt) == testset.size()); + + //Create an ordered copy of the intrusive container + set_tester.insert(set_tester.end(), testset.begin(), testset.end()); + std::sort(set_tester.begin(), set_tester.end()); + { + typename std::vector::iterator it = set_tester.begin(), itend = set_tester.end(); + typename std::vector::iterator random_init_it(random_init.begin()); + for( ; it != itend; ++it){ + while(!random_init_it->is_linked()) + ++random_init_it; + BOOST_TEST(*it == *random_init_it); + ++random_init_it; + } + } + set_tester.clear(); + } + } + } } //test: insert (seq-version), swap, erase (seq-version), size: -template -void test_unordered_multiset::test_swap(std::vector& values) +template +void test_unordered_multiset::test_swap(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_multiset , constant_time_size + , cache_begin + , compare_hash > unordered_multiset_type; typedef typename unordered_multiset_type::bucket_traits bucket_traits; - typename unordered_multiset_type::bucket_type buckets [BucketSize]; - typename unordered_multiset_type::bucket_type buckets2 [BucketSize]; - unordered_multiset_type testset1(&values[0], &values[0] + 2, bucket_traits(buckets, BucketSize)); - unordered_multiset_type testset2(bucket_traits(buckets2, BucketSize)); + { + typename unordered_multiset_type::bucket_type buckets2 [BucketSize]; + unordered_multiset_type testset1(&values[0], &values[0] + 2, bucket_traits(buckets, BucketSize)); + unordered_multiset_type testset2(bucket_traits(buckets2, BucketSize)); - testset2.insert (&values[0] + 2, &values[0] + 6); - testset1.swap (testset2); + testset2.insert (&values[0] + 2, &values[0] + 6); + testset1.swap (testset2); - { int init_values [] = { 1, 2, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testset1.begin() ); } + { int init_values [] = { 1, 2, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testset1.begin() ); } - { int init_values [] = { 2, 3 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testset2.begin() ); } - - testset1.erase (testset1.iterator_to(values[5]), testset1.end()); - BOOST_TEST (testset1.size() == 1); - // BOOST_TEST (&testset1.front() == &values[3]); - BOOST_TEST (&*testset1.begin() == &values[3]); + { int init_values [] = { 2, 3 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testset2.begin() ); } + testset1.erase (testset1.iterator_to(values[5]), testset1.end()); + BOOST_TEST (testset1.size() == 1); + // BOOST_TEST (&testset1.front() == &values[3]); + BOOST_TEST (&*testset1.begin() == &values[3]); + } } //test: rehash: -template -void test_unordered_multiset::test_rehash(std::vector& values) +template +void test_unordered_multiset::test_rehash(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_multiset , constant_time_size + , cache_begin + , compare_hash > unordered_multiset_type; typedef typename unordered_multiset_type::bucket_traits bucket_traits; @@ -261,14 +353,16 @@ void test_unordered_multiset::test_rehash(std::vector -void test_unordered_multiset::test_find(std::vector& values) +template +void test_unordered_multiset::test_find(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_multiset , constant_time_size + , cache_begin + , compare_hash > unordered_multiset_type; typedef typename unordered_multiset_type::bucket_traits bucket_traits; @@ -293,8 +387,8 @@ void test_unordered_multiset::test_find(std::vector -void test_unordered_multiset +template +void test_unordered_multiset ::test_clone(std::vector& values) { typedef typename ValueTraits::value_type value_type; @@ -302,6 +396,8 @@ void test_unordered_multiset , constant_time_size + , cache_begin + , compare_hash > unordered_multiset_type; typedef typename unordered_multiset_type::bucket_traits bucket_traits; { @@ -373,6 +469,8 @@ class test_main_template < value_type , typename value_type::unordered_set_base_hook_t >::type + , true + , false >::test_all(data); test_unordered_multiset < typename detail::get_member_value_traits @@ -382,6 +480,8 @@ class test_main_template , &value_type::unordered_set_node_ > >::type + , false + , false >::test_all(data); return 0; @@ -404,6 +504,8 @@ class test_main_template < value_type , typename value_type::unordered_set_base_hook_t >::type + , true + , false >::test_all(data); test_unordered_multiset < typename detail::get_member_value_traits @@ -413,12 +515,16 @@ class test_main_template , &value_type::unordered_set_node_ > >::type + , false + , false >::test_all(data); test_unordered_multiset < typename detail::get_base_value_traits < value_type , typename value_type::unordered_set_auto_base_hook_t >::type + , true + , true >::test_all(data); test_unordered_multiset < typename detail::get_member_value_traits @@ -428,6 +534,8 @@ class test_main_template , &value_type::unordered_set_auto_node_ > >::type + , false + , true >::test_all(data); return 0; } diff --git a/test/unordered_set_test.cpp b/test/unordered_set_test.cpp index 3eeccf6..7702a2e 100644 --- a/test/unordered_set_test.cpp +++ b/test/unordered_set_test.cpp @@ -26,7 +26,7 @@ using namespace boost::intrusive; static const std::size_t BucketSize = 11; -template +template struct test_unordered_set { typedef typename ValueTraits::value_type value_type; @@ -40,14 +40,16 @@ struct test_unordered_set static void test_clone(std::vector& values); }; -template -void test_unordered_set::test_all(std::vector& values) +template +void test_unordered_set::test_all(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_set , constant_time_size + , cache_begin + , compare_hash > unordered_set_type; typedef typename unordered_set_type::bucket_traits bucket_traits; { @@ -75,14 +77,16 @@ void test_unordered_set::test_all(std::vector -void test_unordered_set::test_impl() +template +void test_unordered_set::test_impl() { typedef typename ValueTraits::value_type value_type; typedef unordered_set , constant_time_size + , cache_begin + , compare_hash > unordered_set_type; typedef typename unordered_set_type::bucket_traits bucket_traits; @@ -103,14 +107,16 @@ void test_unordered_set::test_impl() } //test: constructor, iterator, clear, reverse_iterator, front, back, size: -template -void test_unordered_set::test_sort(std::vector& values) +template +void test_unordered_set::test_sort(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_set , constant_time_size + , cache_begin + , compare_hash > unordered_set_type; typedef typename unordered_set_type::bucket_traits bucket_traits; @@ -126,14 +132,16 @@ void test_unordered_set::test_sort(std::vector -void test_unordered_set::test_insert(std::vector& values) +template +void test_unordered_set::test_insert(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_set , constant_time_size + , cache_begin + , compare_hash > unordered_set_type; typedef typename unordered_set_type::bucket_traits bucket_traits; @@ -161,14 +169,16 @@ void test_unordered_set::test_insert(std::vector -void test_unordered_set::test_swap(std::vector& values) +template +void test_unordered_set::test_swap(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_set , constant_time_size + , cache_begin + , compare_hash > unordered_set_type; typedef typename unordered_set_type::bucket_traits bucket_traits; @@ -192,14 +202,16 @@ void test_unordered_set::test_swap(std::vector -void test_unordered_set::test_rehash(std::vector& values) +template +void test_unordered_set::test_rehash(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_set , constant_time_size + , cache_begin + , compare_hash > unordered_set_type; typedef typename unordered_set_type::bucket_traits bucket_traits; @@ -237,14 +249,16 @@ void test_unordered_set::test_rehash(std::vector -void test_unordered_set::test_find(std::vector& values) +template +void test_unordered_set::test_find(std::vector& values) { typedef typename ValueTraits::value_type value_type; typedef unordered_set , constant_time_size + , cache_begin + , compare_hash > unordered_set_type; typedef typename unordered_set_type::bucket_traits bucket_traits; @@ -267,8 +281,8 @@ void test_unordered_set::test_find(std::vector -void test_unordered_set +template +void test_unordered_set ::test_clone(std::vector& values) { typedef typename ValueTraits::value_type value_type; @@ -276,6 +290,8 @@ void test_unordered_set , constant_time_size + , cache_begin + , compare_hash > unordered_set_type; typedef typename unordered_set_type::bucket_traits bucket_traits; { @@ -347,6 +363,8 @@ class test_main_template < value_type , typename value_type::unordered_set_base_hook_t >::type + , true + , false >::test_all(data); test_unordered_set < typename detail::get_member_value_traits < value_type @@ -355,6 +373,8 @@ class test_main_template , &value_type::unordered_set_node_ > >::type + , false + , false >::test_all(data); return 0; @@ -377,6 +397,8 @@ class test_main_template < value_type , typename value_type::unordered_set_base_hook_t >::type + , true + , false >::test_all(data); test_unordered_set < typename detail::get_member_value_traits @@ -386,12 +408,16 @@ class test_main_template , &value_type::unordered_set_node_ > >::type + , false + , false >::test_all(data); test_unordered_set < typename detail::get_base_value_traits < value_type , typename value_type::unordered_set_auto_base_hook_t >::type + , true + , true >::test_all(data); test_unordered_set < typename detail::get_member_value_traits @@ -401,6 +427,8 @@ class test_main_template , &value_type::unordered_set_auto_node_ > >::type + , false + , true >::test_all(data); return 0; }