On Apr 8, 2006, at 11:56 AM, [EMAIL PROTECTED] wrote:

If it were me, I'd just drag the text file directly into the project. Then at app startup (or better yet, the first time you need to look up a word), split the file on its end-of-line delimiter and stuff the words into a Dictionary object (as keys, with a dummy value like True).

Stuffing the dictionary with 3.9 MB of data might take a second or so, but then lookup (using Dictionary.HasKey) will be blazingly fast. Also, since you know ahead of time how many words you'll be stuffing, you can make the stuffing go faster by pre-sizing the dictionary (i.e., assign a suitably large BinCount before you start loading in values).

Okay, I've got the dictionary loaded, but HasKey is always returning false. Any Ideas?

BinCount of the dictionary is 65521, Count is 177741, loading it takes 2 seconds on a dual 1 GHz G4, and HasKey returns an answer virtually instantaneously.


Your BinCount is too small. Set it to 3*177741. If that fixes your problem, then you have found a problem with the Dictionary implementation.

You might also consider an alternative implementation. Load the word list into an array, sort it, and write the result out to a file. Then you can load the sorted list at runtime and use binary search to look up a word. This will require either 18 or 19 string comparisons for each lookup. It may be slower than a Dictionary on average, but it's guaranteed to be faster in the worst case, and it uses less memory.

Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to