std::unordered_map::bucket(3)
π 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;
- Returns the index of the bucket for key
key. Elements (if any) with keys equivalent tokeyare always found in this bucket. - Returns the index of the bucket for key that compares equivalent to the value
x. Elements (if any) with keys that compare equivalent toxare always found in this bucket. This overload participates in overload resolution only ifHash::is_transparentandKeyEqual::is_transparentare valid and each denotes a type. This assumes that suchHashis callable with bothKandKeytype, and that theKeyEqualis transparent, which, together, allows calling this function without constructing an instance ofKey.
β οΈ The returned value is valid only for instances of the container for whichbucket_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
- 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