highway/
traits.rs

1/// The common set of methods for hashing data.
2pub trait HighwayHash: Sized {
3    /// Convenience function for hashing all data in a single call and receiving a 64bit hash.
4    /// Results are equivalent to appending the data manually.
5    fn hash64(mut self, data: &[u8]) -> u64 {
6        self.append(data);
7        self.finalize64()
8    }
9
10    /// Convenience function for hashing all data in a single call and receiving a 128bit hash.
11    /// Results are equivalent to appending the data manually.
12    fn hash128(mut self, data: &[u8]) -> [u64; 2] {
13        self.append(data);
14        self.finalize128()
15    }
16
17    /// Convenience function for hashing all data in a single call and receiving a 256bit hash.
18    /// Results are equivalent to appending the data manually.
19    fn hash256(mut self, data: &[u8]) -> [u64; 4] {
20        self.append(data);
21        self.finalize256()
22    }
23
24    /// Adds data to be hashed. If it is important, the performance characteristics of this
25    /// function differs depending on the amount of data previously hashed and the amount of
26    /// data to be hashed. For instance, if one appends 50, 1 byte slices then appending the 32nd
27    /// byte will have a performance outlier as the internal 32 byte block is complete and internally processed.
28    fn append(&mut self, data: &[u8]);
29
30    /// Consumes the hasher to return the 64bit hash
31    fn finalize64(self) -> u64;
32
33    /// Consumes the hasher to return the 128bit hash
34    fn finalize128(self) -> [u64; 2];
35
36    /// Consumes the hasher to return the 256bit hash
37    fn finalize256(self) -> [u64; 4];
38
39    /// Serialize the hasher state to be persisted or resumed by another hasher
40    /// 
41    /// Note: At this time, the checkpoint format and API should be considered experimental.
42    /// The format may change in future versions.
43    fn checkpoint(&self) -> [u8; 164];
44}