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 #include using namespace std; #include "primenumber.cpp"

HashTable :: HashTable(unsigned int length){ if (!checkprime(length)){ ARRAY_LENGTH = getNextPrime(length); myArray = new list[ARRAY_LENGTH]; }

else { ARRAY_LENGTH = length; myArray = new list[ARRAY_LENGTH]; }

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 :: iterator i; for (i = myArray[index].begin(); i != myArray[index].end(); i++){ if (*i == word) { cout << *i << " index>" << index<< endl; return true; } } return false; }

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!