Bob Jenkins super fast hash for PHP
PHP's built-in functions like md5() perform really poorly when it comes to using the hash for hash tables or for uniform load balancing.
Paul Hsieh's hash is a very fast and popular hash function for that kind of job.
Last year, Bob Jekins compared a dozen of hash functions and designed its own (actually the third revision of it), that performs as fast as Paul Hsieh's with less collisions
To make a long story short: this is probably the most efficient hash function known yet, as long as it is not used for cryptographic purpose. And it's a pity that PHP doesn't implement it.
It's why I really wanted to spend a few minutes in order to create a PHP extension implementing that hash function.
Download the Jenkins hash extension for PHP and give it a try.
Preliminary benchmarks show that the Jenkins hash, as in the PHP extension, outperforms MD5 by 4 times, while still remaining a pretty good unique identifier.
Comments
-
The first studies of Bob Jenkins about comparing hash functions for table lookup is not only one year old, I have worked using his first results about 5 years ago. He is a very respected computer scientist, algorithm expert AND seems to be a very good developer too… If I understood correctly, he have been working on the hashing problems in the Oracle DB engine. His name is often found in C comments, for example he is mentionned in the explanation of the default simple hashing algorithm of the APR library (Apache httpd framework, svn framework etc.), the well-known x 33 algorithm (for (p = key; *p; p++) hash = hash * 33 + *p;) I often use his words in my blog, and I am a true fan of his work ;) It is not a surprise to find some of his hash functions in the ftwin’s source code !