Hash table for dictionary?

Hi everyone,

I'm trying to create a method for spellchecking which isn't as slow as searching through every word in a dictionary. Apparently the best way of doing this is using a hash table using unordered_map in C++. As far as I understand every word of the dictionary should have a unique key and then when a word needs to be spellchecked a key is generated from that word and if nothing is in that location (much like checking the index of an array) then it isn't a word. Is this right?

My problem at the moment is trying to find a unique key for each word. Does anyone have any ideas (adding ASCII codes surely won't be unique)?

Thanks.
The hash doesn't have to be unique and the standard library already implements that for strings anyway.
Hash tables are generally organized into buckets that contain all the elements whose hash has the same prefix.
All you need is:

1
2
3
4
5
6
7
unordered_set<string> dictionary;
foreach(word,dictionaryFile)dictionary.insert(word);
[...]
if (dictionary.find(word)==dictionary.end())
{
  //word is not in dictionary
}
Last edited on
Topic archived. No new replies allowed.