Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2007-12-08 12:51:10


Author: danieljames
Date: 2007-12-08 12:51:09 EST (Sat, 08 Dec 2007)
New Revision: 41897
URL: http://svn.boost.org/trac/boost/changeset/41897

Log:
Use a template parameter for hash_table_data instead of a macro.
Text files modified:
   sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table.hpp | 33 +++++++----------------------
   sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table_impl.hpp | 45 +++++++++++++++++----------------------
   2 files changed, 28 insertions(+), 50 deletions(-)

Modified: sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table.hpp
==============================================================================
--- sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table.hpp (original)
+++ sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table.hpp 2007-12-08 12:51:09 EST (Sat, 08 Dec 2007)
@@ -360,27 +360,10 @@
     }
 }
 
-#define BOOST_UNORDERED_HASH_EQUIVALENT 1
 #include <boost/unordered/detail/hash_table_impl.hpp>
-#undef BOOST_UNORDERED_HASH_EQUIVALENT
-
-#define BOOST_UNORDERED_HASH_EQUIVALENT 0
-#include <boost/unordered/detail/hash_table_impl.hpp>
-#undef BOOST_UNORDERED_HASH_EQUIVALENT
 
 namespace boost {
     namespace unordered_detail {
- //
- // Hash Table Data
- //
-
- // TODO: Only instantiate the version that is wanted.
- template <typename Alloc, typename EquivKeys>
- struct select_hash_table_data
- : public boost::mpl::if_<
- EquivKeys,
- hash_table_data_equivalent_keys<Alloc>,
- hash_table_data_unique_keys<Alloc> > {};
 
         //
         // Hash Table
@@ -390,9 +373,9 @@
             typename Hash, typename Pred,
             typename Alloc, typename EquivKeys>
         class hash_table
- : public select_hash_table_data<Alloc, EquivKeys>::type
+ : public hash_table_data<Alloc, EquivKeys>
         {
- typedef typename select_hash_table_data<Alloc, EquivKeys>::type data;
+ typedef hash_table_data<Alloc, EquivKeys> data;
             typedef typename data::node_constructor node_constructor;
             typedef typename data::bucket_ptr bucket_ptr;
             typedef typename data::link_ptr link_ptr;
@@ -1321,7 +1304,7 @@
             typedef BOOST_DEDUCED_TYPENAME allocator_value_type<Alloc>::type value_type;
 
         private:
- typedef typename select_hash_table_data<Alloc, EquivKeys>::type data;
+ typedef hash_table_data<Alloc, EquivKeys> data;
             typedef BOOST_DEDUCED_TYPENAME data::local_iterator_base base;
             typedef hash_const_local_iterator<Alloc, EquivKeys> const_local_iterator;
 
@@ -1355,7 +1338,7 @@
             typedef BOOST_DEDUCED_TYPENAME allocator_value_type<Alloc>::type value_type;
 
         private:
- typedef typename select_hash_table_data<Alloc, EquivKeys>::type data;
+ typedef hash_table_data<Alloc, EquivKeys> data;
             typedef BOOST_DEDUCED_TYPENAME data::local_iterator_base base;
             typedef hash_local_iterator<Alloc, EquivKeys> local_iterator;
             friend class hash_local_iterator<Alloc, EquivKeys>;
@@ -1393,7 +1376,7 @@
             typedef BOOST_DEDUCED_TYPENAME allocator_value_type<Alloc>::type value_type;
 
         private:
- typedef typename select_hash_table_data<Alloc, EquivKeys>::type data;
+ typedef hash_table_data<Alloc, EquivKeys> data;
             typedef BOOST_DEDUCED_TYPENAME data::iterator_base base;
             typedef hash_const_iterator<Alloc, EquivKeys> const_iterator;
             friend class hash_const_iterator<Alloc, EquivKeys>;
@@ -1427,7 +1410,7 @@
             typedef BOOST_DEDUCED_TYPENAME allocator_value_type<Alloc>::type value_type;
 
         private:
- typedef typename select_hash_table_data<Alloc, EquivKeys>::type data;
+ typedef hash_table_data<Alloc, EquivKeys> data;
             typedef BOOST_DEDUCED_TYPENAME data::iterator_base base;
             typedef hash_iterator<Alloc, EquivKeys> iterator;
             friend class hash_iterator<Alloc, EquivKeys>;
@@ -1468,7 +1451,7 @@
                 boost::unordered_detail::rebind_wrap<Alloc, ValueType>::type
                 value_allocator;
 
- typedef typename select_hash_table_data<value_allocator, boost::mpl::false_>::type data;
+ typedef hash_table_data<value_allocator, boost::mpl::false_> data;
             typedef hash_table<ValueType, KeyType, Hash, Pred,
                     value_allocator, boost::mpl::false_> hash_table;
             typedef BOOST_DEDUCED_TYPENAME data::iterator_base iterator_base;
@@ -1491,7 +1474,7 @@
                 boost::unordered_detail::rebind_wrap<Alloc, ValueType>::type
                 value_allocator;
 
- typedef typename select_hash_table_data<value_allocator, boost::mpl::true_>::type data;
+ typedef hash_table_data<value_allocator, boost::mpl::true_> data;
             typedef hash_table<ValueType, KeyType, Hash, Pred,
                     value_allocator, boost::mpl::true_> hash_table;
             typedef BOOST_DEDUCED_TYPENAME data::iterator_base iterator_base;

Modified: sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table_impl.hpp
==============================================================================
--- sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table_impl.hpp (original)
+++ sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table_impl.hpp 2007-12-08 12:51:09 EST (Sat, 08 Dec 2007)
@@ -4,22 +4,23 @@
 // 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)
 
-#if BOOST_UNORDERED_HASH_EQUIVALENT
-#define HASH_TABLE_DATA hash_table_data_equivalent_keys
-#else
-#define HASH_TABLE_DATA hash_table_data_unique_keys
-#endif
-
 namespace boost {
     namespace unordered_detail {
 
+ template <typename Alloc, typename EquivKeys>
+ struct select_node_base
+ : public boost::mpl::if_<
+ EquivKeys,
+ node_base_equivalent_keys<Alloc>,
+ node_base_unique_keys<Alloc> > {};
+
         //
         // Hash Table Data
         //
         // Responsible for managing the hash buckets.
 
- template <typename Alloc>
- class HASH_TABLE_DATA
+ template <typename Alloc, typename EquivKeys>
+ class hash_table_data
         {
         public:
             typedef bucket<Alloc> bucket;
@@ -40,11 +41,7 @@
             typedef BOOST_DEDUCED_TYPENAME allocator_pointer<node_allocator>::type node_ptr;
             typedef BOOST_DEDUCED_TYPENAME allocator_reference<value_allocator>::type reference;
 
-#if BOOST_UNORDERED_HASH_EQUIVALENT
- typedef node_base_equivalent_keys<Alloc> node_base;
-#else
- typedef node_base_unique_keys<Alloc> node_base;
-#endif
+ typedef typename select_node_base<Alloc, EquivKeys>::type node_base;
 
             typedef BOOST_DEDUCED_TYPENAME
                 boost::unordered_detail::rebind_wrap<Alloc, node_base>::type
@@ -229,7 +226,7 @@
 
                 void next_group()
                 {
- node_ = HASH_TABLE_DATA::next_group(node_);
+ node_ = hash_table_data::next_group(node_);
                 }
             };
 
@@ -288,7 +285,7 @@
 
             // Constructors/Deconstructor
 
- HASH_TABLE_DATA(size_type n, value_allocator const& a)
+ hash_table_data(size_type n, value_allocator const& a)
               : allocators_(a),
                 buckets_(), bucket_count_(next_prime(n)),
                 cached_begin_bucket_(), size_(0)
@@ -311,7 +308,7 @@
                 buckets_ = constructor.release();
             }
 
- HASH_TABLE_DATA(HASH_TABLE_DATA const& x, size_type n)
+ hash_table_data(hash_table_data const& x, size_type n)
               : allocators_(x.allocators_),
                 buckets_(), bucket_count_(next_prime(n)),
                 cached_begin_bucket_(), size_(0)
@@ -335,7 +332,7 @@
             }
 
             // no throw
- ~HASH_TABLE_DATA()
+ ~hash_table_data()
             {
                 if(buckets_) {
                     bucket_ptr begin = cached_begin_bucket_;
@@ -355,13 +352,13 @@
 
         private:
 
- HASH_TABLE_DATA(HASH_TABLE_DATA const&);
- HASH_TABLE_DATA& operator=(HASH_TABLE_DATA const&);
+ hash_table_data(hash_table_data const&);
+ hash_table_data& operator=(hash_table_data const&);
 
         public:
 
             // no throw
- void swap(HASH_TABLE_DATA& other)
+ void swap(hash_table_data& other)
             {
                 std::swap(buckets_, other.buckets_);
                 std::swap(bucket_count_, other.bucket_count_);
@@ -565,7 +562,7 @@
 
             iterator_base create_node(value_type const& v, iterator_base position)
             {
- BOOST_ASSERT(BOOST_UNORDERED_HASH_EQUIVALENT);
+ BOOST_ASSERT(EquivKeys::value);
 
                 // throws, strong exception-safety:
                 link_ptr n = construct_node(v);
@@ -578,7 +575,7 @@
             iterator_base create_node(value_type const& v,
                     bucket_ptr base, local_iterator_base position)
             {
- BOOST_ASSERT(BOOST_UNORDERED_HASH_EQUIVALENT);
+ BOOST_ASSERT(EquivKeys::value);
 
                 // throws, strong exception-safety:
                 link_ptr n = construct_node(v);
@@ -764,7 +761,7 @@
 
 #if defined(BOOST_MPL_CFG_MSVC_ETI_BUG)
         template <>
- class HASH_TABLE_DATA<int>
+ class hash_table_data<int>
         {
         public:
             typedef int size_type;
@@ -774,5 +771,3 @@
 
     }
 }
-
-#undef HASH_TABLE_DATA


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk