From ad5dcdf8b33c2a31e893df6db29334e586a8ed9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 12 Jun 2007 17:13:44 +0000 Subject: [PATCH] no message [SVN r37976] --- doc/Jamfile.v2 | 6 +-- doc/intrusive.qbk | 3 ++ .../intrusive/detail/parent_from_member.hpp | 9 ++-- .../boost/intrusive/detail/rbtree_node.hpp | 7 ++- include/boost/intrusive/hashtable.hpp | 45 +++++++++++------ include/boost/intrusive/list.hpp | 50 +++++++++---------- include/boost/intrusive/pointer_plus_bit.hpp | 15 ++---- include/boost/intrusive/slist.hpp | 46 ++++++++--------- 8 files changed, 94 insertions(+), 87 deletions(-) diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 8178ae4..ab523ad 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -8,9 +8,9 @@ # See http://www.boost.org/libs/intrusive for documentation. -project boost/intrusive/libs/doc ; +project boost/intrusive/doc ; -import doxygen ; +import boostbook : boostbook ; import quickbook ; doxygen intrusive_doxygen @@ -28,7 +28,7 @@ doxygen intrusive_doxygen xml intrusive_xml : intrusive.qbk ; -boostbook standalone +boostbook intrusive : intrusive_xml intrusive_doxygen diff --git a/doc/intrusive.qbk b/doc/intrusive.qbk index 2682900..e2d1452 100644 --- a/doc/intrusive.qbk +++ b/doc/intrusive.qbk @@ -2393,8 +2393,11 @@ all the objects to be inserted in intrusive containers in containers like `std:: * Visual 7.1/WinXP * Visual 8.0/WinXP * GCC 4.1.1/MinGW +* GCC 3.4.4/Cygwin * Intel 9.1/WinXP * GCC 4.1.2/Linux +* Codewarrior 9.4/WinXP +* GCC 3.4.3 Solaris 11 [endsect] diff --git a/include/boost/intrusive/detail/parent_from_member.hpp b/include/boost/intrusive/detail/parent_from_member.hpp index 93b46e3..6c2e945 100644 --- a/include/boost/intrusive/detail/parent_from_member.hpp +++ b/include/boost/intrusive/detail/parent_from_member.hpp @@ -23,12 +23,11 @@ std::size_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member) { //The implementation of a pointer to member is compiler dependent. #if defined(BOOST_MSVC) || defined(__GNUC__) || \ - defined(BOOST_INTEL) || defined(__HP_aCC) || \ - defined(__EDG_VERSION__) - //This works with gcc, msvc, edg, ac++ + defined(BOOST_INTEL) || defined(__HP_aCC) + //This works with gcc, msvc, ac++ return *(const std::size_t*)(const void*)&ptr_to_member; - #else - //This is the traditional C-front approach: CW 9.4, dmc + #else + //This is the traditional C-front approach: __MWERKS__, __DMC__, __SUNPRO_CC return *(const std::size_t*)(const void*)&ptr_to_member - 1; #endif } diff --git a/include/boost/intrusive/detail/rbtree_node.hpp b/include/boost/intrusive/detail/rbtree_node.hpp index dbcfe2b..baf8c81 100644 --- a/include/boost/intrusive/detail/rbtree_node.hpp +++ b/include/boost/intrusive/detail/rbtree_node.hpp @@ -26,6 +26,7 @@ #include #endif #include +#include namespace boost { namespace intrusive { @@ -170,10 +171,8 @@ struct rbtree_node_traits : public rbtree_node_traits_dispatch - >::type + + >::value >::value > {}; diff --git a/include/boost/intrusive/hashtable.hpp b/include/boost/intrusive/hashtable.hpp index 6ab8e20..5c3d65d 100644 --- a/include/boost/intrusive/hashtable.hpp +++ b/include/boost/intrusive/hashtable.hpp @@ -648,30 +648,43 @@ class hashtable try{ size_type n = 0; - bool same_buffer = old_buckets == new_buckets; - //If we are shrinking the bucket array, just rehash the last nodes - if(same_buffer && (old_buckets_len > new_buckets_len)){ + 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) && + (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; } //Iterate through nodes for(; n < old_buckets_len; ++n){ bucket_type &old_bucket = old_buckets[n]; - local_iterator before_i(old_bucket.before_begin()); - local_iterator end(old_bucket.end()); - local_iterator i(old_bucket.begin()); - for(;i != end; ++i){ - size_type new_n = this->priv_hasher()(*i) % 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; + + if(!fast_shrink){ + local_iterator before_i(old_bucket.before_begin()); + local_iterator end(old_bucket.end()); + local_iterator i(old_bucket.begin()); + for(;i != end; ++i){ + const size_type new_n = (this->priv_hasher()(*i) % 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; + } } } + else{ + const size_type new_n = n % new_buckets_len; + bucket_type &new_b = new_buckets[new_n]; + new_b.splice_after(new_b.before_begin(), old_bucket); + } } this->priv_buckets() = new_buckets; diff --git a/include/boost/intrusive/list.hpp b/include/boost/intrusive/list.hpp index df2089d..c6435cd 100644 --- a/include/boost/intrusive/list.hpp +++ b/include/boost/intrusive/list.hpp @@ -116,7 +116,7 @@ class list list() { size_traits::set_size(size_type(0)); - node_algorithms::init(get_root_node()); + node_algorithms::init(this->get_root_node()); } //! Requires: Dereferencing iterator must yield an lvalue of type value_type. @@ -131,7 +131,7 @@ class list list(Iterator b, Iterator e) { size_traits::set_size(size_type(0)); - node_algorithms::init(get_root_node()); + node_algorithms::init(this->get_root_node()); this->insert(this->end(), b, e); } @@ -166,7 +166,7 @@ class list node_ptr to_insert = ValueTraits::to_node_ptr(value); if(safemode_or_autounlink) BOOST_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::link_before(get_root_node(), to_insert); + node_algorithms::link_before(this->get_root_node(), to_insert); size_traits::increment(); } @@ -185,7 +185,7 @@ class list node_ptr to_insert = ValueTraits::to_node_ptr(value); if(safemode_or_autounlink) BOOST_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::link_before(node_traits::get_next(get_root_node()), to_insert); + node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert); size_traits::increment(); } @@ -199,7 +199,7 @@ class list //! Note: Invalidates the iterators (but not the references) to the erased element. void pop_back() { - node_ptr to_erase = node_traits::get_previous(get_root_node()); + node_ptr to_erase = node_traits::get_previous(this->get_root_node()); node_algorithms::unlink(to_erase); size_traits::decrement(); if(safemode_or_autounlink) @@ -220,7 +220,7 @@ class list template void pop_back_and_destroy(Destroyer destroyer) { - node_ptr to_erase = node_traits::get_previous(get_root_node()); + node_ptr to_erase = node_traits::get_previous(this->get_root_node()); node_algorithms::unlink(to_erase); size_traits::decrement(); if(safemode_or_autounlink) @@ -238,7 +238,7 @@ class list //! Note: Invalidates the iterators (but not the references) to the erased element. void pop_front() { - node_ptr to_erase = node_traits::get_next(get_root_node()); + node_ptr to_erase = node_traits::get_next(this->get_root_node()); node_algorithms::unlink(to_erase); size_traits::decrement(); if(safemode_or_autounlink) @@ -259,7 +259,7 @@ class list template void pop_front_and_destroy(Destroyer destroyer) { - node_ptr to_erase = node_traits::get_next(get_root_node()); + node_ptr to_erase = node_traits::get_next(this->get_root_node()); node_algorithms::unlink(to_erase); size_traits::decrement(); if(safemode_or_autounlink) @@ -273,7 +273,7 @@ class list //! //! Complexity: Constant. reference front() - { return *ValueTraits::to_value_ptr(node_traits::get_next(get_root_node())); } + { return *ValueTraits::to_value_ptr(node_traits::get_next(this->get_root_node())); } //! Effects: Returns a const_reference to the first element of the list. //! @@ -281,7 +281,7 @@ class list //! //! Complexity: Constant. const_reference front() const - { return *ValueTraits::to_value_ptr(uncast(node_traits::get_next(get_root_node()))); } + { return *ValueTraits::to_value_ptr(uncast(node_traits::get_next(this->get_root_node()))); } //! Effects: Returns a reference to the last element of the list. //! @@ -289,7 +289,7 @@ class list //! //! Complexity: Constant. reference back() - { return *ValueTraits::to_value_ptr(node_traits::get_previous(get_root_node())); } + { return *ValueTraits::to_value_ptr(node_traits::get_previous(this->get_root_node())); } //! Effects: Returns a const_reference to the last element of the list. //! @@ -297,7 +297,7 @@ class list //! //! Complexity: Constant. const_reference back() const - { return *ValueTraits::to_value_ptr(uncast(node_traits::get_previous(get_root_node()))); } + { return *ValueTraits::to_value_ptr(uncast(node_traits::get_previous(this->get_root_node()))); } //! Effects: Returns an iterator to the first element contained in the list. //! @@ -305,7 +305,7 @@ class list //! //! Complexity: Constant. iterator begin() - { return iterator(node_traits::get_next(get_root_node())); } + { return iterator(node_traits::get_next(this->get_root_node())); } //! Effects: Returns a const_iterator to the first element contained in the list. //! @@ -321,7 +321,7 @@ class list //! //! Complexity: Constant. const_iterator cbegin() const - { return const_iterator(node_traits::get_next(get_root_node())); } + { return const_iterator(node_traits::get_next(this->get_root_node())); } //! Effects: Returns an iterator to the end of the list. //! @@ -329,7 +329,7 @@ class list //! //! Complexity: Constant. iterator end() - { return iterator(get_root_node()); } + { return iterator(this->get_root_node()); } //! Effects: Returns a const_iterator to the end of the list. //! @@ -345,7 +345,7 @@ class list //! //! Complexity: Constant. const_iterator cend() const - { return const_iterator(uncast(get_root_node())); } + { return const_iterator(uncast(this->get_root_node())); } //! Effects: Returns a reverse_iterator pointing to the beginning //! of the reversed list. @@ -436,7 +436,7 @@ class list if(ConstantTimeSize) return size_traits::get_size(); else - return node_algorithms::count(get_root_node()) - 1; + return node_algorithms::count(this->get_root_node()) - 1; } //! Effects: Returns true if the list contains no elements. @@ -447,7 +447,7 @@ class list //! //! Note: Does not affect the validity of iterators and references. bool empty() const - { return node_algorithms::unique(get_root_node()); } + { return node_algorithms::unique(this->get_root_node()); } //! Effects: Swaps the elements of x and *this. //! @@ -458,7 +458,7 @@ class list //! Note: Does not affect the validity of iterators and references. void swap(list& other) { - node_algorithms::swap_nodes(get_root_node(), other.get_root_node()); + node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node()); if(ConstantTimeSize){ size_type backup = size_traits::get_size(); size_traits::set_size(other.get_size()); @@ -479,7 +479,7 @@ class list { //Null shift, nothing to do if(!n) return; - node_ptr root = get_root_node(); + node_ptr root = this->get_root_node(); node_ptr last = node_traits::get_previous(root); //size() == 0 or 1, nothing to do if(last == node_traits::get_next(root)) return; @@ -505,7 +505,7 @@ class list { //Null shift, nothing to do if(!n) return; - node_ptr root = get_root_node(); + node_ptr root = this->get_root_node(); node_ptr first = node_traits::get_next(root); //size() == 0 or 1, nothing to do if(first == node_traits::get_previous(root)) return; @@ -636,7 +636,7 @@ class list this->erase(this->begin(), this->end()); } else{ - node_algorithms::init(get_root_node()); + node_algorithms::init(this->get_root_node()); size_traits::set_size(size_type(0)); } } @@ -898,8 +898,8 @@ class list template void sort(Predicate p) { - if(node_traits::get_next(get_root_node()) - != node_traits::get_previous(get_root_node())){ + if(node_traits::get_next(this->get_root_node()) + != node_traits::get_previous(this->get_root_node())){ list carry; list counter[64]; int fill = 0; @@ -975,7 +975,7 @@ class list //! //! Note: Iterators and references are not invalidated void reverse() - { node_algorithms::reverse(get_root_node()); } + { node_algorithms::reverse(this->get_root_node()); } //! Effects: Removes all the elements that compare equal to value. //! No destructors are called. diff --git a/include/boost/intrusive/pointer_plus_bit.hpp b/include/boost/intrusive/pointer_plus_bit.hpp index 8a2de51..35542b2 100644 --- a/include/boost/intrusive/pointer_plus_bit.hpp +++ b/include/boost/intrusive/pointer_plus_bit.hpp @@ -13,9 +13,6 @@ #ifndef BOOST_INTRUSIVE_POINTER_PLUS_BIT_HPP #define BOOST_INTRUSIVE_POINTER_PLUS_BIT_HPP -#include -#include - namespace boost { namespace intrusive { @@ -23,7 +20,7 @@ namespace intrusive { //!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 +template struct has_pointer_plus_bit { enum { value = false }; @@ -32,11 +29,10 @@ struct has_pointer_plus_bit //!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 +template +struct has_pointer_plus_bit { - enum { value = (boost::alignment_of::value % 2u) == 0 }; + enum { value = N % 2u == 0 }; }; //!This is class that is supposed to have static methods @@ -57,9 +53,6 @@ struct pointer_plus_bit { typedef T* pointer; - //Check that the pointer can embed the bit - BOOST_STATIC_ASSERT((has_pointer_plus_bit::value)); - static pointer get_pointer(pointer n) { return pointer(std::size_t(n) & std::size_t(~1u)); } diff --git a/include/boost/intrusive/slist.hpp b/include/boost/intrusive/slist.hpp index 9a605c7..ffdaacc 100644 --- a/include/boost/intrusive/slist.hpp +++ b/include/boost/intrusive/slist.hpp @@ -137,7 +137,7 @@ class slist slist() { size_traits::set_size(size_type(0)); - node_algorithms::init(get_root_node()); + node_algorithms::init(this->get_root_node()); } //! Requires: Dereferencing iterator must yield an lvalue of type value_type. @@ -152,7 +152,7 @@ class slist slist(Iterator b, Iterator e) { size_traits::set_size(size_type(0)); - node_algorithms::init(get_root_node()); + node_algorithms::init(this->get_root_node()); insert_after(before_begin(), b, e); } @@ -182,7 +182,7 @@ class slist this->erase_after(this->before_begin(), this->end()); } else{ - node_algorithms::init(get_root_node()); + node_algorithms::init(this->get_root_node()); size_traits::set_size(size_type(0)); } } @@ -213,10 +213,10 @@ class slist //! Note: Does not affect the validity of iterators and references. void push_front(reference value) { - node_ptr to_insert(ValueTraits::to_node_ptr(value)); + node_ptr to_insert = ValueTraits::to_node_ptr(value); if(safemode_or_autounlink) BOOST_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::link_after(get_root_node(), to_insert); + node_algorithms::link_after(this->get_root_node(), to_insert); size_traits::increment(); } @@ -230,8 +230,8 @@ class slist //! Note: Invalidates the iterators (but not the references) to the erased element. void pop_front() { - node_ptr to_erase = node_traits::get_next(get_root_node()); - node_algorithms::unlink_after(get_root_node()); + node_ptr to_erase = node_traits::get_next(this->get_root_node()); + node_algorithms::unlink_after(this->get_root_node()); size_traits::decrement(); if(safemode_or_autounlink) node_algorithms::init(to_erase); @@ -250,7 +250,7 @@ class slist template void pop_front_and_destroy(Destroyer destroyer) { - node_ptr to_erase = node_traits::get_next(get_root_node()); + node_ptr to_erase = node_traits::get_next(this->get_root_node()); this->pop_front(); destroyer(ValueTraits::to_value_ptr(to_erase)); } @@ -261,7 +261,7 @@ class slist //! //! Complexity: Constant. reference front() - { return *ValueTraits::to_value_ptr(node_traits::get_next(get_root_node())); } + { return *ValueTraits::to_value_ptr(node_traits::get_next(this->get_root_node())); } //! Effects: Returns a const_reference to the first element of the list. //! @@ -269,7 +269,7 @@ class slist //! //! Complexity: Constant. const_reference front() const - { return *ValueTraits::to_value_ptr(uncast(node_traits::get_next(get_root_node()))); } + { return *ValueTraits::to_value_ptr(uncast(node_traits::get_next(this->get_root_node()))); } //! Effects: Returns an iterator to the first element contained in the list. //! @@ -277,7 +277,7 @@ class slist //! //! Complexity: Constant. iterator begin() - { return iterator (node_traits::get_next(get_root_node())); } + { return iterator (node_traits::get_next(this->get_root_node())); } //! Effects: Returns a const_iterator to the first element contained in the list. //! @@ -285,7 +285,7 @@ class slist //! //! Complexity: Constant. const_iterator begin() const - { return const_iterator (node_traits::get_next(get_root_node())); } + { return const_iterator (node_traits::get_next(this->get_root_node())); } //! Effects: Returns a const_iterator to the first element contained in the list. //! @@ -293,7 +293,7 @@ class slist //! //! Complexity: Constant. const_iterator cbegin() const - { return const_iterator (node_traits::get_next(get_root_node())); } + { return const_iterator (node_traits::get_next(this->get_root_node())); } //! Effects: Returns an iterator to the end of the list. //! @@ -301,7 +301,7 @@ class slist //! //! Complexity: Constant. iterator end() - { return iterator (get_root_node()); } + { return iterator (this->get_root_node()); } //! Effects: Returns a const_iterator to the end of the list. //! @@ -309,7 +309,7 @@ class slist //! //! Complexity: Constant. const_iterator end() const - { return const_iterator (uncast(get_root_node())); } + { return const_iterator (uncast(this->get_root_node())); } //! Effects: Returns a const_iterator to the end of the list. //! @@ -317,7 +317,7 @@ class slist //! //! Complexity: Constant. const_iterator cend() const - { return const_iterator (uncast(get_root_node())); } + { return const_iterator (uncast(this->get_root_node())); } //! Effects: Returns an iterator that points to a position //! before the first element. Equivalent to "end()" @@ -381,7 +381,7 @@ class slist if(ConstantTimeSize) return size_traits::get_size(); else - return node_algorithms::count(get_root_node()) - 1; + return node_algorithms::count(this->get_root_node()) - 1; } //! Effects: Returns true if the list contains no elements. @@ -392,7 +392,7 @@ class slist //! //! Note: Does not affect the validity of iterators and references. bool empty() const - { return node_algorithms::unique(get_root_node()); } + { return node_algorithms::unique(this->get_root_node()); } //! Effects: Swaps the elements of x and *this. //! @@ -403,7 +403,7 @@ class slist //! Note: Does not affect the validity of iterators and references. void swap(slist& other) { - node_algorithms::swap_nodes(get_root_node(), other.get_root_node()); + node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node()); if(ConstantTimeSize){ size_type backup = size_traits::get_size(); size_traits::set_size(other.get_size()); @@ -424,7 +424,7 @@ class slist { //Null shift, nothing to do if(!n) return; - node_ptr root = get_root_node(); + node_ptr root = this->get_root_node(); node_ptr first = node_traits::get_next(root); //size() == 0 or 1, nothing to do @@ -474,7 +474,7 @@ class slist { //Null shift, nothing to do if(!n) return; - node_ptr root = get_root_node(); + node_ptr root = this->get_root_node(); node_ptr first = node_traits::get_next(root); //size() == 0 or 1, nothing to do @@ -1029,7 +1029,7 @@ class slist template void sort(Predicate p) { - if (node_traits::get_next(node_traits::get_next(get_root_node())) + if (node_traits::get_next(node_traits::get_next(this->get_root_node())) != this->get_root_node()) { slist carry; slist counter[64]; @@ -1159,7 +1159,7 @@ class slist //! //! Note: Iterators and references are not invalidated void reverse() - { node_algorithms::reverse(get_root_node()); } + { node_algorithms::reverse(this->get_root_node()); } //! Effects: Removes all the elements that compare equal to value. //! No destructors are called.