The C++ function std::unordered_map::max_load_factor() returns the current maximum load factor for the unordered_map container.
The load factor is calculated as follows −
load_factor = um.size() / um.bucket_count()
Default value of max_load_factor is 1.0
The load factor influences the probability of collision in the hash table. The container uses the value of max_load_factor as the threshold that forces an increase in the number of buckets and thus causing a rehash.
Following is the declaration for std::unordered_map::max_load_factor() function form std::unordered_map header.
float max_load_factor() const noexcept;
None
Returns the maximum load factor.
This member function never throws exception.
Constant i.e. O(1)
The following example shows the usage of std::unordered_map::max_load_factor() function.
#include <iostream> #include <unordered_map> using namespace std; int main(void) { unordered_map<char, int> um; cout << "max_load_factor of unordered_map = " << um.max_load_factor() << endl; return 0; }
Let us compile and run the above program, this will produce the following result −
max_load_factor of unordered_map = 1