C++ STL 中的 unordered_multiset max_bucket_count() 函数
unordered_multiset::max_bucket_count() 是 C++ STL 中的一个内置函数,它返回无序多重集合容器可以拥有的最大桶数。这是它最多拥有的数量,尽管由于其某些限制而导致的冲突,它也不能超过这个数量。
语法 :
unordered_multiset_name.max_bucket_count()
参数 :该函数不接受任何参数。
返回值 :该函数返回可能的最大桶数。
下面的程序说明了 unordered_multiset::maximum_bucket_count() 函数:
程序1 :
// C++ program to illustrate the
// unordered_multiset::maximum_bucket_count() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// 声明
unordered_multiset<char> sample;
// 插入元素
sample.insert('a');
sample.insert('b');
sample.insert('b');
sample.insert('b');
sample.insert('z');
cout << "最大桶数为:" <<
sample.max_bucket_count();
return 0;
}
最大桶数为:1152921504606846975
程序2 :
// C++ program to illustrate the
// unordered_multiset::maximum_bucket_count() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// 声明
unordered_multiset<int> sample;
// 插入元素
sample.insert(1);
sample.insert(2);
sample.insert(2);
sample.insert(4);
sample.insert(4);
cout << "最大桶数为:"
<< sample.max_bucket_count();
return 0;
}
最大桶数为:1152921504606846975