跳到主要内容

std::unordered_multimap max_bucket_count() 方法

// Const version only
size_type max_bucket_count() const;

由于系统或库实现的限制,返回容器能够容纳的最大桶数。

参数

(无)

返回值

最大桶数。

复杂度

常数 - O(1)

异常

(无)

示例

#include <iostream>
#include <unordered_map>

int main()
{
struct Ha { std::size_t operator()(long x) const { return std::hash<long>{}(x); }; };

auto c1 = std::unordered_multimap<char, long>{};
auto c2 = std::unordered_multimap<long, long>{};
auto c3 = std::unordered_multimap<long, long, std::hash<int>>{};
auto c4 = std::unordered_multimap<long, long, Ha>{};

std::cout
<< "Max bucket count of\n" << std::hex << std::showbase
<< "c1: " << c1.max_bucket_count() << '\n'
<< "c2: " << c2.max_bucket_count() << '\n'
<< "c3: " << c3.max_bucket_count() << '\n'
<< "c4: " << c4.max_bucket_count() << '\n'
;
}
可能输出
Max bucket count of
c1: 0xfffffffffffffff
c2: 0xfffffffffffffff
c3: 0xfffffffffffffff
c4: 0xaaaaaaaaaaaaaaa
本文来源于 此 CppReference 页面。可能为了改进或编辑偏好而进行了修改。点击“编辑此页面”查看此文档的所有更改。
悬停查看原始许可证。

std::unordered_multimap max_bucket_count() 方法

// Const version only
size_type max_bucket_count() const;

由于系统或库实现的限制,返回容器能够容纳的最大桶数。

参数

(无)

返回值

最大桶数。

复杂度

常数 - O(1)

异常

(无)

示例

#include <iostream>
#include <unordered_map>

int main()
{
struct Ha { std::size_t operator()(long x) const { return std::hash<long>{}(x); }; };

auto c1 = std::unordered_multimap<char, long>{};
auto c2 = std::unordered_multimap<long, long>{};
auto c3 = std::unordered_multimap<long, long, std::hash<int>>{};
auto c4 = std::unordered_multimap<long, long, Ha>{};

std::cout
<< "Max bucket count of\n" << std::hex << std::showbase
<< "c1: " << c1.max_bucket_count() << '\n'
<< "c2: " << c2.max_bucket_count() << '\n'
<< "c3: " << c3.max_bucket_count() << '\n'
<< "c4: " << c4.max_bucket_count() << '\n'
;
}
可能输出
Max bucket count of
c1: 0xfffffffffffffff
c2: 0xfffffffffffffff
c3: 0xfffffffffffffff
c4: 0xaaaaaaaaaaaaaaa
本文来源于 此 CppReference 页面。可能为了改进或编辑偏好而进行了修改。点击“编辑此页面”查看此文档的所有更改。
悬停查看原始许可证。