C++ Unordered_multimap 库 - bucket_count() 函数
描述
C++ 函数 std::unordered_multimap::bucket_count() 返回 unordered_multimap 容器中存在的桶数。
声明
以下是 std::unordered_multimap::bucket_count() 函数形式 std::unordered_map() 头的声明。
C++11
size_type bucket_count() const noexcept;
参数
None
返回值
返回 unordered_multimap 中存在的桶的总数。
异常
该成员函数不会抛出异常。
时间复杂度
常数,即 O(1)
示例
以下示例显示了 std::unordered_multimap::bucket_count() 函数的用法。
#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) {
unordered_multimap<char, int> umm = {
{'a', 1},
{'b', 2},
{'c', 3},
{'d', 4},
{'e', 5}
};
cout << "Number of buckets = " << umm.bucket_count() << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Number of buckets = 11

