Learn C++ STL

Lesson 2 of 9 · map and multimap: A Key Finds Its Value

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

  1. Making one: empty, from a list, from a range, or a copy
  2. operator[]: find the key, or add it
  3. at: a lookup that never adds
  4. insert and emplace: add only when the key is new
  5. try_emplace and insert_or_assign
  6. Seven calls on one tree
  7. find and count
  8. erase: by key, by iterator, or a range
  9. lower_bound, upper_bound and equal_range on the keys
  10. The element is pair<const K, V>, so the key is read-only
  11. Changing a key with extractIntermediate
  12. begin and rbegin: the smallest and the largest key
  13. size, empty, clear, swap, and comparing two maps
  14. A map in descending key order: greater<K>
  15. multimap: insert always adds
  16. multimap: equal_range, erase(k) and erase(it)
  17. Every cost in one table, and the measurement
Every map and multimap Operation, One by One, With Its Cost | Learn C++ STL | Progsity