Use 64-bit TommyDS hash functions on 64-bit architectures

This commit is contained in:
Andrea Mazzoleni
2026-10-08 20:45:29 +02:00
parent 2dc349fe93
commit 4e6192b625
5 changed files with 42 additions and 18 deletions
+9 -5
View File
@@ -70,9 +70,13 @@ struct snapraid_hash* hash_alloc(struct snapraid_state* state, struct snapraid_d
return hash;
}
static inline tommy_uint32_t hash_hash(struct snapraid_hash* hash)
static inline tommy_hash_t hash_hash(struct snapraid_hash* hash)
{
#if TOMMY_SIZE_BIT == 64
return tommy_hash_u64(0, hash->hash, HASH_MAX);
#else
return tommy_hash_u32(0, hash->hash, HASH_MAX);
#endif
}
static void hash_free(void* void_hash)
@@ -112,7 +116,7 @@ void state_dup(struct snapraid_state* state)
for (j = disk->filelist; j != 0; j = j->next) {
struct snapraid_file* file = j->data;
struct snapraid_hash* hash;
tommy_hash_t hash32;
tommy_hash_t hash_val;
/* if empty, skip it */
if (file->size == 0)
@@ -124,9 +128,9 @@ void state_dup(struct snapraid_state* state)
if (!hash)
continue;
hash32 = hash_hash(hash);
hash_val = hash_hash(hash);
struct snapraid_hash* found = tommy_hashdyn_search(&hashset, hash_compare, hash->hash, hash32);
struct snapraid_hash* found = tommy_hashdyn_search(&hashset, hash_compare, hash->hash, hash_val);
if (found) {
++count;
size += found->file->size;
@@ -134,7 +138,7 @@ void state_dup(struct snapraid_state* state)
printf("%12" PRIu64 " %s = %s\n", file->size, fmt_term(disk, file->sub), fmt_term(found->disk, found->file->sub));
hash_free(hash);
} else {
tommy_hashdyn_insert(&hashset, &hash->node, hash, hash32);
tommy_hashdyn_insert(&hashset, &hash->node, hash, hash_val);
}
}
}
+25 -9
View File
@@ -982,9 +982,9 @@ int file_path_compare(const void* void_a, const void* void_b);
/**
* Compute the hash of a file inode.
*/
static inline tommy_uint32_t file_inode_hash(uint64_t inode)
static inline tommy_hash_t file_inode_hash(uint64_t inode)
{
return (tommy_uint32_t)tommy_inthash_u64(inode);
return tommy_inthash_u64(inode);
}
/**
@@ -1003,15 +1003,19 @@ int file_pathstamp_compare(const void* void_a, const void* void_b);
/**
* Compute the hash of a file path with known length.
*/
static inline tommy_uint32_t file_path_hash_len(const char* sub, size_t len)
static inline tommy_hash_t file_path_hash_len(const char* sub, size_t len)
{
#if TOMMY_SIZE_BIT == 64
return tommy_hash_u64(0, sub, len);
#else
return tommy_hash_u32(0, sub, len);
#endif
}
/**
* Compute the hash of a file path.
*/
static inline tommy_uint32_t file_path_hash(const char* sub)
static inline tommy_hash_t file_path_hash(const char* sub)
{
return file_path_hash_len(sub, strlen(sub));
}
@@ -1019,9 +1023,13 @@ static inline tommy_uint32_t file_path_hash(const char* sub)
/**
* Compute the hash of a file stamp.
*/
static inline tommy_uint32_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)
{
#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));
#else
return tommy_inthash_u32((tommy_uint32_t)size ^ tommy_inthash_u32((tommy_uint32_t)mtime_sec ^ tommy_inthash_u32(mtime_nsec)));
#endif
}
/**
@@ -1097,15 +1105,19 @@ int link_alpha_compare(const void* void_a, const void* void_b);
/**
* Compute the hash of a link name with known length.
*/
static inline tommy_uint32_t link_name_hash_len(const char* name, size_t len)
static inline tommy_hash_t link_name_hash_len(const char* name, size_t len)
{
#if TOMMY_SIZE_BIT == 64
return tommy_hash_u64(0, name, len);
#else
return tommy_hash_u32(0, name, len);
#endif
}
/**
* Compute the hash of a link name.
*/
static inline tommy_uint32_t link_name_hash(const char* name)
static inline tommy_hash_t link_name_hash(const char* name)
{
return link_name_hash_len(name, strlen(name));
}
@@ -1147,15 +1159,19 @@ int dir_name_compare(const void* void_arg, const void* void_data);
/**
* Compute the hash of a dir name with known length.
*/
static inline tommy_uint32_t dir_name_hash_len(const char* name, size_t len)
static inline tommy_hash_t dir_name_hash_len(const char* name, size_t len)
{
#if TOMMY_SIZE_BIT == 64
return tommy_hash_u64(0, name, len);
#else
return tommy_hash_u32(0, name, len);
#endif
}
/**
* Compute the hash of a dir name.
*/
static inline tommy_uint32_t dir_name_hash(const char* name)
static inline tommy_hash_t dir_name_hash(const char* name)
{
return dir_name_hash_len(name, strlen(name));
}
+5 -1
View File
@@ -30,9 +30,13 @@ struct snapraid_pool* pool_alloc(const char* dir, const char* name, const char*
return pool;
}
static inline tommy_uint32_t pool_hash(const char* file)
static inline tommy_hash_t pool_hash(const char* file)
{
#if TOMMY_SIZE_BIT == 64
return tommy_hash_u64(0, file, strlen(file));
#else
return tommy_hash_u32(0, file, strlen(file));
#endif
}
static void pool_free(void* void_pool)
+1 -1
View File
@@ -1021,7 +1021,7 @@ static void scan_file_apply(void* void_scan, void* void_disc)
* in such case we have a "copy" over an "update"
*/
if (!state->opt.force_nocopy) {
tommy_uint32_t hash = file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec);
tommy_hash_t hash = file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec);
/* search for a file with the same name and stamp in all the disks */
for (i = state->disklist; i != 0; i = i->next) {
+2 -2
View File
@@ -22,7 +22,7 @@ static const char* es(int err)
static void search_file(struct snapraid_state* state, const char* path, data_off_t size, int64_t mtime_sec, int mtime_nsec)
{
struct snapraid_search_file* file;
tommy_uint32_t file_hash;
tommy_hash_t file_hash;
file = malloc_nofail(sizeof(struct snapraid_search_file));
file->path = strdup_nofail(path);
@@ -133,7 +133,7 @@ int search_file_compare(const void* void_arg, const void* void_data)
int state_search_fetch(struct snapraid_state* state, int prevhash, struct snapraid_file* missing_file, block_off_t missing_file_pos, struct snapraid_block* missing_block, unsigned char* buffer)
{
struct snapraid_search_file* file;
tommy_uint32_t file_hash;
tommy_hash_t file_hash;
struct search_file_compare_arg arg;
arg.state = state;