summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastian Vater2025-07-24 15:55:42 +0200
committerSebastian Vater2025-07-24 15:55:42 +0200
commit74b8ced1eee373ada8554ddbcb0e8a1bd8b7c574 (patch)
tree95e841a3379dfc939f42da7b8c4392101088edef /src
parentFixed some typos and changed header digest CRC32C functions to store the resu... (diff)
downloaddnbd3-74b8ced1eee373ada8554ddbcb0e8a1bd8b7c574.tar.gz
dnbd3-74b8ced1eee373ada8554ddbcb0e8a1bd8b7c574.tar.xz
dnbd3-74b8ced1eee373ada8554ddbcb0e8a1bd8b7c574.zip
Made fast hashing a little bit more readable and fixed address increment for next hash data value (should be 8 bytes instead of 1).
Diffstat (limited to 'src')
-rw-r--r--src/server/iscsi.c5
-rw-r--r--src/server/iscsi.h4
2 files changed, 5 insertions, 4 deletions
diff --git a/src/server/iscsi.c b/src/server/iscsi.c
index 925e4e8..c5f796d 100644
--- a/src/server/iscsi.c
+++ b/src/server/iscsi.c
@@ -185,12 +185,13 @@ static int iscsi_hashmap_resize(iscsi_hashmap *map)
*/
static inline uint32_t iscsi_hashmap_hash_data(const uint8_t *data, const size_t len)
{
+ const uint64_t *hash_data = (const uint64_t *) data;
size_t num_blocks = iscsi_align(len, ISCSI_HASHMAP_KEY_ALIGN) >> ISCSI_HASHMAP_KEY_ALIGN_SHIFT;
uint64_t hash = ISCSI_HASHMAP_HASH_INITIAL;
do {
- hash ^= *(uint64_t *) data++; // Hash 8 bytes of data at once
- hash *= ISCSI_HASHMAP_HASH_XOR;
+ hash ^= *hash_data++;
+ hash *= ISCSI_HASHMAP_HASH_MUL;
} while ( --num_blocks > 0UL );
return (uint32_t) (hash ^ hash >> 32ULL);
diff --git a/src/server/iscsi.h b/src/server/iscsi.h
index 0f1419a..a8e0a35 100644
--- a/src/server/iscsi.h
+++ b/src/server/iscsi.h
@@ -111,8 +111,8 @@ static inline void iscsi_put_be64(uint8_t *data, const uint64_t val)
#define ISCSI_HASHMAP_RESIZE_FACTOR 1UL // Number of bits to shift left when resizing
#define ISCSI_HASHMAP_KEY_ALIGN_SHIFT 3UL // Key data shift value for alignment enforcement
#define ISCSI_HASHMAP_KEY_ALIGN (1UL << (ISCSI_HASHMAP_KEY_ALIGN_SHIFT)) // Key data size must be multiple of 8 bytes by now
-#define ISCSI_HASHMAP_HASH_INITIAL 2166136261UL // Initial hash code
-#define ISCSI_HASHMAP_HASH_XOR 0xBF58476D1CE4E5B9ULL // XOR value for hash code
+#define ISCSI_HASHMAP_HASH_INITIAL 0x811C9DC5UL // Initial hash code
+#define ISCSI_HASHMAP_HASH_MUL 0xBF58476D1CE4E5B9ULL // Value to multiply hash code with
typedef struct iscsi_hashmap_bucket {
struct iscsi_hashmap_bucket *next; // Must be first element