std::unordered_map::bucket(3)

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

πŸ’– std::unordered_map::bucket(3) πŸ’–

okay bestie, welcome to the std::unordered_map::bucket(3) page β€” it's from the C++ Standard Libary manual, and it's literally about asking an unordered_map which bucket a key belongs to. group-chat energy on, brain on πŸ’…


🌸 NAME 🌸

std::unordered_map::bucket β€” std::unordered_map::bucket. She said what she said, and honestly? iconic. πŸ’…


πŸ¦‹ Synopsis πŸ¦‹

size_type bucket( const Key& key ) const; (1) (since C++11)
template< typename K >                    (2) (since C++26)
size_type bucket( const K& x ) const;
  1. Returns the index of the bucket for key key. Elements (if any) with keys equivalent to key are always found in this bucket.
  2. Returns the index of the bucket for key that compares equivalent to the value x. Elements (if any) with keys that compare equivalent to x are always found in this bucket. This overload participates in overload resolution only if Hash::is_transparent and KeyEqual::is_transparent are valid and each denotes a type. This assumes that such Hash is callable with both K and Key type, and that the KeyEqual is transparent, which, together, allows calling this function without constructing an instance of Key.
⚠️ The returned value is valid only for instances of the container for which bucket_count() returns the same value (e.g., rehash() invalidates a previously obtained value). So don't treat it like a forever value, bestie 😭
πŸ’€ The behavior is undefined if bucket_count() is zero. Like, genuinely undefined β€” do not.

🌸 Parameters 🌸

  • key β€” the value of the key to examine.
  • x β€” a value of any type that can be transparently compared with a key.

⭐ Return value ⭐

Bucket index for the requested key. That's it, that's the tea. ✨


πŸ”₯ Complexity πŸ”₯

Constant. No cap, constant. πŸ’…


πŸŽ€ Notes πŸŽ€

Feature-test macro table vibes β€” here are all the bits, bestie:

  • Feature-test macro: __cpp_lib_associative_heterogeneous_insertion
  • Value: 202311L
  • Std: (C++26)
  • Feature: Heterogeneous overloads for the remaining member functions in ordered and unordered associative containers. (2)

🧚 Example 🧚

This section is incomplete β€” reason: no example. It's giving "left on read" 😭.


πŸ‘‘ See also πŸ‘‘

  • bucket_size β€” returns the number of elements in specific bucket (public member function).

🌈 Category 🌈

  • Todo no example

xoxo, your C++ bestie 🫢 β€” source: http://cppreference.com, version/date: 2024.06.10, page: std::unordered_map::bucket(3) βœ¨πŸ’–

πŸ“¦ where this page comes from