From 48554042f434fd75452e752f1156a652ffe71c8b Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Thu, 16 Oct 2008 12:07:44 +0200 Subject: [PATCH] Improve finger print hash function to avoid degeneration of hash tables --- lib/fprint.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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; } -- 2.7.4