hash: Correct implementation of mhash_finish().
authorBen Pfaff <blp@nicira.com>
Fri, 14 Dec 2012 21:43:54 +0000 (13:43 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 22 Jan 2013 21:40:50 +0000 (13:40 -0800)
With rotates instead of shifts, the upper and lower 16 bits of the returned
hash are always the same.

I noticed this while working on replacing Jenkins hash by murmurhash,
because some of the database unit tests started failing, e.g. "row
hashing (scalars)".

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/hash.h

index 701e686..96866c4 100644 (file)
@@ -152,11 +152,11 @@ static inline uint32_t mhash_add(uint32_t hash, uint32_t data)
 static inline uint32_t mhash_finish(uint32_t hash, size_t n)
 {
     hash ^= n * 4;
-    hash ^= hash_rot(hash, 16);
+    hash ^= hash >> 16;
     hash *= 0x85ebca6b;
-    hash ^= hash_rot(hash, 13);
+    hash ^= hash >> 13;
     hash *= 0xc2b2ae35;
-    hash ^= hash_rot(hash, 16);
+    hash ^= hash >> 16;
     return hash;
 }