Learn C++ STL

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

Module 9 · map and multimap: A Key Finds Its Value

When to Use map, a Sorted vector of Pairs or a Plain Array, and When Not To

Free with an accountReading

Maria counts the marks of a 10,000,000-row exam log in a map<int, int>, although every mark is a whole number from 0 to 100. Kenji keeps his café's menu as a sorted vector of (name, price) pairs, and every new item goes in at its place. Both programs work. Amara asks each of them one question: what did the job need? This lesson is her answer, with a chart, a flowchart and three measurements.

Checking what this lesson needs for you…

What is inside When to Use map, a Sorted vector of Pairs or a Plain Array, and When Not To

  1. Five questions before you pick
  2. The comparison chart
  3. The decision flowchart
  4. Maria's marks, measured: an array against a map
  5. Kenji's items, measured: fill once, then a million lookups
  6. Kenji's items, measured: keys that keep arriving
  7. The honest default
  8. When not to use a map
  9. flat_map: a sorted vector that looks like a map
When to Use map, a Sorted vector of Pairs or a Plain Array, and When Not To | Learn C++ STL | Progsity