The unordered_map::load_factor() is a built-in function in C++ STL which returns the current load factor in the unordered_map container. The load factor is the ratio between the number of elements in the container (its size) and the number of buckets (bucket_count):
load_factor = size / bucket_count
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 automatically increases the number of buckets to keep the load factor below a specific threshold (its max_load_factor), by causing a rehash each time when an expansion is needed.
Parameter: The function does not accept any parameter.
Return Value: The function returns the current load factor.
The size is: 4 The bucket_count is: 7 The load_factor is: 0.571429 The size is: 5 The bucket_count is: 7 The load_factor is: 0.714286 The size is: 6 The bucket_count is: 7 The load_factor is: 0.857143
The size is: 4 The bucket_count is: 7 The load_factor is: 0.571429 The size is: 6 The bucket_count is: 7 The load_factor is: 0.857143 The size is: 7 The bucket_count is: 17 The load_factor is: 0.411765
- return statement in C/C++ with Examples
- HashMap computeIfPresent(key, BiFunction) method in Java with Examples
- BlockingQueue remainingCapacity() method in Java with examples
- HashMap replaceAll(BiFunction) method in Java with Examples
- HashMap getOrDefault(key, defaultValue) method in Java with Examples
- How to implement our own Vector Class in C++?
- Web Programming in C++
- Queue in Scala
- C++ Program to print an Array using Recursion
- Storage Classes in C++ with Examples
- How to wait for a promise to finish before returning the variable of a function?
- How to see the extensions loaded by PHP ?
- How to redirect a page to another page in HTML ?
- When to use self over $this in PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.