Files
scoutfs/utils/src/leaf_item_hash.c
Zach Brown 35d1ad1422 scoutfs-utils: switch to using fnv1a for hashing
Track the scoutfs module's switch to FNV1a for hashing.

Signed-off-by: Zach Brown <zab@versity.com>
2020-08-26 14:39:28 -07:00

40 lines
829 B
C

#include "sparse.h"
#include "util.h"
#include "format.h"
#include "hash.h"
#include "leaf_item_hash.h"
/*
* A minimal extraction of the leaf item hash from the kernel's btree.
*/
int leaf_item_hash_ind(struct scoutfs_key *key)
{
return scoutfs_hash32(key, sizeof(struct scoutfs_key)) %
SCOUTFS_BTREE_LEAF_ITEM_HASH_NR;
}
__le16 *leaf_item_hash_buckets(struct scoutfs_btree_block *bt)
{
return (void *)bt + SCOUTFS_BLOCK_LG_SIZE -
SCOUTFS_BTREE_LEAF_ITEM_HASH_BYTES;
}
void leaf_item_hash_insert(struct scoutfs_btree_block *bt,
struct scoutfs_key *key, __le16 off)
{
__le16 *buckets = leaf_item_hash_buckets(bt);
int i;
if (bt->level > 0)
return;
for (i = leaf_item_hash_ind(key);
i < SCOUTFS_BTREE_LEAF_ITEM_HASH_NR; i++) {
if (buckets[i] == 0) {
buckets[i] = off;
return;
}
}
}