The unorderedmultimap::loadfactor method is a predefined function in the C++ STL that provides the existing load factor value of the unorderedmultimap container. This load factor represents the proportion of the total elements in a container (its size) to the total count of buckets (bucketcount):
loadfactor = bucketcount / size
The load factor influences the likelihood of collision occurrence within a hash table, specifically referring to the chance of two entries landing in the same bucket. To manage this, the container adjusts the number of buckets dynamically by triggering a rehash whenever expansion becomes necessary. This process ensures that the load factor remains below a predefined threshold known as its maxloadfactor.
The ```
The value of the load balancer: 1
The max load factor of the sample after setting it: 300
The elements of the sample {40, 400} {10, 300}
### Syntax:
It has the following function:
unorderedmultimapname.maxloadfactor.
Functions: The function accepts no parameters.
Return Value: It offers a numerical value that signifies the maximum load factor of the container.
### Example:
// Program to implement
// unorderedmultimap::maxload_factor
include <bits/stdc++.h>
using namespace std;
int main
{
// main method
unordered_multimap<int, int> ex;
//inserting the key value elements
ex.insert({ 5, 500 });
ex.insert({ 6, 600 });
// display of maximum load factor
cout << "The max load factor value is: "
<< ex.maxloadfactor;
cout << "\nThe key values of ex are:";
for (auto ite = ex.begin; ite != ex.end; ite++) {
cout << "{" << ite->first << ", " << ite->second << "} ";
}
return 0;
}
Output:
The max load factor value is: 1
The key values of ex are:{6, 600} {5, 500}
### Syntax:
unorderedmultimapname.maxloadfactor(N)
The function takes in a single mandatory parameter, N, which specifies the load factor to be assigned. This value N signifies the maximum load factor of the container.
Return Value: Nothing is returned by the function
### Example:
// C++ Program to implement
// unorderedmultimap::maxload_factor(N)
include <bits/stdc++.h>
using namespace std;
int main
{
//variable declaration
unordered_multimap<int, int> ex1;
// inserting the keys
ex1.insert({ 10, 300 });
ex1.insert({ 40, 400 });
cout << "The value of the load balancer: "
<<ex1.maxloadfactor;
// sets the load factor
ex1.maxloadfactor(300);
cout << "\nThe max load factor of ex1 after setting it: "
<< ex1.maxloadfactor;
cout << "\nThe elements of the sample ";
for (auto ite = ex1.begin; ite != ex1.end; ite++) {
cout << "{" << ite->first << ", " << ite->second << "} ";
}
return 0;
}
Output:
The value of the load balancer: 1
The max load factor of the sample after setting it: 300
The elements of the sample {40, 400} {10, 300}