This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] [Bug libstdc++/61667] setting max_load_factor of unordered_map cause buckets shrink


On 07/08/14 20:56 +0200, François Dumont wrote:
Hi

I took a closer look to this PR and there is indeed a problem. My comment on the PR is incorrect, I thought the problem was in the rehash method but is it not. It is indeed wrong to shrink buckets when invoking max_load_factor, it reverts the effect of preallocating buckets before a big insertion.

The fix is simple. A call to _M_need_rehash rather than _M_bkt_for_elements/_M_next_bkt automatically initialize the rehash policy considering the current number of elements and buckets in the container.

2014-08-07  François Dumont <fdumont@gcc.gnu.org>

   * include/bits/hashtable.h (_Hashtable<>::__rehash_policy): Use
   _M_need_rehash to initialize the rehash policy and check if a rehash is
   needed.
   * testsuite/23_containers/unordered_map/modifiers/61667.cc: New.

Tested under Linux x86_64.

Ok to commit ? In 4.9 branch also perhaps ?

OK for trunk.

If you're confident it's correct and safe then please also commit it
to the 4.9 branch - thanks.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]