From aee017903b5c463fa3ad7c4ed352b74d0efd2d01 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 18 Jun 2019 16:41:26 -0700 Subject: [PATCH] scoutfs: add hash helper Add a quick header which calculates 64bit hashes by calculating the crc of the two halves of a byte region. Signed-off-by: Zach Brown --- kmod/src/hash.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 kmod/src/hash.h diff --git a/kmod/src/hash.h b/kmod/src/hash.h new file mode 100644 index 00000000..3ad3de09 --- /dev/null +++ b/kmod/src/hash.h @@ -0,0 +1,15 @@ +#ifndef _SCOUTFS_HASH_H_ +#define _SCOUTFS_HASH_H_ + +#include + +/* XXX replace with xxhash */ +static inline u64 scoutfs_hash64(const void *data, unsigned int len) +{ + unsigned int half = (len + 1) / 2; + + return crc32c(~0, data, half) | + ((u64)crc32c(~0, data + len - half, half) << 32); +} + +#endif