This is the mail archive of the
mailing list for the GCC project.
Re: [patch] [Bug libstdc++/61667] setting max_load_factor of unordered_map cause buckets shrink
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: François Dumont <frs dot dumont at gmail dot com>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 7 Aug 2014 20:07:19 +0100
- Subject: Re: [patch] [Bug libstdc++/61667] setting max_load_factor of unordered_map cause buckets shrink
- Authentication-results: sourceware.org; auth=none
- References: <53E3CBC7 dot 8090901 at gmail dot com>
On 07/08/14 20:56 +0200, François Dumont wrote:
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 <firstname.lastname@example.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 ?
OK for trunk.
If you're confident it's correct and safe then please also commit it
to the 4.9 branch - thanks.