C++ Unordered_set 库 - rehash
描述
它用于将容器中的桶数设置为 n 或更多。
声明
以下是 std::unordered_set::rehash 的声明。
C++11
void rehash ( size_type n );
参数
n − n 是桶的最小数量。
返回值
none
异常
如果任何元素比较对象抛出异常,则抛出异常。
请注意,无效的参数会导致未定义的行为。
时间复杂度
固定的时间。
示例
以下示例显示了 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

