unordered_map max_bucket_count in C++ STL

The unordered_map::max_bucket_count is a built in function in C++ STL. It returns the maximum number of buckets unordered_map container can have.

Syntax

unordered_map.max_bucket_count()

Parameters : It does not accept any parameter.



Return Type : Returns maximum number of buckets. Return type is an unsigned integer.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_map::max_bucket_count function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration of unordered_map
    unordered_map<int, int> sample;
  
    cout << "Size is : " << sample.size() << endl;
    cout << "Max bucket count is : " << sample.max_bucket_count() << endl;
  
    // insert elements
    sample.insert({ 5, 10 });
    sample.insert({ 10, 10 });
    sample.insert({ 15, 10 });
    sample.insert({ 20, 10 });
    sample.insert({ 21, 10 });
  
    cout << "Size is : " << sample.size() << endl;
    cout << "Max bucket count is : " << sample.max_bucket_count() << endl;
    return 0;
}

chevron_right


Output:

Size is : 0
Max bucket count is : 1152921504606846975
Size is : 5
Max bucket count is : 1152921504606846975

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_map::max_bucket_count function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration of unordered_map
    unordered_map<char, int> sample;
  
    cout << "Size is : " << sample.size() << endl;
    cout << "Max bucket count is : " << sample.max_bucket_count() << endl;
  
    // insert elements
    sample.insert({ 'a', 10 });
    sample.insert({ 'b', 10 });
    sample.insert({ 'c', 10 });
    sample.insert({ 'd', 10 });
    sample.insert({ 'e', 10 });
    sample.insert({ 'f', 10 });
  
    cout << "Size is : " << sample.size() << endl;
    cout << "Max bucket count is : " << sample.max_bucket_count() << endl;
    return 0;
}

chevron_right


Output:

Size is : 0
Max bucket count is : 1152921504606846975
Size is : 6
Max bucket count is : 1152921504606846975

Complexity: Its Complexity is constant.



My Personal Notes arrow_drop_up

All powers are within you You can do anything and everything Believe in that

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.