Skip to main content

aleph_bft_mock/
hasher.rs

1use aleph_bft_types::Hasher;
2use std::{collections::hash_map::DefaultHasher, hash::Hasher as StdHasher};
3
4// A hasher from the standard library that hashes to u64, should be enough to
5// avoid collisions in testing.
6#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
7pub struct Hasher64;
8
9impl Hasher for Hasher64 {
10    type Hash = [u8; 8];
11
12    fn hash(x: &[u8]) -> Self::Hash {
13        let mut hasher = DefaultHasher::new();
14        hasher.write(x);
15        hasher.finish().to_ne_bytes()
16    }
17}
18
19pub type Hash64 = <Hasher64 as Hasher>::Hash;