Module 9 · map and multimap: A Key Finds Its Value
Every map and multimap Operation, One by One, With Its Cost
Free with an accountReading
Bob's grocery till checks every scanned barcode against a map<int, int> of 100,000 prices, with prices[code]. He only wants to know "do we sell this?", and every answer is right. Yet after one day of scans, his map holds 200,000 codes, half of them at a price of 0. The cost lines below explain why, and the measurement at the end shows what it cost him.
Checking what this lesson needs for you…
What is inside Every map and multimap Operation, One by One, With Its Cost
- Making one: empty, from a list, from a range, or a copy
- operator[]: find the key, or add it
- at: a lookup that never adds
- insert and emplace: add only when the key is new
- try_emplace and insert_or_assign
- Seven calls on one tree
- find and count
- erase: by key, by iterator, or a range
- lower_bound, upper_bound and equal_range on the keys
- The element is pair<const K, V>, so the key is read-only
- Changing a key with extractIntermediate
- begin and rbegin: the smallest and the largest key
- size, empty, clear, swap, and comparing two maps
- A map in descending key order: greater<K>
- multimap: insert always adds
- multimap: equal_range, erase(k) and erase(it)
- Every cost in one table, and the measurement