Open In App

unordered_map max_bucket_count in C++ STL

Last Updated : 14 Dec, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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:




// 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;
}


Output:

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

Example-2:




// 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;
}


Output:

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

Complexity: Its Complexity is constant.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads