unordered_multimap::rehash()
描述 (Description)
C ++函数std::unordered_multimap::rehash()将容器中的桶数设置为n或更多。
如果n大于容器中当前的桶数,则强制重新散列。 新的桶数可以等于或大于n 。
如果n低于容器中当前的桶数,则该功能可能对桶计数没有影响,并且可能不会强制重新散列。
声明 (Declaration)
以下是std :: unordered_multimap :: rehash()函数形式std :: unordered_map()头的声明。
C++11
void rehash(size_type n);
参数 (Parameters)
n - 新的桶数
返回值
没有
时间复杂
线性即平均情况下为O(n)。
在最坏的情况下,二次即O(n 2 )。
例子 (Example)
以下示例显示了std :: unordered_multimap :: rehash()函数的用法。
#include <iostream>
#include <unordered_map>
using namespace std;
int main (void) {
unordered_multimap<char, int> umm;
cout << "Initial bucket_count: " << umm.bucket_count() << endl;
umm.rehash(20);
cout << "Current bucket_count: " << umm.bucket_count() << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Initial bucket_count: 11
Current bucket_count: 23