Fast String Hashing Algorithm with low collision rates with 32 bit integer


I have lots of unrelated named things that I'd like to do quick searches against. An "aardvark" is always an "aardvark" everywhere, so hashing the string and reusing the integer would work well to speed up comparisons. The entire set of names is unknown (and changes over time). What is a fast string hashing algorithm that will generate small (32 or 16) bit values and have a low collision rate?

I'd like to see an optimized implementation specific to C/C++.

9/9/2012 4:20:49 PM

Accepted Answer

One of the FNV variants should meet your requirements. They're fast, and produce fairly evenly distributed outputs.

9/22/2008 10:08:32 AM

Murmur Hash is pretty nice.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow