unordered_set max_bucket_count() function in C++ STL

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.



My Personal Notes arrow_drop_up

2nd year student of Information Technology JADAVPUR UNIVERSITY

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.