Learn C++ STL

Lesson 2 of 9 · unordered_set and unordered_map: Hashing, Collisions and the Anti-Hash Test

Module 10 · unordered_set and unordered_map: Hashing, Collisions and the Anti-Hash Test

Every unordered_set and unordered_map Operation, One by One, With Its Cost

Free with an accountReading

Bob keeps the shop's stock in an unordered_map<string, int>. To ask whether there is cake, he writes if (stock["cake"] == 0). The answer is right, and the map now holds one item more: cake, with 0. Every question about a missing item adds that item, and three more questions took this lesson's map from 3 items to 6. The sections below show why, and which calls ask without adding.

Checking what this lesson needs for you…

What is inside Every unordered_set and unordered_map Operation, One by One, With Its Cost

  1. Making one: empty, from a list, from a range, or with a bucket count
  2. insert and emplace, and the pair they return
  3. operator[]: find, or add a default
  4. at: read, or stop
  5. insert_or_assign and try_emplace
  6. find and count
  7. erase: by key, by iterator, or a range
  8. size, empty, clear and swap
  9. The walk, and == that ignores order
  10. The bucket interfaceIntermediate
  11. reserve and rehashIntermediate
  12. A hash for a pair keyIntermediate
  13. A weak hash piles keys into one bucketIntermediate
  14. unordered_multiset and unordered_multimap
  15. What the hash containers do not have
  16. Every cost in one table