diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index 791bdd89..30ad3bec 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -564,7 +564,7 @@ namespace boost { namespace unordered { namespace detail { template class functions { - friend class set_hash_functions; + friend class boost::unordered::detail::set_hash_functions; functions& operator=(functions const&); typedef compressed function_pair; diff --git a/include/boost/unordered/detail/fwd.hpp b/include/boost/unordered/detail/fwd.hpp index 395b4057..1949b5d1 100644 --- a/include/boost/unordered/detail/fwd.hpp +++ b/include/boost/unordered/detail/fwd.hpp @@ -21,26 +21,26 @@ namespace unordered { template , + class H = boost::hash, class P = std::equal_to, class A = std::allocator > > class unordered_map; template , + class H = boost::hash, class P = std::equal_to, class A = std::allocator > > class unordered_multimap; template , + class H = boost::hash, class P = std::equal_to, class A = std::allocator > class unordered_set; template , + class H = boost::hash, class P = std::equal_to, class A = std::allocator > class unordered_multiset; diff --git a/include/boost/unordered/detail/node.hpp b/include/boost/unordered/detail/node.hpp deleted file mode 100644 index ab2adb3f..00000000 --- a/include/boost/unordered/detail/node.hpp +++ /dev/null @@ -1,364 +0,0 @@ - -// Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard. -// Copyright (C) 2005-2011 Daniel James -// 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) - -// This contains the basic data structure, apart from the actual values. There's -// no construction or deconstruction here. So this only depends on the pointer -// type. - -#ifndef BOOST_UNORDERED_DETAIL_NODE_HPP_INCLUDED -#define BOOST_UNORDERED_DETAIL_NODE_HPP_INCLUDED - -#include - -#if BOOST_WORKAROUND(__BORLANDC__, <= 0X0582) -#define BOOST_UNORDERED_BORLAND_BOOL(x) (bool)(x) -#else -#define BOOST_UNORDERED_BORLAND_BOOL(x) x -#endif - -namespace boost { namespace unordered { namespace detail { - - // Some forward declarations for buckets and tables - - template class table; - template class buckets; - - //////////////////////////////////////////////////////////////////////////// - // - // This section implements buckets and nodes. Here's a rough - // inheritance diagram, to show how they pull together. - // - // For unordered_set/unordered_map: - // - // bucket value_base::value_type> - // | | - // +--------------+-------------+ - // | - // ungrouped_node - // - // For unordered_multiset/unordered_multimap: - // - // bucket value_base::value_type> - // | | - // +--------------+-------------+ - // | - // grouped_node - - // bucket - // - // bucket is used for both the buckets and as a base class for - // nodes. By using 'bucket_ptr' for 'node_ptr', 'next_' can point - // to either a bucket or a node. This is used later to implement a - // sentinel at the end of the bucket array. - - template - class bucket - { - bucket& operator=(bucket const&); - public: - typedef typename ::boost::unordered::detail::rebind_wrap::type - bucket_allocator; - typedef typename allocator_traits::pointer bucket_ptr; - typedef bucket_ptr node_ptr; - - node_ptr next_; - - bucket() : next_() {} - }; - - // The space used to store values in a node. - - template - struct value_base - { - typedef ValueType value_type; - typename ::boost::aligned_storage< - sizeof(value_type), - ::boost::alignment_of::value>::type data_; - - void* address() { - return this; - } - value_type& value() { - return *(ValueType*) this; - } - value_type* value_ptr() { - return (ValueType*) this; - } - private: - value_base& operator=(value_base const&); - }; - - // In containers with equivalent keys (unordered_multimap and - // unordered_multiset) equivalent nodes are grouped together, in - // containers with unique keys (unordered_map and unordered_set) - // individual nodes are treated as groups of one. The following two - // classes implement the data structure. - - // This is used for containers with unique keys. There are no groups - // so it doesn't add any extra members, and just treats individual - // nodes as groups of one. - - template - struct ungrouped_node - : ::boost::unordered::detail::bucket, - value_base::value_type> - { - typedef ::boost::unordered::detail::bucket bucket; - typedef typename bucket::bucket_ptr bucket_ptr; - typedef typename bucket::node_ptr node_ptr; - typedef typename allocator_traits::value_type value_type; - - std::size_t hash_; - - ungrouped_node() : bucket() {} - - void init(node_ptr) {} - - static node_ptr next_group(node_ptr ptr) - { - return ptr->next_; - } - - static node_ptr next_group2(node_ptr ptr) - { - return ptr->next_; - } - - static std::size_t group_count(node_ptr n) - { - return !n ? 0 : 1; - } - - static void add_after_node(node_ptr n, node_ptr position) - { - n->next_ = position->next_; - position->next_ = position; - } - - static node_ptr unlink_node(bucket& b, node_ptr n) - { - return unlink_nodes(b, n, n->next_); - } - - static node_ptr unlink_nodes(bucket& b, node_ptr begin, node_ptr end) - { - node_ptr prev = b.next_; - while(prev->next_ != begin) prev = prev->next_; - prev->next_ = end; - return prev; - } - - static std::size_t get_hash(node_ptr p) - { - return static_cast(*p).hash_; - } - - static void set_hash(node_ptr p, std::size_t hash) - { - static_cast(*p).hash_ = hash; - } - - static value_type& get_value(node_ptr p) - { - return static_cast(*p).value(); - } - - static value_type* get_value_ptr(node_ptr p) - { - return static_cast(*p).value_ptr(); - } - }; - - // This is used for containers with equivalent keys. It implements a - // circular list running in the opposite direction to the linked - // list through the nodes. - - template - struct grouped_node - : ::boost::unordered::detail::bucket, - value_base::value_type> - { - typedef ::boost::unordered::detail::bucket bucket; - typedef typename bucket::bucket_ptr bucket_ptr; - typedef typename bucket::node_ptr node_ptr; - typedef typename allocator_traits::value_type value_type; - - std::size_t hash_; - node_ptr group_prev_; - - grouped_node() : bucket(), group_prev_() {} - void init(node_ptr n) - { - group_prev_ = n; - } - - static node_ptr next_group(node_ptr ptr) - { - return get(ptr).group_prev_->next_; - } - - static node_ptr next_group2(node_ptr ptr) - { - return get(ptr->next_).group_prev_; - } - - static std::size_t group_count(node_ptr ptr) - { - if (!ptr) return 0; - - node_ptr start = ptr; - std::size_t size = 0; - do { - ++size; - ptr = get(ptr).group_prev_; - } while(ptr != start); - return size; - } - - static void add_after_node(node_ptr n, node_ptr pos) - { - n->next_ = get(pos).group_prev_->next_; - get(n).group_prev_ = get(pos).group_prev_; - get(pos).group_prev_->next_ = n; - get(pos).group_prev_ = n; - } - - static node_ptr unlink_node(bucket& b, node_ptr n) - { - node_ptr next = n->next_; - node_ptr prev = get(n).group_prev_; - - if(prev->next_ != n) { - // The node is at the beginning of a group. - - // Find the previous node pointer: - prev = b.next_; - while(prev->next_ != n) { - prev = next_group2(prev); - } - - // Remove from group - if(BOOST_UNORDERED_BORLAND_BOOL(next) && - get(next).group_prev_ == n) - { - get(next).group_prev_ = get(n).group_prev_; - } - } - else if(BOOST_UNORDERED_BORLAND_BOOL(next) && - get(next).group_prev_ == n) - { - // The deleted node is not at the end of the group, so - // change the link from the next node. - get(next).group_prev_ = get(n).group_prev_; - } - else { - // The deleted node is at the end of the group, so the - // first node in the group is pointing to it. - // Find that to change its pointer. - node_ptr x = get(n).group_prev_; - while(get(x).group_prev_ != n) { - x = get(x).group_prev_; - } - get(x).group_prev_ = get(n).group_prev_; - } - prev->next_ = next; - - return prev; - } - - static node_ptr unlink_nodes(bucket& b, node_ptr begin, node_ptr end) - { - node_ptr prev = get(begin).group_prev_; - - if(prev->next_ != begin) { - // The node is at the beginning of a group. - - // Find the previous node pointer: - prev = b.next_; - while(prev->next_ != begin) prev = next_group2(prev); - - if(BOOST_UNORDERED_BORLAND_BOOL(end)) split_group(end); - } - else { - node_ptr group1 = split_group(begin); - if(BOOST_UNORDERED_BORLAND_BOOL(end)) { - node_ptr group2 = split_group(end); - - if(begin == group2) { - node_ptr end1 = get(group1).group_prev_; - node_ptr end2 = get(group2).group_prev_; - get(group1).group_prev_ = end2; - get(group2).group_prev_ = end1; - } - } - } - - prev->next_ = end; - - return prev; - } - - // Break a ciruclar list into two, with split as the beginning - // of the second group (if split is at the beginning then don't - // split). - static node_ptr split_group(node_ptr split) - { - // Find first node in group. - node_ptr first = split; - while(next_group(first) == first) - first = get(first).group_prev_; - - if(first == split) return split; - - node_ptr last = get(first).group_prev_; - get(first).group_prev_ = get(split).group_prev_; - get(split).group_prev_ = last; - - return first; - } - - static std::size_t get_hash(node_ptr p) { - return static_cast(*p).hash_; - } - static void set_hash(node_ptr p, std::size_t hash) { - static_cast(*p).hash_ = hash; - } - static value_type& get_value(node_ptr p) { - return static_cast(*p).value(); - } - static value_type* get_value_ptr(node_ptr p) { - return static_cast(*p).value_ptr(); - } - - static grouped_node& get(node_ptr ptr) { - return static_cast(*ptr); - } - }; - - // These two classes implement an easy way to pass around the node - // group policy classes without the messy template parameters. - // Whenever you see the template parameter 'G' it's one of these. - - struct ungrouped - { - template - struct node { - typedef ungrouped_node type; - }; - }; - - struct grouped - { - template - struct node { - typedef grouped_node type; - }; - }; - -}}} - -#endif diff --git a/include/boost/unordered/detail/table.hpp b/include/boost/unordered/detail/table.hpp index 2683bace..ed128c9a 100644 --- a/include/boost/unordered/detail/table.hpp +++ b/include/boost/unordered/detail/table.hpp @@ -22,9 +22,11 @@ namespace boost { namespace unordered { namespace iterator_detail { // all no throw template struct iterator; - template struct c_iterator; + template struct c_iterator; template struct l_iterator; - template struct cl_iterator; + template struct cl_iterator; // Local Iterators // @@ -37,7 +39,8 @@ namespace boost { namespace unordered { namespace iterator_detail { NodePointer, Value&> { #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) - template + template friend struct boost::unordered::iterator_detail::cl_iterator; private: #endif @@ -102,11 +105,12 @@ namespace boost { namespace unordered { namespace iterator_detail { cl_iterator() : ptr_() {} - cl_iterator(node_pointer x, std::size_t b, std::size_t c) - : ptr_(x), bucket_(b), bucket_count_(c) {} + cl_iterator(node_pointer x, std::size_t b, std::size_t c) : + ptr_(x), bucket_(b), bucket_count_(c) {} - cl_iterator(boost::unordered::iterator_detail::l_iterator const& x) - : ptr_(x.ptr_), bucket_(x.bucket_), bucket_count_(x.bucket_count_) + cl_iterator(boost::unordered::iterator_detail::l_iterator< + NodePointer, Value> const& x) : + ptr_(x.ptr_), bucket_(x.bucket_), bucket_count_(x.bucket_count_) {} Value const& @@ -147,7 +151,8 @@ namespace boost { namespace unordered { namespace iterator_detail { NodePointer, Value&> { #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) - template + template friend struct boost::unordered::iterator_detail::c_iterator; private: #endif @@ -169,11 +174,14 @@ namespace boost { namespace unordered { namespace iterator_detail { } iterator& operator++() { - node_ = node_ = static_cast(node_->next_); return *this; + node_ = node_ = static_cast(node_->next_); + return *this; } iterator operator++(int) { - iterator tmp(node_); node_ = node_ = static_cast(node_->next_); return tmp; + iterator tmp(node_); + node_ = node_ = static_cast(node_->next_); + return tmp; } bool operator==(iterator const& x) const { @@ -191,7 +199,8 @@ namespace boost { namespace unordered { namespace iterator_detail { std::forward_iterator_tag, Value, std::ptrdiff_t, ConstNodePointer, Value const&> { - friend struct boost::unordered::iterator_detail::iterator; + friend struct boost::unordered::iterator_detail::iterator< + NodePointer, Value>; #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) template @@ -215,7 +224,8 @@ namespace boost { namespace unordered { namespace iterator_detail { explicit c_iterator(node_pointer const& x) : node_(x) {} - c_iterator(boost::unordered::iterator_detail::iterator const& x) : node_(x.node_) {} + c_iterator(boost::unordered::iterator_detail::iterator< + NodePointer, Value> const& x) : node_(x.node_) {} Value const& operator*() const { return node_->value(); @@ -226,11 +236,14 @@ namespace boost { namespace unordered { namespace iterator_detail { } c_iterator& operator++() { - node_ = static_cast(node_->next_); return *this; + node_ = static_cast(node_->next_); + return *this; } c_iterator operator++(int) { - c_iterator tmp(node_); node_ = node_ = static_cast(node_->next_); return tmp; + c_iterator tmp(node_); + node_ = node_ = static_cast(node_->next_); + return tmp; } friend bool operator==(c_iterator const& x, c_iterator const& y) { @@ -248,7 +261,7 @@ namespace boost { namespace unordered { namespace detail { //////////////////////////////////////////////////////////////////////////// // convert double to std::size_t - inline std::size_t double_to_size_t(double f) + inline std::size_t double_to_size(double f) { return f >= static_cast( (std::numeric_limits::max)()) ? @@ -320,10 +333,15 @@ namespace boost { namespace unordered { namespace detail { typedef typename buckets::node_pointer node_pointer; typedef typename buckets::const_node_pointer const_node_pointer; - typedef boost::unordered::iterator_detail::iterator iterator; - typedef boost::unordered::iterator_detail::c_iterator c_iterator; - typedef boost::unordered::iterator_detail::l_iterator l_iterator; - typedef boost::unordered::iterator_detail::cl_iterator cl_iterator; + typedef boost::unordered::iterator_detail:: + iterator iterator; + typedef boost::unordered::iterator_detail:: + c_iterator c_iterator; + typedef boost::unordered::iterator_detail:: + l_iterator l_iterator; + typedef boost::unordered::iterator_detail:: + cl_iterator + cl_iterator; // Members @@ -338,7 +356,7 @@ namespace boost { namespace unordered { namespace detail { using namespace std; // size < mlf_ * count - return boost::unordered::detail::double_to_size_t(ceil( + return boost::unordered::detail::double_to_size(ceil( static_cast(this->mlf_) * static_cast(this->max_bucket_count()) )) - 1; @@ -350,7 +368,7 @@ namespace boost { namespace unordered { namespace detail { // From 6.3.1/13: // Only resize when size >= mlf_ * count - return boost::unordered::detail::double_to_size_t(ceil( + return boost::unordered::detail::double_to_size(ceil( static_cast(this->mlf_) * static_cast(this->bucket_count_) )); @@ -378,7 +396,7 @@ namespace boost { namespace unordered { namespace detail { // count > size / mlf_ return boost::unordered::detail::next_prime( - boost::unordered::detail::double_to_size_t(floor( + boost::unordered::detail::double_to_size(floor( static_cast(size) / static_cast(mlf_))) + 1); } @@ -494,10 +512,12 @@ namespace boost { namespace unordered { namespace detail { move_assign_no_alloc(x); } else { - set_hash_functions new_func_this(*this, x); + boost::unordered::detail::set_hash_functions + new_func_this(*this, x); if (x.size_) { - buckets b(this->node_alloc(), x.min_buckets_for_size(x.size_)); + buckets b(this->node_alloc(), + x.min_buckets_for_size(x.size_)); buckets tmp(x, move_tag()); table_impl::move_buckets_to(tmp, b); b.swap(*this); @@ -514,7 +534,8 @@ namespace boost { namespace unordered { namespace detail { void move_assign_no_alloc(table& x) { - set_hash_functions new_func_this(*this, x); + boost::unordered::detail::set_hash_functions + new_func_this(*this, x); // No throw from here. this->move_buckets_from(x); this->mlf_ = x.mlf_; @@ -537,8 +558,10 @@ namespace boost { namespace unordered { namespace detail { template void swap(table& x, Propagate p) { - set_hash_functions op1(*this, x); - set_hash_functions op2(x, *this); + boost::unordered::detail::set_hash_functions + op1(*this, x); + boost::unordered::detail::set_hash_functions + op2(x, *this); // I think swap can throw if Propagate::value, // since the allocators' swap can throw. Not sure though. this->buckets::swap(x, p); @@ -647,7 +670,7 @@ namespace boost { namespace unordered { namespace detail { } else { min_buckets = next_prime((std::max)(min_buckets, - boost::unordered::detail::double_to_size_t(floor( + boost::unordered::detail::double_to_size(floor( static_cast(this->size_) / static_cast(mlf_))) + 1)); diff --git a/include/boost/unordered/detail/util.hpp b/include/boost/unordered/detail/util.hpp index 28b1e95f..53976f8e 100644 --- a/include/boost/unordered/detail/util.hpp +++ b/include/boost/unordered/detail/util.hpp @@ -151,7 +151,8 @@ namespace boost { namespace unordered { namespace detail { template inline std::size_t initial_size(I i, I j, - std::size_t num_buckets = boost::unordered::detail::default_bucket_count) + std::size_t num_buckets = + boost::unordered::detail::default_bucket_count) { // TODO: Why +1? return (std::max)( @@ -189,15 +190,15 @@ namespace boost { namespace unordered { namespace detail { : boost::detail::if_true< boost::is_empty::value >:: BOOST_NESTED_TEMPLATE then< - compressed_base, - uncompressed_base + boost::unordered::detail::compressed_base, + boost::unordered::detail::uncompressed_base > {}; template struct compressed - : private generate_base::type, - private generate_base::type + : private boost::unordered::detail::generate_base::type, + private boost::unordered::detail::generate_base::type { typedef typename generate_base::type base1; typedef typename generate_base::type base2; diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index 738ce1b2..f12c84b1 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -258,7 +258,8 @@ namespace unordered )).first); \ } - BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EMPLACE, _) + BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, + BOOST_UNORDERED_EMPLACE, _) #undef BOOST_UNORDERED_EMPLACE @@ -536,7 +537,8 @@ namespace unordered // Assign - unordered_multimap& operator=(BOOST_COPY_ASSIGN_REF(unordered_multimap) x) + unordered_multimap& operator=( + BOOST_COPY_ASSIGN_REF(unordered_multimap) x) { table_.assign(x.table_); return *this; @@ -649,7 +651,8 @@ namespace unordered ))); \ } - BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EMPLACE, _) + BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, + BOOST_UNORDERED_EMPLACE, _) #undef BOOST_UNORDERED_EMPLACE diff --git a/include/boost/unordered/unordered_set.hpp b/include/boost/unordered/unordered_set.hpp index 72026ad5..227610bf 100644 --- a/include/boost/unordered/unordered_set.hpp +++ b/include/boost/unordered/unordered_set.hpp @@ -256,7 +256,8 @@ namespace unordered )).first); \ } - BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EMPLACE, _) + BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, + BOOST_UNORDERED_EMPLACE, _) #undef BOOST_UNORDERED_EMPLACE @@ -298,7 +299,8 @@ namespace unordered return this->emplace_hint(hint, x); } - iterator insert(const_iterator hint, BOOST_UNORDERED_RV_REF(value_type) x) + iterator insert(const_iterator hint, + BOOST_UNORDERED_RV_REF(value_type) x) { return this->emplace_hint(hint, boost::move(x)); } @@ -518,7 +520,8 @@ namespace unordered // Assign - unordered_multiset& operator=(BOOST_COPY_ASSIGN_REF(unordered_multiset) x) + unordered_multiset& operator=( + BOOST_COPY_ASSIGN_REF(unordered_multiset) x) { table_.assign(x.table_); return *this; @@ -631,7 +634,8 @@ namespace unordered ))); \ } - BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EMPLACE, _) + BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, + BOOST_UNORDERED_EMPLACE, _) #undef BOOST_UNORDERED_EMPLACE @@ -673,7 +677,8 @@ namespace unordered return this->emplace_hint(hint, x); } - iterator insert(const_iterator hint, BOOST_UNORDERED_RV_REF(value_type) x) + iterator insert(const_iterator hint, + BOOST_UNORDERED_RV_REF(value_type) x) { return this->emplace_hint(hint, boost::move(x)); } @@ -1190,7 +1195,8 @@ namespace unordered #if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST) template - void unordered_multiset::insert(std::initializer_list list) + void unordered_multiset::insert( + std::initializer_list list) { table_.insert_range(list.begin(), list.end()); } @@ -1212,7 +1218,8 @@ namespace unordered template typename unordered_multiset::iterator - unordered_multiset::erase(const_iterator first, const_iterator last) + unordered_multiset::erase( + const_iterator first, const_iterator last) { return iterator(table_.erase_range(first.node_, last.node_)); }