consistent_hashing_aa/
identity_hasher.rs

1use std::hash::{BuildHasher, Hasher};
2
3#[derive(Debug, Clone)]
4pub struct IdentityHasher {
5    hash: u64,
6}
7
8impl IdentityHasher {
9    fn new() -> Self {
10        IdentityHasher { hash: 0 }
11    }
12}
13
14impl Hasher for IdentityHasher {
15    fn write(&mut self, bytes: &[u8]) {
16        if let Ok(s) = std::str::from_utf8(bytes) {
17            self.hash = s.parse::<u64>().expect("This should never fail");
18        }
19    }
20
21    fn finish(&self) -> u64 {
22        self.hash
23    }
24}
25
26impl Default for IdentityHasher {
27    fn default() -> Self {
28        IdentityHasher::new()
29    }
30}
31
32#[derive(Debug, Clone)]
33pub struct IdentityHasherBuilder;   
34
35impl BuildHasher for IdentityHasherBuilder {
36    type Hasher = IdentityHasher;
37
38    fn build_hasher(&self) -> Self::Hasher {
39        IdentityHasher::new()
40    }
41}