From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27077 invoked by alias); 2 Jul 2014 09:10:02 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 26756 invoked by uid 48); 2 Jul 2014 09:09:50 -0000 From: "tinrow at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/61667] New: setting max_load_factor of unordered_map cause buckets shrink Date: Wed, 02 Jul 2014 09:10:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: tinrow at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg00069.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61667 Bug ID: 61667 Summary: setting max_load_factor of unordered_map cause buckets shrink Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: tinrow at gmail dot com I want to build an unordered_map with at least 200000 initial buckets and set max load factor to 0.5. The bucket count shrinks to 2 during call to max_load_factor. Reproduce: $ cat 1.cpp #include #include using namespace std; int main () { unordered_map m(200000); cout << m.bucket_count() << endl; m.max_load_factor(0.5); cout << m.bucket_count() << endl; return 0; } $ g++ -std=c++11 1.cpp $ ./a.out 202409 2 $ g++ --version g++ (GCC) 4.8.2 In the ISO/IEC 14882:2011 standard, here is a possible "increase" but no "shrink". b.max_load_factor() float Returns a positive number that the container attempts to keep the load factor less than or equal to. The container automatically increases the number of buckets as necessary to keep the load factor below this number.