The unordered_multiset::rehash() is a built-in function in C++ STL which sets the number of buckets in the container to N or more. If N is greater than the current number of buckets in the container (bucket_count), a rehash is forced.
The new bucket count can either be equal or greater than N. If n is lower than the current number of buckets in the container (bucket_count), the function may have no effect on the bucket count and may not force a rehash.
A rehash is the reconstruction of the hash table: All the elements in the container are rearranged according to their hash value into the new set of buckets. This may alter the order of iteration of elements within the container, although the relative order of the elements with equivalent keys is preserved. Rehashes are automatically performed by the container whenever its load factor is going to surpass its max_load_factor in an operation. By calling rehash to reserve a certain minimum amount of buckets in the hash table, we avoid the multiple rehashes that the expansion of the container may cause.
Parameters: The function accepts only one parameter as listed below:
- count: It is the new number of buckets.
Return Value: none(void type function)
Below programs illustrate the above method:
Initial values are: 3 1 2 initial parameters are: bucketcount() = 7 load factor = 0.428571 Max_load_factor = 1 final parameters are: bucketcount() = 211 load factor = 0.014218 Max_load_factor = 1
Initial values are: c a b initial parameters are: bucketcount() = 7 load factor = 0.428571 Max_load_factor = 1 final parameters are: bucketcount() = 211 load factor = 0.014218 Max_load_factor = 1
- unordered_set rehash() function in C++ STL
- unordered_multimap rehash() function in C++ STL
- unordered_map rehash in C++ STL
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- exp() function C++
- log() function in C++
- div() function in C++
- fma() function in C++
- isinf() function in C++
- mbsrtowcs() function in C/C++
- isunordered() function in C++
- lldiv() function in C++ STL
- Modulus function in C++ STL
- transform_inclusive_scan() function in C++
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.