HashCode

Hello ,
What is the most efficient algorithm applied on strings that generates a unique hash code ?
I need this algorithm to apply on the words of a dictionary , which then will be put in a hash table .
So i need a suitable algorithm with the least number of collisions .
I'v tried the following : Adding the ASCII code for each letter . example:
the word "abe" :
a-->97
b-->98
e-->101
hash code : 97+98+101 = 296
But this seems to generate lots of collisions ( a lot of words will have the same code ) .
I'am a beginner using C# language , Any help would be appreciated .
Thank you and sorry for the long post .
There is no one specific hash function out there that generates a unique hashcode for every string. There are some that come close and these are the ones that achieve avalanche very quickly and provide minimal collisions. Ones like FNV and Mumurhash (Used by Google) are among the best.

This website provides information on most hash functions out there:
http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx

Avalanche:
http://en.wikipedia.org/wiki/Avalanche_effect

Popular hash functions tested:
http://programmers.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed

If you want to generate a hash function that produces no collisions for your given set of input, then you need to know before hand the type of input you will be getting and the number of them. Only with those 2 information will you be able to generate a unique hash function that will map each key to a unique bucket
https://en.wikipedia.org/wiki/Perfect_hash_function


Also I beleive C# Strings just like Java have a method that returns a hashCode for the String:
http://msdn.microsoft.com/en-CA/library/system.string.gethashcode.aspx
Last edited on
Thank you , the links were very helpful , i will be testing these hash functions
to find the one with the least collisions .
Topic archived. No new replies allowed.