unordered_set max_load_factor() in C++ STL

unordered_set::max_load_factor() is a function in C++ STL which returns(Or sets) the current maximum load factor of the unordered set container.

The load factor is the ratio between number of elements in the container and number of buckets(bucket_count). By default the maximum load factor of an unordered set container is set to 1.0 .

max_load_factor()

Syntax:

unordered_set_name.max_load_factor()

Return Value This method returns the current maximum load factor.

Below program illustrate the unordered_set::max_load_factor() method:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program o illustrate the
// unordered_set::max_load_factor() function
  
#include <iostream>
#include <unordered_set>
  
using namespace std;
  
int main()
{
    unordered_set<int> uset = { 1, 5, 4, 7 };
  
    // Get the max_load_factor of uset
    cout << "Maximum load factor of uset: "
         << uset.max_load_factor()
         << endl;
  
    // Now check the current load factor
    cout << "Current load factor of uset: "
         << uset.load_factor();
}

chevron_right


Output:

Maximum load factor of uset: 1
Current load factor of uset: 0.8

max_load_factor(float)

Syntax

unordered_set_name.max_load_factor(float z)

Parameter: This method takes a floating point number as parameter to which the max_load_factor is to be set.

Return Value: This method does not return any value .

Below program illustrate the unordered_set::max_load_factor(float) method:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_set::max_load_factor() function
  
#include <iostream>
#include <unordered_set>
using namespace std;
  
int main()
{
    unordered_set<int> uset = { 1, 5, 4, 7 };
  
    // Now set the max_load_factor as  0.5
    uset.max_load_factor(0.5);
  
    // Now get the new max_load_factor of uset
    cout << "New Maximum load factor of uset: "
         << uset.max_load_factor()
         << endl;
  
    // Check the new load factor
    cout << "Current load factor of uset1: "
         << uset.load_factor()
         << endl;
}

chevron_right


Output:

New Maximum load factor of uset: 0.5
Current load factor of uset1: 0.363636


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.




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.