// Program to Test Hash Table Class // Program is driven by command input: // i url -- insert "url" into hash table; report whether it's // already there. // q url -- query table for "url"; report success/failure. // r url -- remove "url" from table; report whether it was there. // p -- print contents of table. // end-of-file to quit // Lines beginning "#" are ignored. #include #include #include // has EXIT_SUCCESS #include "hashTable.h" #include "URL.h" int main(void) { hashTable URLTable; char prompt[] = "Command? "; string inURL; char cmd; cerr << prompt; while (cin >> cmd) { if (cmd == '#') { string cmtLine; getline(cin, cmtLine); cout << '#' << cmtLine << endl; } else if (cmd == 'i') { cin >> inURL; URL u(inURL); cout << "Inserting " << inURL << ": "; hashTable::insertPair insertAnswer = URLTable.insert(u); if (insertAnswer.first == true) cout << inURL << " inserted\n"; else cout << inURL << " not inserted; duplicate of " << insertAnswer.second << endl; } else if (cmd == 'q') { cin >> inURL; URL u(inURL); if (URLTable.query(u)) cout << inURL << " found\n"; else cout << inURL << " not found\n"; } else if (cmd == 'r') { cin >> inURL; URL u(inURL); if (URLTable.remove(u)) cout << inURL << " removed\n"; else cout << inURL << " not removed; not present\n"; } else if (cmd == 'p') { cout << "\nHash table contents:\n" << URLTable << endl; } cerr << prompt; } cerr << endl; cout << "\nThat's all, folks!\n"; return EXIT_SUCCESS; }