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

François Dumont frs.dumont@gmail.com
Thu Aug 7 18:56:00 GMT 2014


     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 

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
     * testsuite/23_containers/unordered_map/modifiers/61667.cc: New.

Tested under Linux x86_64.

Ok to commit ? In 4.9 branch also perhaps ?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 61667.patch
Type: text/x-patch
Size: 2325 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20140807/f455caaf/attachment.bin>

More information about the Libstdc++ mailing list