Is there a glibc hash function? Is there a glibc hash function? linux linux

Is there a glibc hash function?


You can take a look at Bob Jenkin's survey and analysis of many hash functions:

Or just drop his lookup3 routines (which he's put into the public domain) into your project:


For a hash table, you do not need cryptographic strength, only good randomization properties. Broken cryptographic hash functions (like MD5) are fine for that, but you may want to use MD4, which is both faster and simpler, to the point that you could simply include an implementation directly in your code. It is not difficult to rewrite it from the specification (and since you want only a function for a hash table, it is not really a problem if you get it wrong at some point). Shameless plug: there is an optimized C implementation of MD4 in sphlib.


Unless you already have a good reason for using MD5, you may want to reconsider. What makes for a "good" hash function in a hash table is pretty dependent on what you're trying to accomplish. You may want to read the comments in Python's dictobject.c to see the sorts of tradeoffs others have made.