PPL Assignment
IRM2015006
hash_search.cpp
Go to the documentation of this file.
1 #include "hash_search.h"
2 
4 {
5  for (auto boy : boyslist) {
6  hashTable[boy->name] = boy;
7  }
8 }
9 
10 HashSearch::HashSearch(std::vector<Boy*> boyslist)
11 {
12  this->boyslist = boyslist;
13 }
14 
15 void HashSearch::findGirlfriends (std::vector<std::string> namelist, Logger *logger)
16 {
17  makeHashTable();
18  for (auto name : namelist) {
19  auto searchResult = hashTable.find(name);
20  if (searchResult != hashTable.end()) {
21  Boy* boy = searchResult->second;
22  logger->log("found", name+" boy found in list", true);
23  if (boy->committed) {
24  logger->log("q7:exists", name+" is committed with "+boy->girlfriend->name, true);
25  } else {
26  logger->log("q7:single", name+" is single", true);
27  }
28  } else {
29  logger->log("not found", name, true);
30  }
31  }
32 }
bool committed
Definition: boy.h:32
HashSearch(std::vector< Boy * > boylist)
Definition: hash_search.cpp:10
void log(const std::string type, const std::string msg, bool print=false)
Definition: logger.cpp:27
Definition: logger.h:8
void makeHashTable()
Definition: hash_search.cpp:3
void findGirlfriends(std::vector< std::string > namelist, Logger *logger) override
Definition: hash_search.cpp:15
std::map< std::string, Boy * > hashTable
Definition: hash_search.h:12
std::vector< Boy * > boyslist
Definition: search.h:14
std::string name
Definition: girl.h:24
Definition: boy.h:20
Girl * girlfriend
Definition: boy.h:30