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

            Bug ID: 71181
           Summary: Reserving in unordered_map doesn't reserve enough
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: riad93 at mail dot ru
  Target Milestone: ---

Code:

#include <iostream>
#include <unordered_map>
using namespace std;

int main() {
        std::unordered_map<int, int> x;
        x.reserve(97);
        std::cout << x.bucket_count() << std::endl;
        for (int i = 0; i < 97; ++i) {
                x[i] = 1;
        }
        std::cout << x.bucket_count() << std::endl;
}

it prints for me

97
199

It doesn't contradict my reading of the Standard but still counterintuitive.
If user reserves smth, he would expect no rehashes

Note, probably any prime will do.

Generally, for each as far as I understand rehashing happens when 
new_size >= buckets_count (multiplied by load_factor which is 1)

I propose changing >= to >

Reply via email to