std::unordered_set::rehash(3)
π NAME π
std::unordered_set::rehash β bestie, it's the glow-up for your bucket count β¨
okay so real quick, the manual name is std::unordered_set::rehash and it lives in the C++ Standard Libary, and yes we are about to make your hash table move different π
β¨ Synopsis β¨
void rehash( size_type count ); (since C++11)
So what it does is it changes the number of buckets to some value n that is not less than count and satisfies
n >= size() / max_load_factor()
and then it rehashes the container β which is just a fancy way of saying it puts the elements into appropriate buckets considering that the total number of buckets has changed. like, everybody gets re-seated at the function, no cap π
πΈ Parameters πΈ
countβ the lower bound for the new number of buckets. it's a floor, not a demand, iykyk π¦
π«Ά Return value π«Ά
(none) β it gives you nothing back, it just does the thing. main character energy honestly π
π₯ Complexity π₯
- Average case: linear in the size of the container π
- Worst case: quadratic π
so like, usually slay, but worst case it's giving slow. plan accordingly bestie π
π Notes π
rehash(0) may be used to force an unconditional rehash β for real, zero is a valid move here π
like, say you temporarily increased max_load_factor() and that suspended automatic rehashing? this is your little "ok we're back, rehash everything now" button. iconic β¨
π§ See also π§
reserveβ reserves space for at least the specified number of elements and regenerates the hash table (public member function) π
and that's the whole vibe check, bestie π¦ this page was brought to you by http://cppreference.com (the source, ily) and it's dated 2024.06.10 πΈ go forth and rehash responsibly, mwah π
π¦ 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