std::unorde...ucket_count(3)
π std::unordered_map::max_bucket_count π
okay bestie so this page lives in the C++ Standard Library manual (you already knew that, you're iconic) β and today's main character is std::unordered_map::max_bucket_count π
No cap, this one is a lil cutie. Let's get into it β¨
πΈ NAME πΈ
std::unordered_map::max_bucket_count β like, literally std::unordered_map::max_bucket_count π
π¦ Synopsis π¦
The β¨vibeβ¨ is:
size_type max_bucket_count() const; (since C++11)
So what it does is β it hands you back the maximum number of buckets the container can even hold, because of system or library implementation limitations. That's it, that's the whole personality π«Ά
ngl "system or library implementation limitations" is doing a lot of heavy lifting there β it just means your computer / your stdlib says "bestie this is my ceiling" π
π Parameters π
(none) β she takes nothing, she needs nothing, she is unbothered π
β Return value β
The maximum number of buckets. That's the whole thing. Slay π
π§ Complexity π§
Constant. Fast. Instant. No drama, no waiting, we love a low-effort queen π
π Example π
Run this code, fr fr:
#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_map<char, long>{};
auto c2 = std::unordered_map<long, long>{};
auto c3 = std::unordered_map<long, long, std::hash<int>>{};
auto c4 = std::unordered_map<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'
;
}
Like β four whole maps, four different template setups, all just flexing their bucket ceilings π and yes, we're printing in hex with std::showbase because we're classy like that π
Possible output:
Max bucket count of
c1: 0xfffffffffffffff
c2: 0xfffffffffffffff
c3: 0xfffffffffffffff
c4: 0xaaaaaaaaaaaaaaa
Not c4 pulling up with a completely different number and zero explanation π β anyway, that's what you get, taste the rainbow π
π₯ See also π₯
bucket_countβ returns the number of buckets (public member function) β like her chiller, more chillaxed cousin, iykyk π
okay that's the whole page, love u, go write some hash maps π β this one was published on cppreference over at http://cppreference.com, dated 2024.06.10, and it's the std::unorde...ucket_count(3) page in the C++ Standard Libary manual. mwah, see u in the next one πβ¨π¦
π¦ 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