Question: Implementing a custom hashtable that hashes a bunch of dictionary words to use with a wordsearch automation program. Hash methods try to do separate chaining
Implementing a custom hashtable that hashes a bunch of dictionary words to use with a wordsearch automation program. Hash methods try to do separate chaining with linked lists but not sure why it is hashing incorrectly. It only registers letters or a couple words but not all.
#include "hashTable.h" #include
HashTable :: HashTable(unsigned int length){ if (!checkprime(length)){ ARRAY_LENGTH = getNextPrime(length); myArray = new list
else { ARRAY_LENGTH = length; myArray = new list
cout << "Hash made "<< ARRAY_LENGTH << endl; }
HashTable :: ~HashTable(){ }
unsigned int HashTable :: hash(string x){ unsigned int index = 0; for (int i =0; i < x.length(); i++){ index+= (unsigned int)x.at(i) * pow(37, i); } return index % ARRAY_LENGTH; }
void HashTable :: store (string x){ int index = hash(x); myArray[index].push_back(x); }
bool HashTable :: match (string word){ int index = hash(word); if (word.length() < 3) return false;
list
this is portion in main to test if wordsearch 2d array contains a valid word
// Get a word (of length 10), starting at position (2,2) in the // array, in each of the 8 directions for(int x = 0; x < cols; x ++){ for(int y = 0; y < rows; y++){ for ( int d = 0; d < 8; d++ ){ string temp = getWordInGrid(x,y,d,10,rows,cols); if (h.match(temp)) { wordCount++; cout << direction(d) << "( " << x << " , " << y << " ) : " << temp << endl; break; } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
