using namespace std;

#include <iostream>
#include <fstream>

#include "hashmap.h"

/**
 * Hash table example.  Uses a map implemented as a hash table to
 * read data from a file and display selected records.
 */

int main(int argc, char **argv)
{
  HashMap rpis;

  if (argc != 2)
    {
      cerr << "USAGE: " << argv[0] << " rpi-file" << endl;
      return 1;
    }

  ifstream infile(argv[1]);

  if (!infile)
    {
      cerr << argv[0] << ": error opening rpi-file " << argv[1] << endl;
      return 1;
    }

  double rpi;
  string teamName;

  // read rpi/team pairs and add them to the map
  while (infile >> rpi)
    {
      getline(infile, teamName);

      rpis.addItem(teamName, rpi);
    }

  // read teams from standard input and display their rpis
  while (getline(cin, teamName) && cin)
    {
      if (rpis.contains(teamName))
	cout << rpis.getValue(teamName) << endl;
      else
	cout << "not found" << endl;
    }
}

