Skip to content
Related Articles

Related Articles

unordered_set max_bucket_count() function in C++ STL
  • Difficulty Level : Basic
  • Last Updated : 01 Oct, 2018

The unordered_set::max_bucket_count() is a built-in function in C++ STL which is used to find the maximum number of buckets that unordered_set can have.

This function returns the maximum number of buckets a system can have because of the constraints specified by the system and some limitations.

Parameters : This function does not take any parameters.

Syntax :

size_type max_bucket_count()

Where, size_type is an unsigned integral type.



Return Value : It returns the maximum number of buckets that the unordered_set container can have.

Exceptions : An Exception is thrown if any element comparison object throws exception.

Below program illustrate the unordered_set::max_bucket_count() function:




// CPP program to illustrate 
// unordered_set::max_bucket_count() function
  
#include <iostream>
#include <unordered_set>
using namespace std;
  
int main()
{
    unordered_set<int> Myset;
  
    Myset.insert(10);
    Myset.insert(20);
  
    // printing the contents
    cout<<"Elements : ";
    for (auto it = Myset.begin(); it != Myset.end(); ++it)
        cout << "[" << *it << "]";
    cout << endl;
  
    // inspect current parameters
    cout << "max_size : " << Myset.max_size() << endl;
    cout << "max_bucket_count() : " << Myset.max_bucket_count() << endl;
    cout << "max_load_factor() : " << Myset.max_load_factor() << endl;
      
    return 0;
}
Output:
Elements : [20][10]
max_size : 1152921504606846975
max_bucket_count() : 1152921504606846975
max_load_factor() : 1

Output :

[20][10]
max_size : 1152921504606846975
max_bucket_count() : 1152921504606846975
max_load_factor() : 1

Time Complexity: It takes constant time of complexity to perform an operation.

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :