Archived

This topic is now archived and is closed to further replies.

perfect hashing

This topic is 5149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

can you tell me how to hash lists of keywords like this : void const int float double char long short unsigned signed struct sizeof enum asm for do while switch case if else break continue default goto return so they will have a unique hash (no collision) I tried using cicelli''s method but still found a collision can anyone help me with the solution thanks before

Share this post


Link to post
Share on other sites
I use a hash system in my file packer similar to mpq''s where I get my hash values by doing operations against entries in a CRC table. CRC table values are pretty wierd, so you might try that. Also, increase the size of your hash table, and the reduces collisions greatly at the expense of memory of course, but I''ve never really seen hash tables as mem efficient. In my file system, I use far more entries than file in the archive, and I''ve never seen a collision using both techniques. In fact, the numbers come out very different, which is what you want.

Share this post


Link to post
Share on other sites
I didn't check this out, but it seems on such a simple list, that simple addition should work...

Simply add the byte value of each letter in the word and use that as a hash, I don't think you'll get any repeats that way with this list, but like I said, I haven't tested it.


--- Edit ---
Also, just wanted to say, a compiler I was working on, it created hash values for keywords, variable names, etc. If a hash matches, simply check the string to be sure it's identical, the hashes shouldn't have to be identical. I actually checked the length + hash value before checking the actual string to verify it was identical.

[edited by - Ready4Dis on November 9, 2003 11:08:50 PM]

Share this post


Link to post
Share on other sites
The only perfect hash function for an arbitrary list of items is an explicit mapping. Assign each keyword a unique integer. Then store the integers in a hashtable, keyed by an imperfect hash of the keyword.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites