From 3d7b6c64b5c7bd0e5f5d53795000e43f3ae0ff85 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 6 Oct 2011 21:31:25 +0000 Subject: [PATCH] Unordered: some more formatting + namespaces [SVN r74767] --- include/boost/unordered/detail/equivalent.hpp | 89 +++++++++++-------- include/boost/unordered/detail/unique.hpp | 64 +++++++------ 2 files changed, 90 insertions(+), 63 deletions(-) diff --git a/include/boost/unordered/detail/equivalent.hpp b/include/boost/unordered/detail/equivalent.hpp index 3594cfe7..85a4780b 100644 --- a/include/boost/unordered/detail/equivalent.hpp +++ b/include/boost/unordered/detail/equivalent.hpp @@ -69,7 +69,8 @@ namespace boost { namespace unordered { namespace detail { // If the allocator uses raw pointers use grouped_ptr_node // Otherwise use grouped_node. - template + template struct pick_grouped_node2 { typedef boost::unordered::detail::grouped_node node; @@ -118,7 +119,7 @@ namespace boost { namespace unordered { namespace detail { template struct multiset { - typedef multiset types; + typedef boost::unordered::detail::multiset types; typedef A allocator; typedef H hasher; @@ -129,18 +130,19 @@ namespace boost { namespace unordered { namespace detail { typedef typename traits::void_pointer void_pointer; typedef value_type key_type; - typedef typename boost::unordered::detail::pick_grouped_node::node node; - typedef typename boost::unordered::detail::pick_grouped_node::bucket bucket; - typedef typename boost::unordered::detail::pick_grouped_node::link_pointer link_pointer; - typedef boost::unordered::detail::grouped_table_impl table; + typedef boost::unordered::detail::pick_grouped_node pick; + typedef typename pick::node node; + typedef typename pick::bucket bucket; + typedef typename pick::link_pointer link_pointer; + typedef boost::unordered::detail::grouped_table_impl table; typedef boost::unordered::detail::set_extractor extractor; }; template struct multimap { - typedef multimap types; + typedef boost::unordered::detail::multimap types; typedef A allocator; typedef H hasher; @@ -151,12 +153,14 @@ namespace boost { namespace unordered { namespace detail { typedef typename traits::value_type value_type; typedef typename traits::void_pointer void_pointer; - typedef typename boost::unordered::detail::pick_grouped_node::node node; - typedef typename boost::unordered::detail::pick_grouped_node::bucket bucket; - typedef typename boost::unordered::detail::pick_grouped_node::link_pointer link_pointer; - typedef boost::unordered::detail::grouped_table_impl table; + typedef boost::unordered::detail::pick_grouped_node pick; + typedef typename pick::node node; + typedef typename pick::bucket bucket; + typedef typename pick::link_pointer link_pointer; - typedef boost::unordered::detail::map_extractor extractor; + typedef boost::unordered::detail::grouped_table_impl table; + typedef boost::unordered::detail::map_extractor + extractor; }; template @@ -234,7 +238,8 @@ namespace boost { namespace unordered { namespace detail { return node_pointer(); } - n = static_cast(static_cast(n->group_prev_)->next_); + n = static_cast( + static_cast(n->group_prev_)->next_); } } @@ -273,8 +278,10 @@ namespace boost { namespace unordered { namespace detail { { node_pointer n2 = other.find_matching_node(n1); if (!n2) return false; - node_pointer end1 = static_cast(static_cast(n1->group_prev_)->next_); - node_pointer end2 = static_cast(static_cast(n2->group_prev_)->next_); + node_pointer end1 = static_cast( + static_cast(n1->group_prev_)->next_); + node_pointer end2 = static_cast( + static_cast(n2->group_prev_)->next_); if (!group_equals(n1, end1, n2, end2)) return false; n1 = end1; } @@ -319,7 +326,8 @@ namespace boost { namespace unordered { namespace detail { value_type const& v = n1->value(); if (find(start, n1, v)) continue; std::size_t matches = count_equal(n2, end2, v); - if (!matches || matches != 1 + count_equal(static_cast(n1->next_), end1, v)) + if (!matches || matches != 1 + count_equal( + static_cast(n1->next_), end1, v)) return false; } @@ -334,7 +342,8 @@ namespace boost { namespace unordered { namespace detail { return false; } - static std::size_t count_equal(node_pointer n, node_pointer end, value_type const& v) + static std::size_t count_equal(node_pointer n, node_pointer end, + value_type const& v) { std::size_t count = 0; for(;n != end; n = static_cast(n->next_)) @@ -371,7 +380,8 @@ namespace boost { namespace unordered { namespace detail { { n->next_ = static_cast(pos->group_prev_)->next_; n->group_prev_ = pos->group_prev_; - static_cast(pos->group_prev_)->next_ = static_cast(n); + static_cast(pos->group_prev_)->next_ = + static_cast(n); pos->group_prev_ = static_cast(n); } @@ -402,8 +412,8 @@ namespace boost { namespace unordered { namespace detail { if (start_node->next_) { this->get_bucket( - static_cast(start_node->next_)->hash_ % - this->bucket_count_)->next_ = n; + static_cast(start_node->next_)->hash_ + % this->bucket_count_)->next_ = n; } b->next_ = start_node; @@ -502,7 +512,7 @@ namespace boost { namespace unordered { namespace detail { } } - //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// // Erase // // no throw @@ -521,18 +531,21 @@ namespace boost { namespace unordered { namespace detail { for (;;) { if (!prev->next_) return 0; - std::size_t node_hash = static_cast(prev->next_)->hash_; + std::size_t node_hash = + static_cast(prev->next_)->hash_; if (node_hash % this->bucket_count_ != bucket_index) return 0; if (node_hash == hash && - this->key_eq()(k, this->get_key(static_cast(prev->next_)->value()))) + this->key_eq()(k, this->get_key( + static_cast(prev->next_)->value()))) break; prev = static_cast( static_cast(prev->next_)->group_prev_); } node_pointer pos = static_cast(prev->next_); - link_pointer end1 = static_cast(pos->group_prev_)->next_; + link_pointer end1 = + static_cast(pos->group_prev_)->next_; node_pointer end = static_cast(end1); prev->next_ = end1; this->fix_buckets(bucket, prev, end); @@ -571,7 +584,8 @@ namespace boost { namespace unordered { namespace detail { static previous_pointer unlink_node(bucket& b, node_pointer n) { node_pointer next = static_cast(n->next_); - previous_pointer prev = static_cast(n->group_prev_); + previous_pointer prev = + static_cast(n->group_prev_); if(prev->next_ != n) { // The node is at the beginning of a group. @@ -579,7 +593,8 @@ namespace boost { namespace unordered { namespace detail { // Find the previous node pointer: prev = b.next_; while(prev->next_ != n) { - prev = static_cast(static_cast(prev->next_)->group_prev_); + prev = static_cast( + static_cast(prev->next_)->group_prev_); } // Remove from group @@ -609,12 +624,13 @@ namespace boost { namespace unordered { namespace detail { return prev; } - static previous_pointer unlink_nodes(bucket& b, node_pointer begin, node_pointer end) + static previous_pointer unlink_nodes(bucket& b, + node_pointer begin, node_pointer end) { - previous_pointer prev = static_cast(begin->group_prev_); + previous_pointer prev = static_cast( + begin->group_prev_); if(prev->next_ != static_cast(begin)) { -std::cout << "A" << std::endl; // The node is at the beginning of a group. // Find the previous node pointer: @@ -626,7 +642,6 @@ std::cout << "A" << std::endl; if (end) split_group(end); } else { -std::cout << "B" << std::endl; node_pointer group1 = split_group(begin); if (end) { @@ -653,7 +668,8 @@ std::cout << "B" << std::endl; { // Find first node in group. node_pointer first = split; - while (static_cast(first->group_prev_)->next_ == static_cast(first)) + while (static_cast(first->group_prev_)->next_ == + static_cast(first)) first = static_cast(first->group_prev_); if(first == split) return split; @@ -665,7 +681,7 @@ std::cout << "B" << std::endl; return first; } - //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// // copy_buckets_to // // Basic exception safety. If an exception is thrown this will @@ -712,11 +728,11 @@ std::cout << "B" << std::endl; } } - //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// // move_buckets_to // - // Basic exception safety. The source nodes are left in an unusable state - // if an exception throws. + // Basic exception safety. The source nodes are left in an unusable + // state if an exception throws. static void move_buckets_to(buckets& src, buckets& dst) { @@ -788,7 +804,8 @@ std::cout << "B" << std::endl; // Iterate through the nodes placing them in the correct buckets. // pre: prev->next_ is not null. - static previous_pointer place_in_bucket(buckets& dst, previous_pointer prev, node_pointer end) + static previous_pointer place_in_bucket(buckets& dst, + previous_pointer prev, node_pointer end) { bucket_pointer b = dst.get_bucket(end->hash_ % dst.bucket_count_); diff --git a/include/boost/unordered/detail/unique.hpp b/include/boost/unordered/detail/unique.hpp index efceaa6b..b1e4d2c1 100644 --- a/include/boost/unordered/detail/unique.hpp +++ b/include/boost/unordered/detail/unique.hpp @@ -65,7 +65,8 @@ namespace boost { namespace unordered { namespace detail { // If the allocator uses raw pointers use ptr_node // Otherwise use node. - template + template struct pick_node2 { typedef boost::unordered::detail::node node; @@ -114,7 +115,7 @@ namespace boost { namespace unordered { namespace detail { template struct set { - typedef set types; + typedef boost::unordered::detail::set types; typedef A allocator; typedef H hasher; @@ -125,18 +126,19 @@ namespace boost { namespace unordered { namespace detail { typedef typename traits::void_pointer void_pointer; typedef value_type key_type; - typedef typename boost::unordered::detail::pick_node::node node; - typedef typename boost::unordered::detail::pick_node::bucket bucket; - typedef typename boost::unordered::detail::pick_node::link_pointer link_pointer; - typedef boost::unordered::detail::table_impl table; + typedef boost::unordered::detail::pick_node pick; + typedef typename pick::node node; + typedef typename pick::bucket bucket; + typedef typename pick::link_pointer link_pointer; + typedef boost::unordered::detail::table_impl table; typedef boost::unordered::detail::set_extractor extractor; }; template struct map { - typedef map types; + typedef boost::unordered::detail::map types; typedef A allocator; typedef H hasher; @@ -147,12 +149,14 @@ namespace boost { namespace unordered { namespace detail { typedef typename traits::value_type value_type; typedef typename traits::void_pointer void_pointer; - typedef typename boost::unordered::detail::pick_node::node node; - typedef typename boost::unordered::detail::pick_node::bucket bucket; - typedef typename boost::unordered::detail::pick_node::link_pointer link_pointer; - typedef boost::unordered::detail::table_impl table; + typedef boost::unordered::detail::pick_node pick; + typedef typename pick::node node; + typedef typename pick::bucket bucket; + typedef typename pick::link_pointer link_pointer; - typedef boost::unordered::detail::map_extractor extractor; + typedef boost::unordered::detail::table_impl table; + typedef boost::unordered::detail::map_extractor + extractor; }; template @@ -454,12 +458,13 @@ namespace boost { namespace unordered { namespace detail { do { // Note: can't use get_key as '*i' might not be value_type - it - // could be a pair with first_types as key_type without const or a - // different second_type. + // could be a pair with first_types as key_type without const or + // a different second_type. // - // TODO: Might be worth storing the value_type instead of the key - // here. Could be more efficient if '*i' is expensive. Could be - // less efficient if copying the full value_type is expensive. + // TODO: Might be worth storing the value_type instead of the + // key here. Could be more efficient if '*i' is expensive. Could + // be less efficient if copying the full value_type is + // expensive. insert_range_impl2(a, extractor::extract(*i), i, j); } while(++i != j); } @@ -509,7 +514,7 @@ namespace boost { namespace unordered { namespace detail { } while(++i != j); } - //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// // Erase // // no throw @@ -528,11 +533,13 @@ namespace boost { namespace unordered { namespace detail { for (;;) { if (!prev->next_) return 0; - std::size_t node_hash = static_cast(prev->next_)->hash_; + std::size_t node_hash = + static_cast(prev->next_)->hash_; if (node_hash % this->bucket_count_ != bucket_index) return 0; if (node_hash == hash && - this->key_eq()(k, this->get_key(static_cast(prev->next_)->value()))) + this->key_eq()(k, this->get_key( + static_cast(prev->next_)->value()))) break; prev = static_cast(prev->next_); } @@ -578,16 +585,18 @@ namespace boost { namespace unordered { namespace detail { return unlink_nodes(b, n, static_cast(n->next_)); } - static previous_pointer unlink_nodes(bucket& b, node_pointer begin, node_pointer end) + static previous_pointer unlink_nodes(bucket& b, + node_pointer begin, node_pointer end) { previous_pointer prev = b.next_; link_pointer begin_void = static_cast(begin); - while(prev->next_ != begin_void) prev = static_cast(prev->next_); + while(prev->next_ != begin_void) + prev = static_cast(prev->next_); prev->next_ = static_cast(end); return prev; } - //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// // copy_buckets_to // // Basic exception safety. If an exception is thrown this will @@ -618,11 +627,11 @@ namespace boost { namespace unordered { namespace detail { } } - //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// // move_buckets_to // - // Basic exception safety. The source nodes are left in an unusable state - // if an exception throws. + // Basic exception safety. The source nodes are left in an unusable + // state if an exception throws. static void move_buckets_to(buckets& src, buckets& dst) { @@ -676,7 +685,8 @@ namespace boost { namespace unordered { namespace detail { // Iterate through the nodes placing them in the correct buckets. // pre: prev->next_ is not null. - static previous_pointer place_in_bucket(buckets& dst, previous_pointer prev) + static previous_pointer place_in_bucket(buckets& dst, + previous_pointer prev) { node_pointer n = static_cast(prev->next_); bucket_pointer b = dst.get_bucket(n->hash_ % dst.bucket_count_);