Javatpoint Logo
Javatpoint Logo

unordered_multimap rehash() function in C++

The unordered_multimap rehash(N) function in C++ increases the number of elements in the container to n or more. If n is more than the number of elements in the container, a rehash is required. The new element count might be either equal to or more than n. If n is less than the present number of elements in the container, the function's result may not affect the bucket count and will not require a rehash function. Rehash() returns nothing and takes n as an argument, which determines the lowest possible number of buckets for the frame of the hash table.

A rehash is the rebuilding of the hash table. All the components in the container are reorganized into a new set of buckets based on their hash value. It may change the order in which elements within the container are iterated, but the relative order of elements with equivalent keys is retained. Rehashes are carried out automatically by the container's memory whenever its load factor in an operation exceeds its max_load_factor. We prevent several rehashes caused by container expansion by executing rehash to reserve a particular minimum number of buckets in the hash table.

Syntax:

It has the following syntax:

Parameters: The function receives a single important argument, N, which determines the minimum number of buckets for the container's hash table.

Return Value: Nothing is returned by the function.

Algorithm

Example 1:

Let's take an example to illustrate the use of unordered_multimap rehash(N) function in C++.

Output:

The size of the sample s1 is: 2
key value of sample s1 is:{40, 800} {20, 300} 

The size of the sample s2 is:3
key value of sample s1 is:{200, 350} {20, 700} {40, 400} 

Example 2:

Let's take another example to illustrate the use of unordered_multimap rehash(N) function in C++.

Output:

The sample s2 size is: 2
The values of sample s2:{f, F} {b, B} 
The sample s2 size is :3
The values of sample s2::{l, L} {m, M} {d, D} 






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA