The unordered_map::max_load_factor in C++ STL is a built in function which is used to get and set maximum load factor in unordered_map. Load factor is the ratio between number of elements in container and number of buckets. By default unordered_map max_load factor is 1.0.
Syntax: There are two type of functions for max_load_factor.
- float max_load_factor()
- void max_load_factor(float new_size)
Return type: Only first version returns max_load_factor.
Parameter: Only second version accept new size.
- First version return maximum load factor.
- Second version sets new load factor.
Current size is : 6 Current load factor is : 0.857143 Current Max load factor is 1 Current size is : 6 Current load factor is : 0.857143 Current Max load factor is 2.5
Current size is : 4 Current load factor is : 0.571429 Current Max load factor is 1 Current size is : 4 Current load factor is : 0.571429 Current Max load factor is 2.5
Complexity : O(1).
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- std::sort() in C++ STL
- unordered_map in C++ STL
- fill() and fill_n() functions in C++ STL
- std::transform() in C++ STL (Perform an operation on all elements)
- Array algorithms in C++ STL (all_of, any_of, none_of, copy_n and iota)
- Iterators in C++ STL
- accumulate() and partial_sum() in C++ STL : numeric header
- std::partition in C++ STL
- Merge operations using STL in C++ | merge(), includes(), set_union(), set_intersection(), set_difference(), ., inplace_merge,
- Heap in C++ STL | make_heap(), push_heap(), pop_heap(), sort_heap(), is_heap, is_heap_until()
- numeric header in C++ STL | Set 2 (adjacent_difference(), inner_product() and iota())
- Counts of distinct consecutive sub-string of length two using C++ STL
- Delete elements in C++ STL list
- Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)
- Descending order in Map and Multimap of C++ STL
- The C++ Standard Template Library (STL)
- Pair in C++ Standard Template Library (STL)
- Vector in C++ STL
- Modifiers for Vector in C++ STL
- List in C++ Standard Template Library (STL)
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.