[sheepdog] [PATCH 2/7] add sd_hash to generate more dispersed hash values

MORITA Kazutaka morita.kazutaka at gmail.com
Fri Aug 30 11:32:04 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

I noticed that adding one more fnv_64a calculation like

  hval = fnv_64a_64(hval, hval)

generates much more dispersed hash values.

This patch introduces sd_hash(), which does the above calculation
before returning the result.  This also add sd_hash_next(), which is
intended to be used for virtual nodes and virtual disks.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/sheepdog_proto.h |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 845dac6..c194c8c 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -265,6 +265,25 @@ static inline uint64_t fnv_64a_64(uint64_t oid, uint64_t hval)
 	return hval;
 }
 
+static inline uint64_t sd_hash(const void *buf, size_t len)
+{
+	uint64_t hval = fnv_64a_buf(buf, len, FNV1A_64_INIT);
+
+	return fnv_64a_64(hval, hval);
+}
+
+static inline uint64_t sd_hash_64(uint64_t oid)
+{
+	uint64_t hval = fnv_64a_64(oid, FNV1A_64_INIT);
+
+	return fnv_64a_64(hval, hval);
+}
+
+static inline uint64_t sd_hash_next(uint64_t hval)
+{
+	return fnv_64a_64(hval, hval);
+}
+
 static inline uint64_t hash_64(uint64_t val, unsigned int bits)
 {
 	uint64_t hash = fnv_64a_buf(&val, sizeof(uint64_t), FNV1A_64_INIT);
-- 
1.7.9.5




More information about the sheepdog mailing list