std::unorde...map::reserve(3)

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

okay bestie, buckle up: this is std::unorde...map::reserve(3) from the C++ Standard Libary manual πŸ’…βœ¨ (yes, β€œLibary,” she said what she said πŸŽ€).

πŸ’– NAME πŸ’–

std::unordered_map::reserve β€” std::unordered_map::reserve (it’s giving β€œsame name, same energy,” and honestly? iconic πŸ’€).

✨ Synopsis ✨

void reserve( size_type count );  (since C++11)

okay so what does it actually do? It sets the number of buckets to the number needed to accommodate at least count elements without exceeding maximum load factor, and it rehashes the container β€” i.e. it puts the elements into appropriate buckets considering that the total number of buckets has changed. Effectively calls rehash(std::ceil(count / max_load_factor())). no cap, that’s the whole vibe πŸ¦‹

🌸 Parameters 🌸

  • count β€” the new capacity of the container, bestie. That’s the number we’re reserving room for.

πŸŽ€ Return value πŸŽ€

(none) β€” literally nothing comes back. void behavior, no notes, periodt πŸ’….

πŸ¦‹ Complexity πŸ¦‹

Average case is linear in the size of the container, but worst case? quadratic 😭. So like, don’t get caught sleeping on the worst case, okay?

🌈 See also 🌈

  • rehash β€” reserves at least the specified number of buckets and regenerates the hash table (public member function). bestie behavior, fr fr 🫢.

xoxo, source: http://cppreference.com, dated 2024.06.10 β€” from the std::unorde...map::reserve(3) page in the C++ Standard Libary manual πŸ’–πŸ§š

πŸ“¦ where this page comes from