From: Florian Festi Date: Thu, 16 Oct 2008 10:07:44 +0000 (+0200) Subject: Improve finger print hash function to avoid degeneration of hash tables X-Git-Tag: tznext/4.11.0.1.tizen20130304~3524 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=48554042f434fd75452e752f1156a652ffe71c8b;p=tools%2Flibrpm-tizen.git Improve finger print hash function to avoid degeneration of hash tables --- diff --git a/lib/fprint.c b/lib/fprint.c index 5a2c055..6805765 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -197,16 +197,13 @@ fingerPrint fpLookup(fingerPrintCache cache, const char * dirName, unsigned int fpHashFunction(const fingerPrint * fp) { unsigned int hash = 0; - char ch; - const char * chptr; + int j; - ch = 0; - chptr = fp->baseName; - while (*chptr != '\0') ch ^= *chptr++; + hash = hashFunctionString(fp->baseName); + if (fp->subDir) hash ^= hashFunctionString(fp->subDir); - hash |= ((unsigned)ch) << 24; - hash |= (((((unsigned)fp->entry->dev) >> 8) ^ fp->entry->dev) & 0xFF) << 16; - hash |= fp->entry->ino & 0xFFFF; + hash ^= ((unsigned)fp->entry->dev); + for (j=0; j<4; j++) hash ^= ((fp->entry->ino >> (8*j)) & 0xFF) << ((3-j)*8); return hash; }