max_bucket_count() Function in Unordered Set C++ STL
Last Updated :
27 Nov, 2022
Prerequisite: unordered_set() in C++
The max_bucket_count() is the built-in function defined in C++ STL. This function returns the maximum number of buckets that the Unordered Set is able to hold.
Syntax:
unordered_set.max_bucket_count();
Parameters: It does not accept any parameter.
Return Type: Returns the maximum number of buckets.
Time Complexity: It takes constant time.
Let’s see with multiple examples:
Example:
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_set< int > s;
cout << "Size is : " << s.size() << endl;
cout << "Max bucket count is : " << s.max_bucket_count()
<< endl;
s.insert(5);
s.insert(10);
s.insert(15);
s.insert(20);
s.insert(25);
cout << "Size is : " << s.size() << endl;
cout << "Max bucket count is : " << s.max_bucket_count()
<< endl;
return 0;
}
|
Output
Size is : 0
Max bucket count is : 1152921504606846975
Size is : 5
Max bucket count is : 1152921504606846975
Example:
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_set<string> s;
cout << "Size is : " << s.size() << endl;
cout << "Max bucket count is : " << s.max_bucket_count()
<< endl;
s.insert( "geeks" );
s.insert( "for" );
s.insert( "geeks" );
cout << "Size is : " << s.size() << endl;
cout << "Max bucket count is : " << s.max_bucket_count()
<< endl;
return 0;
}
|
Output
Size is : 0
Max bucket count is : 768614336404564650
Size is : 2
Max bucket count is : 768614336404564650
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...