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 <unordered_map>
#include <iostream>
using namespace std;
int main () {
unordered_map<int, int> 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.