unordered_multiset max_load_factor() in C++ STL

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

Syntax (To return the maximum load factor):

unordered_multiset_name.max_load_factor()

Parameters: The function does not accept any parameters.



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

Below programs illustrate the unordered_multiset::max_load_factor() function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// unordered_multiset::max_load_factor()
#include <iostream>
#include <unordered_set>
  
using namespace std;
  
int main()
{
    // declaration
    unordered_multiset<char> s1;
    s1 = { 'a', 'b', 'c', 'd' };
  
    // displaying initial parameters
    cout << "Current parameters are :\n";
    cout << "max_load_factor= " << s1.max_load_factor() << endl;
    cout << "load_factor= " << s1.load_factor() << endl;
    cout << "size of s1= " << s1.size() << endl;
    cout << "bucket_count= " << s1.bucket_count() << endl;
  
    return 0;
}

chevron_right


Output:

Current parameters are :
max_load_factor= 1
load_factor= 0.571429
size of s1= 4
bucket_count= 7

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to illustrate
// unordered_multiset::max_load_factor()
#include <iostream>
#include <unordered_set>
   
using namespace std;
   
int main()
{
    // declaration
    unordered_multiset<char> s1;
    s1 = { 'a', 'b', 'c', 'd' };
   
    // displaying initial parameters
    cout << "Current parameters are :\n";
    cout << "max_load_factor= " << s1.max_load_factor() << endl;
    cout << "load_factor= " << s1.load_factor() << endl;
    cout << "size of s1= " << s1.size() << endl;
    cout << "bucket_count= " << s1.bucket_count() << endl;
   
    // changing max_load_factor
    s1.max_load_factor(0.5);
    cout << endl;
   
    // displaying final parameters
    cout << "Final parameters are :\n";
    cout << "max_load_factor= " << s1.max_load_factor() << endl;
    cout << "load_factor= " << s1.load_factor() << endl;
    cout << "size of s1= " << s1.size() << endl;
    cout << "bucket_count= " << s1.bucket_count() << endl;
   
    return 0;
}

chevron_right


Output:

Current parameters are :
max_load_factor= 1
load_factor= 0.571429
size of s1= 4
bucket_count= 7

Final parameters are :
max_load_factor= 0.5
load_factor= 0.235294
size of s1= 4
bucket_count= 17


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : ManasChhabra2



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.