hashing words read from a dictionary file

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
	static const int 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".
Last edited on
Make a copy of the string, sort the letters, hash on the sorted string. That way "cat" and "act" will share the same hash.
Topic archived. No new replies allowed.