C ++ STL中的unordered_multimap rehash()函数
C++STL中的unordered_multimaprehash(N)函数将容器中的存储桶数设置为n或更大。如果n大于容器中当前的存储桶数,则将强制进行重新哈希处理。新的存储桶计数可以等于或大于n。如果n小于容器中当前的存储桶数,则该功能可能对存储桶数没有影响,也可能不会强制重新哈希。Rehash()不返回任何内容,并以n作为参数,该参数指定容器哈希表的最小存储桶数。
算法
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.
范例程式码
#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;
}输出结果
The size is: 2
Key and values are: {a, 20} {b, 10}热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便