C++ Unordered_multimap Library - load_factor() Function


Advertisements

Description

The C++ function std::unordered_multimap::load_factor() returns the current load factor of the unordered_multimap container.

The load factor is calculated as follows −

load_factor = umm.size() / umm.bucket_count();

Declaration

Following is the declaration for std::unordered_multimap::load_factor() function form std::unordered_map() header.

C++11

float load_factor() const noexcept;

Parameters

None

Return value

Returns load factor.

Exceptions

This member function never throws exception.

Time complexity

Constant i.e.O(1)

Example

The following example shows the usage of std::unordered_multimap::load_factor() function.

#include <iostream>
#include <unordered_map>

using namespace std;

int main(void) {
   unordered_multimap<char, int> umm = {
            {'a', 1},
            {'b', 2},
            {'c', 3},
            {'d', 4},
            };

   cout << "Load factor = " << umm.load_factor() << endl;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

Load factor = 0.8
unordered_map.htm
Advertisements