目录

rehash

描述 (Description)

它用于将容器中的桶数设置为n或更多。

声明 (Declaration)

以下是std :: unordered_set :: rehash的声明。

C++11

void rehash ( size_type n );

参数 (Parameters)

n - n是桶的最小数量。

返回值

没有

异常 (Exceptions)

如果任何元素比较对象抛出异常,则抛出异常。

请注意,无效参数会导致未定义的行为。

时间复杂

恒定时间。

例子 (Example)

以下示例显示了std :: unordered_set :: max_load_factor的用法。

#include <iostream>
#include <string>
#include <unordered_set>
int main () {
   std::unordered_set<std::string> myset;
   myset.rehash(12);
   myset.insert("android");
   myset.insert("java");
   myset.insert("html");
   myset.insert("css");
   myset.insert("javascript");
   std::cout << "current bucket_count: " << myset.bucket_count() << std::endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

current bucket_count: 13
↑回到顶部↑
WIKI教程 @2018