mirror of
https://github.com/versity/scoutfs.git
synced 2026-08-16 04:06:39 +00:00
We had a few uses of crc for hashing. That was fine enough for initial testing but the huge number of xattrs that srch is recording was seeing very bad collisions from the clumsy combination of crc32c into a 64bit hash. Replace it with FNV for now. This also takes the opportunity to use 3 hash functions in the forest bloom filter so that we can extract them from the 64bit hash of the key rather than iterating and recalculating hashes for each function. Signed-off-by: Zach Brown <zab@versity.com>
50 lines
976 B
C
50 lines
976 B
C
#ifndef _SCOUTFS_HASH_H_
|
|
#define _SCOUTFS_HASH_H_
|
|
|
|
/*
|
|
* We're using FNV1a for now. It's fine. Ish.
|
|
*
|
|
* The longer term plan is xxh3 but it looks like it'll take just a bit
|
|
* more time to be declared stable and then it needs to be ported to the
|
|
* kernel.
|
|
*
|
|
* - https://fastcompression.blogspot.com/2019/03/presenting-xxh3.html
|
|
* - https://github.com/Cyan4973/xxHash/releases/tag/v0.7.4
|
|
*/
|
|
|
|
static inline u32 fnv1a32(const void *data, unsigned int len)
|
|
{
|
|
u32 hash = 0x811c9dc5;
|
|
|
|
while (len--) {
|
|
hash ^= *(u8 *)(data++);
|
|
hash *= 0x01000193;
|
|
}
|
|
|
|
return hash;
|
|
}
|
|
|
|
static inline u64 fnv1a64(const void *data, unsigned int len)
|
|
{
|
|
u64 hash = 0xcbf29ce484222325;
|
|
|
|
while (len--) {
|
|
hash ^= *(u8 *)(data++);
|
|
hash *= 0x100000001b3;
|
|
}
|
|
|
|
return hash;
|
|
}
|
|
|
|
static inline u32 scoutfs_hash32(const void *data, unsigned int len)
|
|
{
|
|
return fnv1a32(data, len);
|
|
}
|
|
|
|
static inline u64 scoutfs_hash64(const void *data, unsigned int len)
|
|
{
|
|
return fnv1a64(data, len);
|
|
}
|
|
|
|
#endif
|