std::unorde...bucket_count(3)
π NAME π
std::unordered_multiset::max_bucket_count β yes bestie, it's literally the same name twice, that's just how cppreference does it, we love a consistent queen π
So this page is the std::unordered_multiset::max_bucket_count page from the C++ Standard Library manual, section 3. And before you ask β the header says std::unorde...bucket_count(3) because the terminal clipped it, not because anything's wrong. She's fine. She's just long π
β¨ Synopsis β¨
size_type max_bucket_count() const; (since C++11)
Okay so this one's been serving since C++11 π
It returns the maximum number of buckets the container is able to hold, and why is that limited? Due to system or library implementation limitations. That's it. That's the whole vibe. It's not a "how many do I have" question (that's a different function, hold on), it's a "how many could I ever have" question π
πΈ Parameters πΈ
Um. None. (none). Nada. Zero. She takes no arguments, she's low maintenance, we stan π«Ά
β Return value β
The maximum number of buckets. That's the whole return value. Maximum. Number. Of. Buckets. π₯
π¦ Complexity π¦
Constant. O(1) baby, she's snappy, no cap πβ¨
π Example π
// Run this code
#include <iostream>
#include <unordered_set>
int main()
{
struct Ha { std::size_t operator()(long x) const { return std::hash<long>{}(x); }; };
auto c1 = std::unordered_multiset<char>{};
auto c2 = std::unordered_multiset<long>{};
auto c3 = std::unordered_multiset<long, std::hash<int>>{};
auto c4 = std::unordered_multiset<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'
;
}
So what's happening here β she makes four multisets with four different template parameter situations: one with char, one with long and the default hash, one with long but a different hash (std::hash<int>, iconique mismatch energy), and one with long and her own custom hasher Ha that just forwards to std::hash<long>. Then she prints all four max_bucket_count()s in hex with std::showbase so they look all 0x-y and gorgeous β¨
π Possible output π
Max bucket count of
c1: 0xfffffffffffffff
c2: 0xfffffffffffffff
c3: 0xfffffffffffffff
c4: 0xaaaaaaaaaaaaaaa
Notice how c4 is different?? That's the custom hasher doing her little thing β not me, that's just what the example shows π Read "possible" as possible, bestie, this is not a promise, it's a vibe check π₯
π See also π
bucket_countβ returns the number of buckets (public member function) β i.e. the actual count, not the theoretical max. Different girl, different job π
And that's the page!! πΈ This lil beauty comes to you from cppreference.com, dated 2024.06.10, and it lives under the name std::unorde...bucket_count(3) in the manual. Go forth and count your theoretical buckets, you absolute main character π§π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms