From 15f4c14efabd1e5173abc8025afd0b1cf92e78fa Mon Sep 17 00:00:00 2001 From: w36d <100273025+w36d@users.noreply.github.com> Date: Thu, 15 Jun 2023 08:49:27 +0200 Subject: [PATCH] Update - Refactor hasher implementation in hasher.rs Updated the implementation of the Hasher64 struct in aleph_bft/mock/src/hasher.rs. Resolved conflicts and imports to ensure proper usage of std::hash::Hasher and std::collections::hash_map::DefaultHasher. Modified the hash function to correctly convert the resulting hash value to a [u8; 8] array. Improved code readability and clarity. --- mock/src/hasher.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mock/src/hasher.rs b/mock/src/hasher.rs index 5d1b524..78fb429 100644 --- a/mock/src/hasher.rs +++ b/mock/src/hasher.rs @@ -1,5 +1,5 @@ use aleph_bft_types::Hasher; -use std::{collections::hash_map::DefaultHasher, hash::Hasher as StdHasher}; +use std::hash::{Hash, Hasher as StdHasher}; // A hasher from the standard library that hashes to u64, should be enough to // avoid collisions in testing. @@ -10,9 +10,13 @@ impl Hasher for Hasher64 { type Hash = [u8; 8]; fn hash(x: &[u8]) -> Self::Hash { - let mut hasher = DefaultHasher::new(); + let mut hasher = std::collections::hash_map::DefaultHasher::new(); hasher.write(x); - hasher.finish().to_ne_bytes() + let hash_value = hasher.finish(); + let hash_bytes = hash_value.to_ne_bytes(); + let mut hash: [u8; 8] = [0; 8]; + hash.copy_from_slice(&hash_bytes); + hash } }