Improve finger print hash function to avoid degeneration of hash tables
authorFlorian Festi <ffesti@redhat.com>
Thu, 16 Oct 2008 10:07:44 +0000 (12:07 +0200)
committerFlorian Festi <ffesti@redhat.com>
Fri, 24 Oct 2008 08:34:26 +0000 (10:34 +0200)
lib/fprint.c

index 5a2c055..6805765 100644 (file)
@@ -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;
 }