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:
CPP
#include <iostream>
#include <unordered_set>
using namespace std;
int main()
{
unordered_set< int > uset = { 1, 5, 4, 7 };
cout << "Maximum load factor of uset: "
<< uset.max_load_factor()
<< endl;
cout << "Current load factor of uset: "
<< uset.load_factor();
}
|
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:
CPP
#include <iostream>
#include <unordered_set>
using namespace std;
int main()
{
unordered_set< int > uset = { 1, 5, 4, 7 };
uset.max_load_factor(0.5);
cout << "New Maximum load factor of uset: "
<< uset.max_load_factor()
<< endl;
cout << "Current load factor of uset1: "
<< uset.load_factor()
<< endl;
}
|
Output:
New Maximum load factor of uset: 0.5
Current load factor of uset1: 0.363636
Time complexity: O(1)
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Jun, 2023
Like Article
Save Article