Open In App

unordered_multimap max_load_factor() function in C++ STL

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The unordered_multimap::max_load_factor() is a built-in function in C++ STL which returns the maximum load factor of the unordered_multimap container. This function also provides with an option of setting the maximum load factor

  • Syntax (To return the maximum load factor) :
unordered_multimap_name.max_load_factor()

Parameters: The function does not accept any parameters. 

Return Value: It returns an integral values which denote the maximum load factor of the container. 

Below programs illustrates the above function: 

Program 1: 

C++
// C++ program to illustrate the
// unordered_multimap::max_load_factor()
#include <bits/stdc++.h>
using namespace std;

int main()
{

    // declaration
    unordered_multimap<int, int> sample1;

    // inserts key and element
    // in sample1
    sample1.insert({ 10, 100 });
    sample1.insert({ 50, 500 });

    // prints the max load factor
    cout << "The max load factor  of sample1: "
         << sample1.max_load_factor();

    cout << "\nKey and Elements of Sample1 are:";
    for (auto it = sample1.begin(); it != sample1.end(); it++) {
        cout << "{" << it->first << ", " << it->second << "} ";
    }

    return 0;
}

Output: 
The max load factor  of sample1: 1
Key and Elements of Sample1 are:{50, 500} {10, 100}

 
  • Syntax (To set the maximum load factor):
unordered_multimap_name.max_load_factor(N)

Parameters: The function accepts a single mandatory parameter N which specifies the load factor to be set. This N will be the maximum load factor of the container. 

Return Value: The function does not returns anything.

Below program illustrates the above function: 

C++
// C++ program to illustrate the
// unordered_multimap::max_load_factor(N)
#include <bits/stdc++.h>
using namespace std;

int main()
{

    // declaration
    unordered_multimap<int, int> sample1;

    // inserts key and element
    // in sample1
    sample1.insert({ 10, 100 });
    sample1.insert({ 50, 500 });

    cout << "The max load factor of elements of sample1: "
         << sample1.max_load_factor();

    // sets the load factor
    sample1.max_load_factor(100);

    cout << "\nThe max load factor of sample1 after setting it: "
         << sample1.max_load_factor();

    cout << "\nKey and Elements of Sample1 are:";
    for (auto it = sample1.begin(); it != sample1.end(); it++) {
        cout << "{" << it->first << ", " << it->second << "} ";
    }

    return 0;
}

Output: 
The max load factor of elements of sample1: 1
The max load factor of sample1 after setting it: 100
Key and Elements of Sample1 are:{50, 500} {10, 100}

 


 


Explore