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.
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