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
- Making one: empty, from a list, from a range, or with a bucket count
- insert and emplace, and the pair they return
- operator[]: find, or add a default
- at: read, or stop
- insert_or_assign and try_emplace
- find and count
- erase: by key, by iterator, or a range
- size, empty, clear and swap
- The walk, and == that ignores order
- The bucket interfaceIntermediate
- reserve and rehashIntermediate
- A hash for a pair keyIntermediate
- A weak hash piles keys into one bucketIntermediate
- unordered_multiset and unordered_multimap
- What the hash containers do not have
- Every cost in one table