std::unorde...bucket_count(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ NAME πŸŽ€

std::unordered_multimap::max_bucket_count β€” std::unordered_multimap::max_bucket_count (the name is literally the same twice, and honestly? iconic πŸ’…)

okay so bestie, you’re on the std::unorde...bucket_count(3) page from the C++ Standard Libary β€” yes that’s the manual name, and we’re about to make max bucket count make sense ✨


✨ Synopsis ✨

size_type max_bucket_count() const;  (since C++11)

Since C++11, this member function is right there giving you the maximum number of buckets the container can hold because of system or library implementation limitations. It’s not β€œinfinite buckets era,” it’s β€œsystem/library says this is the cap” era 😭.

🧸 Parameters 🧸

(none) β€” literally no parameters. She takes nothing, she returns the max, she leaves πŸ’€

🌸 Return value 🌸

Maximum number of buckets. That’s the whole return value, no extra lore πŸ‘‘

⚑ Complexity ⚑

Constant. That’s it β€” constant complexity, no extra lore πŸ”₯

πŸ“ Example πŸ“

// Run this code

#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'
        ;
}

Possible output:

Max bucket count of
c1: 0xfffffffffffffff
c2: 0xfffffffffffffff
c3: 0xfffffffffffffff
c4: 0xaaaaaaaaaaaaaaa

πŸ¦‹ See also πŸ¦‹

  • bucket_count β€” returns the number of buckets (public member function) πŸ’–

source/version: cppreference.com ✨ date: 2024.06.10 🫢 manual tag: std::unorde...bucket_count(3) πŸ’œ

πŸ“¦ where this page comes from