
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Unordered Multimap Rehash Function in C++ STL
The unordered_multimap rehash(N) function in C++ STL sets the number of buckets in the container to n or more. A rehash is forced if n is greater than the current number of buckets in the container. The new bucket count can either be equal to or greater than n. The function may have no effect on the bucket count and may not force a rehash if n is lower than the current number of buckets in the container. Rehash () returns nothing and take n as a parameter which specifies the minimum number of buckets for the container hash table.
Algorithm
Begin Declaring an empty map container m. Force the reahash() function to restrict number of bucket in a container to a minimum amount. Insert the key value pairs in the container atleast same as the minimum number of buckets. Print the elements in the map container. End.
Example Code
#include<iostream> #include <bits/stdc++.h> using namespace std; int main() { unordered_map<char, int> m; m.rehash(1); m.insert (pair<char, int>('b', 10)); m.insert (pair<char, int>('a', 20)); cout << "The size is: " << m.size(); cout << "\nKey and values are: "; for (auto it = m.begin(); it != m.end(); it++) { cout << "{" << it->first << ", " << it->second << "} "; } return 0; }
Output
The size is: 2 Key and values are: {a, 20} {b, 10}
Advertisements