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:
// 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;
} |
Output:
Current parameters are : max_load_factor= 1 load_factor= 0.571429 size of s1= 4 bucket_count= 7
Program 2:
// 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;
} |
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