Open In App

unordered_multimap max_bucket_count() function in C++ STL

Last Updated : 08 Aug, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

The unordered_multimap::max_bucket_count() is a built-in function in C++ STL which returns the maximum number of buckets that the unordered multimap container can have. This is the maximum it can have, it cannot exceed despite the collisions due to certain limitations on it.

Syntax:

unordered_multimap_name.max_bucket_count()

Parameter: The function does not accept anything.

Return Value: The function returns the maximum number of buckets possible.

Below programs illustrate the unordered_multimap::maximum_bucket_count() function:

Program 1:




// C++ program to illustrate the
// unordered_multimap::max_bucket_count()
#include <iostream>
#include <unordered_map>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multimap<char, char> sample;
  
    // inserts key and element
    sample.insert({ 'a', 'b' });
    sample.insert({ 'a', 'b' });
    sample.insert({ 'a', 'd' });
    sample.insert({ 'b', 'e' });
    sample.insert({ 'b', 'd' });
  
    cout << "The maximum bucket count is: "
         << sample.max_bucket_count();
  
    return 0;
}


Output:

The maximum bucket count is: 1152921504606846975

Program 2:




// C++ program to illustrate the
// unordered_multimap::max_bucket_count()
#include <iostream>
#include <unordered_map>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multimap<int, int> sample;
  
    // inserts key and element
    sample.insert({ 1, 2 });
    sample.insert({ 1, 3 });
    sample.insert({ 2, 4 });
    sample.insert({ 5, 8 });
    sample.insert({ 7, 10 });
  
    cout << "The maximum bucket count is: "
         << sample.max_bucket_count();
  
    return 0;
}


Output:

The maximum bucket count is: 1152921504606846975


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads