From c3b30930fa56154f45bb8f37c3715c7501e3d1a9 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 4 Apr 2023 10:34:55 -0700 Subject: [PATCH] Add bloom filter index calc for userspace utils Signed-off-by: Zach Brown --- utils/src/bloom.c | 20 ++++++++++++++++++++ utils/src/bloom.h | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 utils/src/bloom.c create mode 100644 utils/src/bloom.h diff --git a/utils/src/bloom.c b/utils/src/bloom.c new file mode 100644 index 00000000..45939424 --- /dev/null +++ b/utils/src/bloom.c @@ -0,0 +1,20 @@ +#include + +#include "sparse.h" +#include "util.h" +#include "format.h" +#include "hash.h" +#include "bloom.h" + +void calc_bloom_nrs(struct scoutfs_key *key, unsigned int *nrs) +{ + u64 hash; + int i; + + hash = scoutfs_hash64(key, sizeof(struct scoutfs_key)); + + for (i = 0; i < SCOUTFS_FOREST_BLOOM_NRS; i++) { + nrs[i] = (u32)hash % SCOUTFS_FOREST_BLOOM_BITS; + hash >>= SCOUTFS_FOREST_BLOOM_FUNC_BITS; + } +} diff --git a/utils/src/bloom.h b/utils/src/bloom.h new file mode 100644 index 00000000..9a2d3b3b --- /dev/null +++ b/utils/src/bloom.h @@ -0,0 +1,6 @@ +#ifndef _BLOOM_H_ +#define _BLOOM_H_ + +void calc_bloom_nrs(struct scoutfs_key *key, unsigned int *nrs); + +#endif