From: Florian Festi Date: Thu, 16 Oct 2008 07:59:54 +0000 (+0200) Subject: Switch to a better hash functions for strings: Jenkins One-at-a-time hash X-Git-Tag: rpm-4.7.0-beta1~398 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ecc8ff93740f1cc733350016b9b4304c4f14e9d6;p=platform%2Fupstream%2Frpm.git Switch to a better hash functions for strings: Jenkins One-at-a-time hash --- diff --git a/lib/rpmhash.c b/lib/rpmhash.c index 5d5d6a7..34be313 100644 --- a/lib/rpmhash.c +++ b/lib/rpmhash.c @@ -5,19 +5,20 @@ #include "lib/rpmhash.h" -unsigned int hashFunctionString(const char * string) -{ - char xorValue = 0; - char sum = 0; - short len; - int i; - const char * chp = string; - len = strlen(string); - for (i = 0; i < len; i++, chp++) { - xorValue ^= *chp; - sum += *chp; - } +unsigned int hashFunctionString(const char * string) { + /* Jenkins One-at-a-time hash */ + + unsigned int hash = 0xe4721b68; - return ((((unsigned)len) << 16) + (((unsigned)sum) << 8) + xorValue); + while (*string != '\0') { + hash += *string; + hash += (hash << 10); + hash ^= (hash >> 6); + string++; + } + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + return hash; }