From 1c8ff48a21692295db876f3d15421d943d8b1684 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 20 Apr 2008 12:10:56 +0000 Subject: [PATCH] Merge in fix for the swap tests, and rename allocator. Merged revisions 44512-44515,44517-44536 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk ................ r44512 | danieljames | 2008-04-17 20:03:00 +0100 (Thu, 17 Apr 2008) | 11 lines Rename allocator.hpp. ................ r44536 | danieljames | 2008-04-18 11:27:50 +0100 (Fri, 18 Apr 2008) | 1 line Check that hash_table_impl::swap isn't swapping with itself - which is causing the buffered functions to be set with the same value twice, resulting in an assertion. ................ [SVN r44614] --- .../{allocator.hpp => allocator_helpers.hpp} | 0 include/boost/unordered/detail/hash_table.hpp | 2 +- .../boost/unordered/detail/hash_table_impl.hpp | 17 ++++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) rename include/boost/unordered/detail/{allocator.hpp => allocator_helpers.hpp} (100%) diff --git a/include/boost/unordered/detail/allocator.hpp b/include/boost/unordered/detail/allocator_helpers.hpp similarity index 100% rename from include/boost/unordered/detail/allocator.hpp rename to include/boost/unordered/detail/allocator_helpers.hpp diff --git a/include/boost/unordered/detail/hash_table.hpp b/include/boost/unordered/detail/hash_table.hpp index 12280ea3..9e06cc7d 100644 --- a/include/boost/unordered/detail/hash_table.hpp +++ b/include/boost/unordered/detail/hash_table.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/boost/unordered/detail/hash_table_impl.hpp b/include/boost/unordered/detail/hash_table_impl.hpp index 6e0b918f..cd6c1f16 100644 --- a/include/boost/unordered/detail/hash_table_impl.hpp +++ b/include/boost/unordered/detail/hash_table_impl.hpp @@ -694,7 +694,7 @@ namespace boost { BOOST_ASSERT(base == end.bucket_); split_group(end.node_); - + link_ptr ptr(base->next_); base->next_ = end.node_; @@ -1147,7 +1147,7 @@ namespace boost { // // Swap's behaviour when allocators aren't equal is in dispute, for // details see: - // + // // http://unordered.nfshost.com/doc/html/unordered/rationale.html#swapping_containers_with_unequal_allocators // // ---------------------------------------------------------------- @@ -1159,6 +1159,13 @@ namespace boost { void swap(BOOST_UNORDERED_TABLE& x) { + // The swap code can work when swapping a container with itself + // but it triggers an assertion in buffered_functions. + // At the moment, I'd rather leave that assertion in and add a + // check here, rather than remove the assertion. I might change + // this at a later date. + if(this == &x) return; + // These can throw, but they only affect the function objects // that aren't in use so it is strongly exception safe, via. // double buffering. @@ -1669,7 +1676,7 @@ namespace boost { size_type hash_value = hash_function()(k); bucket_ptr bucket = data_.bucket_from_hash(hash_value); link_ptr pos = find_iterator(bucket, k); - + if (BOOST_UNORDERED_BORLAND_BOOL(pos)) { // Found an existing key, return it (no throw). return std::pair( @@ -1744,7 +1751,7 @@ namespace boost { size_type hash_value = hash_function()(extract_key(*i)); bucket_ptr bucket = data_.bucket_from_hash(hash_value); link_ptr pos = find_iterator(bucket, extract_key(*i)); - + if (!BOOST_UNORDERED_BORLAND_BOOL(pos)) { // Doesn't already exist, add to bucket. // Side effects only in this block. @@ -1871,7 +1878,7 @@ namespace boost { }; // Iterators - + template class BOOST_UNORDERED_ITERATOR; template class BOOST_UNORDERED_CONST_ITERATOR; template class BOOST_UNORDERED_LOCAL_ITERATOR;