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

fdumont at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jul 23 20:07:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61667

François Dumont <fdumont at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |fdumont at gcc dot gnu.org

--- Comment #2 from François Dumont <fdumont at gcc dot gnu.org> ---
I just wanted to give a way to shrink unordered containers representation
through a rehash call as long as it was Standard compliant, and it is I think.
Even the classic copy and swap won't work on this type of container. Having it
shrink on call to max_load_factor was also plan but I must confess that in the
provided code it is quite inconvenient.

An easy workaround is to call m.reserve(200000) after the call to
max_load_factor.

I can change the code to limit the shink behavior to rehash calls or I can
change it to do as you propose Jonathan allowing no shrinking except by
rebuilding a new instance from an iterator range and then swap.


More information about the Gcc-bugs mailing list