mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-02 12:57:14 -05:00
Use mulhash for integer keys while retaining inthash_u64 on 32-bit architectures
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
This commit is contained in:
parent
377a907c0c
commit
8f22da9018
2 changed files with 31 additions and 3 deletions
|
|
@ -1773,7 +1773,7 @@ void bucket_free(void* void_bucket)
|
||||||
|
|
||||||
void bucket_insert(tommy_hashdyn* bucket_hash, time_t time_at, block_off_t count, int justsynced)
|
void bucket_insert(tommy_hashdyn* bucket_hash, time_t time_at, block_off_t count, int justsynced)
|
||||||
{
|
{
|
||||||
tommy_hash_t hash = tommy_inthash_u64(time_at);
|
tommy_hash_t hash = bucket_time_hash(time_at);
|
||||||
tommy_node* i = tommy_hashdyn_bucket(bucket_hash, hash);
|
tommy_node* i = tommy_hashdyn_bucket(bucket_hash, hash);
|
||||||
while (i) {
|
while (i) {
|
||||||
struct snapraid_bucket* entry = i->data;
|
struct snapraid_bucket* entry = i->data;
|
||||||
|
|
|
||||||
|
|
@ -984,7 +984,12 @@ int file_path_compare(const void* void_a, const void* void_b);
|
||||||
*/
|
*/
|
||||||
static inline tommy_hash_t file_inode_hash(uint64_t inode)
|
static inline tommy_hash_t file_inode_hash(uint64_t inode)
|
||||||
{
|
{
|
||||||
|
#if TOMMY_SIZE_BIT == 64
|
||||||
|
return tommy_mulhash_u64(inode);
|
||||||
|
#else
|
||||||
|
/* avoid expensive 64-bit multiplications on 32-bit architectures */
|
||||||
return tommy_inthash_u64(inode);
|
return tommy_inthash_u64(inode);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1025,10 +1030,20 @@ static inline tommy_hash_t file_path_hash(const char* sub)
|
||||||
*/
|
*/
|
||||||
static inline tommy_hash_t file_stamp_hash(data_off_t size, int64_t mtime_sec, int mtime_nsec)
|
static inline tommy_hash_t file_stamp_hash(data_off_t size, int64_t mtime_sec, int mtime_nsec)
|
||||||
{
|
{
|
||||||
|
tommy_uint32_t nsec = mtime_nsec;
|
||||||
|
|
||||||
#if TOMMY_SIZE_BIT == 64
|
#if TOMMY_SIZE_BIT == 64
|
||||||
return tommy_inthash_u64((uint64_t)size ^ tommy_inthash_u64((uint64_t)mtime_sec ^ (uint64_t)(uint32_t)mtime_nsec));
|
tommy_uint64_t size_key = size;
|
||||||
|
tommy_uint64_t sec_key = mtime_sec;
|
||||||
|
tommy_uint64_t nsec_key = nsec;
|
||||||
|
|
||||||
|
/* valid nanoseconds use 30 bits above contemporary seconds; -1 stays distinct */
|
||||||
|
return tommy_mulhash_u64(size_key ^ tommy_mulhash_u64(sec_key ^ (nsec_key << 34)));
|
||||||
#else
|
#else
|
||||||
return tommy_inthash_u32((tommy_uint32_t)size ^ tommy_inthash_u32((tommy_uint32_t)mtime_sec ^ tommy_inthash_u32(mtime_nsec)));
|
tommy_uint32_t size_key = size;
|
||||||
|
tommy_uint32_t sec_key = mtime_sec;
|
||||||
|
|
||||||
|
return tommy_mulhash_u32(size_key ^ tommy_mulhash_u32(sec_key) ^ tommy_mulhash_u32(nsec));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1556,6 +1571,19 @@ struct snapraid_bucket {
|
||||||
|
|
||||||
void bucket_free(void* void_bucket);
|
void bucket_free(void* void_bucket);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the hash of a bucket time.
|
||||||
|
*/
|
||||||
|
static inline tommy_hash_t bucket_time_hash(time_t time_at)
|
||||||
|
{
|
||||||
|
#if TOMMY_SIZE_BIT == 64
|
||||||
|
return tommy_mulhash_u64(time_at);
|
||||||
|
#else
|
||||||
|
/* avoid expensive 64-bit multiplications on 32-bit architectures */
|
||||||
|
return tommy_inthash_u64(time_at);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert an bucket record into the hashtable
|
* Insert an bucket record into the hashtable
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue