Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2007-12-07 07:30:28


Author: danieljames
Date: 2007-12-07 07:30:27 EST (Fri, 07 Dec 2007)
New Revision: 41821
URL: http://svn.boost.org/trac/boost/changeset/41821

Log:
Instead of using macros to select the alternative inserts, give them different names and call them explicitly from the container class.
Text files modified:
   sandbox-branches/unordered-refactor/boost/unordered/detail/hash_table_impl.hpp | 48 +++++++++++++++++++--------------------
   sandbox-branches/unordered-refactor/boost/unordered_map.hpp | 16 ++++++++-----
   sandbox-branches/unordered-refactor/boost/unordered_set.hpp | 16 ++++++++-----
   3 files changed, 43 insertions(+), 37 deletions(-)

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-07 07:30:27 EST (Fri, 07 Dec 2007)
@@ -1120,9 +1120,9 @@
                     mlf_(1.0f) // no throw
             {
                 calculate_max_load(); // no throw
-
- // This can throw, but HASH_TABLE_DATA's destructor will clean up.
- insert(i, j);
+ // Inserting elements is left to the containing class.
+ // This is a little odd, but hopefully will be cleaned up with
+ // future development.
             }
             // Copy Construct
 
@@ -1507,13 +1507,11 @@
             // basic exception safety, if hash function throws
             // strong otherwise.
 
-#if BOOST_UNORDERED_HASH_EQUIVALENT
-
             // Insert (equivalent key containers)
 
             // if hash function throws, basic exception safety
             // strong otherwise
