/* ------------------------------------------------------------------
   A "map" is storage stucture to store pairs

               (key, value)

   in a way that the data can be accessed QUICKLY using "key"

   Syntax to use a map:

                M[key] = value       (inserts/updates (key, value)
                M[key]               (returns the value)

   The map in C++ is a great for quickly looking up 
   a corresponding values by the key.

   A "map" is a.k.a. an "associative array"

   An array is great for looking up a corrponding value by
   an INTEGER key

   E.g:
         A[0] = 65   A[1] = 79   A[2] = 23 ...
   ----------------------------------------------------------------- */

#include <iostream>
#include <map>

using namespace std;

int main ()
{
   // Define a map that stores:
   //
   //     (key:string, value:int)
   map<string,int> myMap;
  
   // Adding (key -> value) to map   
   myMap["john"]=1;
   myMap["mary"]=2;
   myMap["jake"]=3;
   myMap["anne"]=4;
  
   cout << "myMap[\"john\"] = " << myMap["john"] << endl;
   cout << "myMap[\"mary\"] = " << myMap["mary"] << endl;
   cout << "myMap[\"jake\"] = " << myMap["jake"] << endl;
   cout << "myMap[\"anne\"] = " << myMap["anne"] << endl;
   cout << endl;

   myMap["john"]=99;   // Updates associated value

   cout << "myMap[\"john\"] = " << myMap["john"] << endl;
   cout << "myMap[\"mary\"] = " << myMap["mary"] << endl;
   cout << "myMap[\"jake\"] = " << myMap["jake"] << endl;
   cout << "myMap[\"anne\"] = " << myMap["anne"] << endl;
   cout << endl;

   // test if a key is in the map
   cout << "myMap.count(\"john\") = " << myMap.count("john") << endl;
   cout << "myMap.count(\"mary\") = " << myMap.count("mary") << endl;
   cout << "myMap.count(\"x\") = " << myMap.count("x") << endl;

   return 0;
}