I am trying to create a hash function that calculates the hash for words that are read from a file. I am planning to put words that have the same letters in an array of linked lists. Later on, when the user asks for all meaningful combinations of a given letter, it will be provided to him.
staticconstint TABLE_SIZE = 11117;
// an array of lists of strings
list<string> table[TABLE_SIZE];
void WordFinder(string dictionaryFile) {
// read in the file and populate the table
ifstream myFile(dictionaryFile);
string word;
int c, hash;
if (!myFile)
cout << "Couldn't open the file" << endl;
while (myFile >> word) //get words one by one (ignoring white spaces) and push them into the string vector
{
transform(word.begin(), word.end(), word.begin(), ::tolower);
//... use hash function here to generate the hash
//table[hash].push_back(word);
}
}
What hash function can I use? I tried the djb2 hash function but it generated different values for "cat" and "act".