- iterator_base insert(value_type const& v)
+ iterator_base insert_equiv(value_type const& v)
             {
                 key_type const& k = extract_key(v);
                 size_type hash_value = hash_function()(k);
@@ -1549,13 +1547,13 @@
 
             // if hash function throws, basic exception safety
             // strong otherwise
- iterator_base insert(iterator_base const& it, value_type const& v)
+ iterator_base insert_equiv(iterator_base const& it, value_type const& v)
             {
                 // equal can throw, but with no effects
                 if (it == this->end() || !equal(extract_key(v), *it)) {
                     // Use the standard insert if the iterator doesn't point
                     // to a matching key.
- return insert(v);
+ return insert_equiv(v);
                 }
                 else {
                     // Find the first node in the group - so that the node
@@ -1591,11 +1589,11 @@
             // if hash function throws, or inserting > 1 element, basic exception safety
             // strong otherwise
             template <typename I>
- void insert_for_range(I i, I j, forward_traversal_tag)
+ void insert_for_range_equiv(I i, I j, forward_traversal_tag)
             {
                 size_type distance = std::distance(i, j);
                 if(distance == 1) {
- insert(*i);
+ insert_equiv(*i);
                 }
                 else {
                     // Only require basic exception safety here
@@ -1620,12 +1618,12 @@
             // if hash function throws, or inserting > 1 element, basic exception safety
             // strong otherwise
             template <typename I>
- void insert_for_range(I i, I j,
+ void insert_for_range_equiv(I i, I j,
                     boost::incrementable_traversal_tag)
             {
                 // If only inserting 1 element, get the required
                 // safety since insert is only called once.
- for (; i != j; ++i) insert(*i);
+ for (; i != j; ++i) insert_equiv(*i);
             }
 
         public:
@@ -1633,13 +1631,13 @@
             // if hash function throws, or inserting > 1 element, basic exception safety
             // strong otherwise
             template <typename I>
- void insert(I i, I j)
+ void insert_equiv(I i, I j)
             {
                 BOOST_DEDUCED_TYPENAME boost::iterator_traversal<I>::type
                     iterator_traversal_tag;
- insert_for_range(i, j, iterator_traversal_tag);
+ insert_for_range_equiv(i, j, iterator_traversal_tag);
             }
-#else
+
             // if hash function throws, basic exception safety
             // strong otherwise
             value_type& operator[](key_type const& k)
@@ -1681,7 +1679,7 @@
 
             // if hash function throws, basic exception safety
             // strong otherwise
- std::pair<iterator_base, bool> insert(value_type const& v)
+ std::pair<iterator_base, bool> insert_unique(value_type const& v)
             {
                 // No side effects in this initial code
                 key_type const& k = extract_key(v);
@@ -1722,40 +1720,40 @@
 
             // if hash function throws, basic exception safety
             // strong otherwise
- iterator_base insert(iterator_base const& it, value_type const& v)
+ iterator_base insert_unique(iterator_base const& it, value_type const& v)
             {
                 if(it != this->end() && equal(extract_key(v), *it))
                     return it;
                 else
- return insert(v).first;
+ return insert_unique(v).first;
             }
 
             // Insert from iterators (unique keys)
 
             template <typename I>
- size_type insert_size(I i, I j, boost::forward_traversal_tag)
+ size_type insert_size_unique(I i, I j, boost::forward_traversal_tag)
             {
                 return std::distance(i, j);
             }
 
             template <typename I>
- size_type insert_size(I, I, boost::incrementable_traversal_tag)
+ size_type insert_size_unique(I, I, boost::incrementable_traversal_tag)
             {
                 return 1;
             }
 
             template <typename I>
- size_type insert_size(I i, I j)
+ size_type insert_size_unique(I i, I j)
             {
                 BOOST_DEDUCED_TYPENAME boost::iterator_traversal<I>::type
                     iterator_traversal_tag;
- return insert_size(i, j, iterator_traversal_tag);
+ return insert_size_unique(i, j, iterator_traversal_tag);
             }
 
             // if hash function throws, or inserting > 1 element, basic exception safety
             // strong otherwise
             template <typename InputIterator>
- void insert(InputIterator i, InputIterator j)
+ void insert_unique(InputIterator i, InputIterator j)
             {
                 // If only inserting 1 element, get the required
                 // safety since insert is only called once.
@@ -1779,7 +1777,7 @@
                         // reserve has basic exception safety if the hash function
                         // throws, strong otherwise.
                         if(size() + 1 >= max_load_) {
- reserve(size() + insert_size(i, j));
+ reserve(size() + insert_size_unique(i, j));
                             bucket = this->buckets_ + this->index_from_hash(hash_value);
                         }
 
@@ -1788,7 +1786,7 @@
                     }
                 }
             }
-#endif
+
         public:
 
             // erase

Modified: sandbox-branches/unordered-refactor/boost/unordered_map.hpp
==============================================================================
--- sandbox-branches/unordered-refactor/boost/unordered_map.hpp (original)
+++ sandbox-branches/unordered-refactor/boost/unordered_map.hpp 2007-12-07 07:30:27 EST (Fri, 07 Dec 2007)
@@ -74,6 +74,7 @@
             : base(f, l, boost::unordered_detail::default_initial_bucket_count,
                 hasher(), key_equal(), allocator_type())
         {
+ base.insert_unique(f, l);
         }
 
         template <class InputIterator>
@@ -84,6 +85,7 @@
                 const allocator_type &a = allocator_type())
             : base(f, l, n, hf, eql, a)
         {
+ base.insert_unique(f, l);
         }
 
     private:
@@ -155,18 +157,18 @@
         std::pair<iterator, bool> insert(const value_type& obj)
         {
             return boost::unordered_detail::pair_cast<iterator, bool>(
- base.insert(obj));
+ base.insert_unique(obj));
         }
 
         iterator insert(const_iterator hint, const value_type& obj)
         {
- return iterator(base.insert(get(hint), obj));
+ return iterator(base.insert_unique(get(hint), obj));
         }
 
         template <class InputIterator>
             void insert(InputIterator first, InputIterator last)
         {
- base.insert(first, last);
+ base.insert_unique(first, last);
         }
 
         iterator erase(const_iterator position)
@@ -389,6 +391,7 @@
             : base(f, l, boost::unordered_detail::default_initial_bucket_count,
                 hasher(), key_equal(), allocator_type())
         {
+ base.insert_equiv(f, l);
         }
 
         template <class InputIterator>
@@ -399,6 +402,7 @@
                 const allocator_type &a = allocator_type())
           : base(f, l, n, hf, eql, a)
         {
+ base.insert_equiv(f, l);
         }
 
     private:
@@ -469,18 +473,18 @@
 
         iterator insert(const value_type& obj)
         {
- return iterator(base.insert(obj));
+ return iterator(base.insert_equiv(obj));
         }
 
         iterator insert(const_iterator hint, const value_type& obj)
         {
- return iterator(base.insert(get(hint), obj));
+ return iterator(base.insert_equiv(get(hint), obj));
         }
 
         template <class InputIterator>
             void insert(InputIterator first, InputIterator last)
         {
- base.insert(first, last);
+ base.insert_equiv(first, last);
         }
 
         iterator erase(const_iterator position)

Modified: sandbox-branches/unordered-refactor/boost/unordered_set.hpp
==============================================================================
--- sandbox-branches/unordered-refactor/boost/unordered_set.hpp (original)
+++ sandbox-branches/unordered-refactor/boost/unordered_set.hpp 2007-12-07 07:30:27 EST (Fri, 07 Dec 2007)
@@ -72,6 +72,7 @@
             : base(f, l, boost::unordered_detail::default_initial_bucket_count,
                 hasher(), key_equal(), allocator_type())
         {
+ base.insert_unique(f, l);
         }
 
         template <class InputIterator>
@@ -81,6 +82,7 @@
                 const allocator_type &a = allocator_type())
             : base(f, l, n, hf, eql, a)
         {
+ base.insert_unique(f, l);
         }
 
     private:
@@ -152,18 +154,18 @@
         std::pair<iterator, bool> insert(const value_type& obj)
         {
             return boost::unordered_detail::pair_cast<iterator, bool>(
- base.insert(obj));
+ base.insert_unique(obj));
         }
 
         iterator insert(const_iterator hint, const value_type& obj)
         {
- return iterator(base.insert(get(hint), obj));
+ return iterator(base.insert_unique(get(hint), obj));
         }
 
         template <class InputIterator>
             void insert(InputIterator first, InputIterator last)
         {
- base.insert(first, last);
+ base.insert_unique(first, last);
         }
 
         iterator erase(const_iterator position)
@@ -357,6 +359,7 @@
             : base(f, l, boost::unordered_detail::default_initial_bucket_count,
                 hasher(), key_equal(), allocator_type())
         {
+ base.insert_equiv(f, l);
         }
 
         template <class InputIterator>
@@ -366,6 +369,7 @@
                 const allocator_type &a = allocator_type())
           : base(f, l, n, hf, eql, a)
         {
+ base.insert_equiv(f, l);
         }
 
     private:
@@ -436,18 +440,18 @@
 
         iterator insert(const value_type& obj)
         {
- return iterator(base.insert(obj));
+ return iterator(base.insert_equiv(obj));
         }
 
         iterator insert(const_iterator hint, const value_type& obj)
         {
- return iterator(base.insert(get(hint), obj));
+ return iterator(base.insert_equiv(get(hint), obj));
         }
 
         template <class InputIterator>
             void insert(InputIterator first, InputIterator last)
         {
- base.insert(first, last);
+ base.insert_equiv(first, last);
         }
 
         iterator erase(const_iterator position)


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