public member function
<unordered_set>
std::unordered_multiset::max_load_factor get (1)float max_load_factor() const noexcept;set (2)
void max_load_factor ( float z );
Get or set maximum load factor
The first version (1) returns the current maximum load factor for the unordered_multiset container.The load factor is the ratio between the number of elements in the container (its size) and the number of buckets (bucket_count).
By default, unordered_multiset containers have a max_load_factor of 1.0.
The load factor influences the probability of collision in the hash table (i.e., the probability of two elements being located in the same bucket). The container uses the value of max_load_factor as the threshold that forces an increase in the number of buckets (and thus causing a rehash).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// unordered_multiset::max_load_factor
#include <iostream>
#include <string>
#include <unordered_set>
int main ()
{
std::unordered_multiset<std::string> myums =
{"human","klingon","vulcan","vulcan","andorian","vulcan"};
std::cout << "current max_load_factor: " << myums.max_load_factor() << std::endl;
std::cout << "current size: " << myums.size() << std::endl;
std::cout << "current bucket_count: " << myums.bucket_count() << std::endl;
std::cout << "current load_factor: " << myums.load_factor() << std::endl;
float z = myums.max_load_factor();
myums.max_load_factor ( z / 2.0 );
std::cout << "[max_load_factor halved]" << std::endl;
std::cout << "new max_load_factor: " << myums.max_load_factor() << std::endl;
std::cout << "new size: " << myums.size() << std::endl;
std::cout << "new bucket_count: " << myums.bucket_count() << std::endl;
std::cout << "new load_factor: " << myums.load_factor() << std::endl;
return 0;
}
current max_load_factor: 1 current size: 6 current bucket_count: 7 current load_factor: 0.857143 [max_load_factor halved] new max_load_factor: 0.5 new size: 6 new bucket_count: 13 new load_factor: 0.461538
A rehash is forced if the new container max_load_factor is set below the current load_factor.
References to elements in the unordered_multiset container remain valid in all cases, even after a rehash.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4