unordered_map max_bucket_count in C++ STL
Last Updated :
14 Dec, 2018
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:
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map< int , int > sample;
cout << "Size is : " << sample.size() << endl;
cout << "Max bucket count is : " << sample.max_bucket_count() << endl;
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:
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map< char , int > sample;
cout << "Size is : " << sample.size() << endl;
cout << "Max bucket count is : " << sample.max_bucket_count() << endl;
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.
Share your thoughts in the comments
Please Login to comment...