I don't know the reason why unordered_map's bucket size is 2^n

Viewed 112
    unordered_map<int, int> um;
    for (int i = 0; i < 100; i++) {
        um[i] = 1;
        cout << um.bucket_count() << endl;
    }

enter image description here Above are my test code and test result.

I found that bucket count grows like 8, 64, 512 in x86(also x64) debug mode on visual studio 2019 community environment.

Why bucket_count() is 2^n? I think it should be a prime number not a even number.

I hope your wise answers.

Thank you for reading.

0 Answers
Related