From 4ac8a45a34076e0d8310c6da737b70710ce02158 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 5 Oct 2017 10:54:22 +0100 Subject: [PATCH] The max_load issue was fixed in the standard ages ago --- doc/buckets.qbk | 7 ++----- include/boost/unordered/detail/implementation.hpp | 7 +++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/doc/buckets.qbk b/doc/buckets.qbk index 6baa64e7..54d2bc94 100644 --- a/doc/buckets.qbk +++ b/doc/buckets.qbk @@ -160,12 +160,9 @@ the expensive rehashing out of the way and let you store iterators, safe in the knowledge that they won't be invalidated. If you are inserting `n` elements into container `x`, you could first call: - x.rehash((x.size() + n) / x.max_load_factor() + 1); + x.rehash((x.size() + n) / x.max_load_factor()); [blurb Note: `rehash`'s argument is the minimum number of buckets, not the -number of elements, which is why the new size is divided by the maximum load factor. The -`+ 1` guarantees there is no invalidation; without it, reallocation could occur -if the number of bucket exactly divides the target size, since the container is -allowed to rehash when the load factor is equal to the maximum load factor.] +number of elements, which is why the new size is divided by the maximum load factor.] [endsect] diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index 8f70db7f..4d676f42 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -360,9 +360,8 @@ namespace boost { std::size_t num_buckets = boost::unordered::detail::default_bucket_count) { - // TODO: Why +1? return (std::max)( - boost::unordered::detail::insert_size(i, j) + 1, num_buckets); + boost::unordered::detail::insert_size(i, j), num_buckets); } ////////////////////////////////////////////////////////////////////////// @@ -3309,7 +3308,7 @@ namespace boost { mlf_ = x.mlf_; recalculate_max_load(); - if (x.size_ >= max_load_) { + if (x.size_ > max_load_) { create_buckets(min_buckets_for_size(x.size_)); } else if (size_) { clear_buckets(); @@ -3384,7 +3383,7 @@ namespace boost { mlf_ = x.mlf_; recalculate_max_load(); - if (x.size_ >= max_load_) { + if (x.size_ > max_load_) { create_buckets(min_buckets_for_size(x.size_)); } else if (size_) { clear_buckets();