std::unordered_set::bucket(3)

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

πŸ’… std::unordered_set::bucket πŸ’…

okay so welcome to the std::unordered_set::bucket(3) page from the C++ Standard Libary β€” yes bestie, that's the manual name, and we're about to make bucket indexes make sense. 🫢✨


🌸 NAME 🌸

std::unordered_set::bucket - std::unordered_set::bucket

It's giving β€œthe name section just names it twice,” and honestly? iconic. πŸ’…

✨ Synopsis ✨

okay so here's the synopsis, overloads and all:

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 previously obtained value). So don't be out here storing it forever, bestie. 😭
πŸ’€ The behavior is undefined if bucket_count() is zero. That's a hard no, fr fr.

πŸŽ€ 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 the whole vibe. πŸ‘‘

⭐ Complexity ⭐

Constant. ⚑

🧚 Notes 🧚

The feature-test macro is giving:

  • __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. 😭 not me crying over the missing example

πŸ‘‘ See also πŸ‘‘

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

πŸ—‚ Category πŸ—‚

  • * Todo no example

πŸ’– cute sign-off: source/version http://cppreference.com, date 2024.06.10, page std::unordered_set::bucket(3) β€” bye bestie, go slay those buckets! πŸŽ€βœ¨

πŸ“¦ where this page comes from