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 <zab@versity.com>
This commit is contained in:
Zach Brown
2019-06-18 16:41:26 -07:00
committed by Zach Brown
parent a7fef3d7dd
commit aee017903b

15
kmod/src/hash.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef _SCOUTFS_HASH_H_
#define _SCOUTFS_HASH_H_
#include <linux/crc32c.h>
/* 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