From cb8ca8156749d07c94b92249a49c1c6aa7c74934 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 14 Dec 2012 14:50:06 -0800 Subject: [PATCH] hash: Change mhash_finish() data measurement from words to bytes. 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 --- lib/flow.c | 4 ++-- lib/hash.c | 2 +- lib/hash.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/flow.c b/lib/flow.c index 861a1f1cb..05bc269d0 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -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); } /* Initializes 'dst' as a copy of 'src'. The caller must eventually free 'dst' diff --git a/lib/hash.c b/lib/hash.c index 41ad1bf2f..8cee5d0b0 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -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); } diff --git a/lib/hash.h b/lib/hash.h index 96866c42a..d33924fc6 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -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; -- 2.43.0