Skip to main content
$12256 / $11500
About
Rules
Blog
FAQ
Style
Forum
String Hash functions
Programming
String Hash functions
jaderamiso
Wednesday, December 22, 2010 - 03:21
does anyone know any good string hash functions??
I think it depends on what you want to do with it on what is a good hash function.
well, i want to use it on a hash table..
ill be using it in creating a symbol table
Depends on the allowed size of the hash, the data to hash, and the amount of collisions you can deal with.
"string" is very generic: only a-zA-Z, or full ASCII, or even full unicode strings?
If the hash size is allowed to be big, you might aswell use a full MD5 or SHA-family algorithm.
If the hash size should be rather small (like, an integer), there is the category of CRC algorithms (for example CRC32 generates one 32-bit integer checksum), I read Adler32 or Fletcher are slightly better than CRC32
Hope that helps.
If you're okay with collisions and you just want to sort them into a bunch of buckets, one thing you can do is, say, hash them by the first character. This is, of course, assuming that the strings are relatively random. If you want to be as fast as possible, my general advice is to pick something that you expect to be different about each string and write a custom has function based on that. If you need to avoid collisions at all costs, use an existing algorithm. :)
thanks for the reply! i did found several algorithms, im currently checking their performance. As for preventing collisions i plan on using chaining.