hash: Change mhash_finish() data measurement from words to bytes.
authorBen Pfaff <blp@nicira.com>
Fri, 14 Dec 2012 22:50:06 +0000 (14:50 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 22 Jan 2013 21:40:52 +0000 (13:40 -0800)
murmurhash includes an xor with the number of bytes hashed in its finishing
step.  Until now, we've only had murmurhash for full words, but an upcoming
commit adds murmurhash for bytes, so the finishing function will need to
take a count of bytes instead.

Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/flow.c
lib/hash.c
lib/hash.h

index 861a1f1..05bc269 100644 (file)
@@ -1148,7 +1148,7 @@ miniflow_hash_in_minimask(const struct miniflow *flow,
         }
     }
 
-    return mhash_finish(hash, p - mask->masks.values);
+    return mhash_finish(hash, (p - mask->masks.values) * 4);
 }
 
 /* Returns a hash value for the bits of 'flow' where there are 1-bits in
@@ -1177,7 +1177,7 @@ flow_hash_in_minimask(const struct flow *flow, const struct minimask *mask,
         }
     }
 
-    return mhash_finish(hash, p - mask->masks.values);
+    return mhash_finish(hash, (p - mask->masks.values) * 4);
 }
 \f
 /* Initializes 'dst' as a copy of 'src'.  The caller must eventually free 'dst'
index 41ad1bf..8cee5d0 100644 (file)
@@ -115,5 +115,5 @@ mhash_words(const uint32_t p[], size_t n_words, uint32_t basis)
     for (i = 0; i < n_words; i++) {
         hash = mhash_add(hash, p[i]);
     }
-    return mhash_finish(hash, n_words);
+    return mhash_finish(hash, n_words * 4);
 }
index 96866c4..d33924f 100644 (file)
@@ -149,9 +149,9 @@ static inline uint32_t mhash_add(uint32_t hash, uint32_t data)
     return hash * 5 + 0xe6546b64;
 }
 
-static inline uint32_t mhash_finish(uint32_t hash, size_t n)
+static inline uint32_t mhash_finish(uint32_t hash, size_t n_bytes)
 {
-    hash ^= n * 4;
+    hash ^= n_bytes;
     hash ^= hash >> 16;
     hash *= 0x85ebca6b;
     hash ^= hash >> 13;