/** * Clayton Cafiero * CS 2240 * 2021-Jan-19 */ #include #include "HashTableBasic.h" /** * Horner hashing function * char is an integral type -- that is, it's value is stored as * an integer. (We're going to pretend Unicode and multibyte * encodings and all that stuff doesn't exist.) */ unsigned long hornerHash(std::string key, unsigned long tableSize) { unsigned long hashVal = 0; for (const char& letter : key) { hashVal = hashVal * 37 + letter; } return hashVal % tableSize; } int main() { HashTableBasic hashTable(53, hornerHash); hashTable.insert("Hello, World!"); hashTable.insert("UVM CS 2240"); hashTable.insert("Who is Egbert Porcupine?"); hashTable.insert("Universitas Viridis Montis"); hashTable.printTable(); optional s = hashTable.find("Hello, World!"); if (s) { std::cout << *s << " is in the table" << std::endl; } else { std::cout << "Hello, World! was not found" << std::endl; } s = hashTable.remove("Hello, World!"); if (s) { std::cout << *s << " has been removed" << std::endl; } else { std::cout << "Hello, World! was not removed" << std::endl; } hashTable.printTable(); return 0; }