rama-net 0.3.0

rama network types and utilities
Documentation
use core::hash::{Hash, Hasher};

#[derive(Default)]
pub(crate) struct StableHasher(u64);

impl Hasher for StableHasher {
    fn finish(&self) -> u64 {
        self.0
    }

    fn write(&mut self, bytes: &[u8]) {
        let mut hash = self.0;
        if hash == 0 {
            hash = 0xcbf2_9ce4_8422_2325;
        }
        for byte in bytes {
            hash ^= u64::from(*byte);
            hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
        }
        self.0 = hash;
    }
}

pub(crate) fn hash<T: Hash + ?Sized>(value: &T) -> u64 {
    let mut hasher = StableHasher::default();
    value.hash(&mut hasher);
    hasher.finish()
}