#include #include #include using namespace std; size_t data_hash(string s){ size_t sum = 1; for(auto c : s) sum *= c; return sum; } #include "hash_table.h" int main(int argc, char ** argv){ if(argc < 2){ cout << "Usage: " << argv[0] << " filename\n"; return 1; } HashTable dictionary; ifstream dfile; dfile.open("/usr/share/dict/american-english"); string dword; while(dfile >> dword){ for(int i = 0; i < dword.length(); i++) dword[i] = tolower(dword[i]); dictionary[dword] = 1; } dfile.close(); cout << "Dictionary has " << dictionary.get_items() << " words\n"; HashTable lwords; ifstream lfile; lfile.open(argv[1]); string lword; while(lfile >> lword){ for(int i = 0; i < lword.length(); i++) lword[i] = tolower(lword[i]); if(dictionary.contains(lword)) if(lwords.contains(lword)) lwords[lword]++; else lwords[lword] = 1; } lfile.close(); cout << "lwords contents\n"; for(auto &w : lwords) cout << w << ": " << lwords[w] << endl; cout << "Number of words: " << lwords.get_items() << endl; return 0; }