C++ Standard Library C++ STL Library

C++ unordered_multimap - max_bucket_count() Function

The C++ unordered_multimap::max_bucket_count function returns the maximum number of buckets that the unordered_multimap can have. It returns the maximum potential number of buckets the unordered_multimap can have due to known system or library implementation limitations.

As an unordered_multimap is implemented using hash table where a bucket is a slot in the container's internal hash table to which elements are assigned based on the hash value of their key. The number of buckets directly influences the load_factor of the container's hash table. The container automatically increases the number of buckets to keep the load_factor below its max_load_factor which causes rehash whenever the number of buckets is increased.


size_type max_bucket_count() const noexcept;


No parameter is required.

Return Value

The maximum number of buckets in the unordered_multimap.

Time Complexity

Constant i.e, Θ(1).


In the example below, the unordered_multimap::max_bucket_count function is used to find out the maximum number of buckets that the unordered_multimap can have.

#include <iostream>
#include <unordered_map>
using namespace std;
int main (){
  unordered_multimap<string, string> uMMap;

  cout<<"Max size = "<<uMMap.max_size()<<"\n";
  cout<<"Max bucket count = "<<uMMap.max_bucket_count()<<"\n";
  cout<<"Max load factor = "<<uMMap.max_load_factor()<<"\n";

  return 0;

A possible output could be:

Max size = 115292150460684697
Max bucket count = 115292150460684697
Max load factor = 1

❮ C++ <unordered_map> Library