max_bucket_count() Function in Unordered Set C++ STL
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++
// C++ program to illustrate the // unordered_set::max_bucket_count function #include <bits/stdc++.h> using namespace std; int main() { // declaration of unordered_set unordered_set< int > s; cout << "Size is : " << s.size() << endl; cout << "Max bucket count is : " << s.max_bucket_count() << endl; // insert elements 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++
// C++ program to illustrate the // unordered_set::max_bucket_count function #include <bits/stdc++.h> using namespace std; int main() { // declaration of unordered_set unordered_set<string> s; cout << "Size is : " << s.size() << endl; cout << "Max bucket count is : " << s.max_bucket_count() << endl; // insert elements 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
Please Login to comment...