#include #include #include using namespace std; #include "hmap.h" #include "bstmap.h" #include "ctimer.h" #include "tvector.h" /** * read a file, store all words in a vector, * then count occurrences of unique words * using a map to time different map implementations */ int main(int argc, char * argv[]) { ifstream input; string filename,s; int count; if (argc > 1) { filename = argv[1]; } else { cout << "filename "; cin >> filename; } input.open(filename.c_str()); tmap * map = new BSTMap(); // tmap * map = new HMap(49999); CTimer timer; tvector words; count = 0; while (input >> s) { words.push_back(s); count++; } timer.Start(); for(int k=0; k < words.size(); k++) { s = words[k]; if (map->contains(s)) { map->get(s)++; } else { map->insert(s,1); } } timer.Stop(); Iterator > *it = map->makeIterator(); for(it->Init(); it->HasMore(); it->Next()) { cout << it->Current().second << "\t" << it->Current().first << endl; } cout << timer.ElapsedTime() << " for " << count << endl; cout << "map size = " << map->size() << endl; return 0; }