C++ Standard Library C++ STL Library

C++ unordered_multiset - max_bucket_count() Function



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

As an unordered_multiset 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. 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.

Syntax

size_type max_bucket_count() const noexcept;

Parameters

No parameter is required.

Return Value

The maximum number of buckets in the unordered_multiset.

Time Complexity

Constant i.e, Θ(1).

Example:

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

#include <iostream>
#include <unordered_set>
using namespace std;
 
int main (){
  unordered_multiset<int> uMSet;

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

  return 0;
}

A possible output could be:

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

❮ C++ <unordered_set> Library