-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhasher.rs
80 lines (69 loc) · 1.81 KB
/
hasher.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
pub trait Hasher: Default {
type Hash: Hash;
fn write(&mut self, buf: &[u8]);
fn finish(self) -> Self::Hash;
}
pub trait Hash: PartialEq + Eq + PartialOrd + Ord + Send + Sync + Copy {}
impl<T> Hash for T where T: PartialEq + Eq + PartialOrd + Ord + Send + Sync + Copy {}
#[cfg(feature = "build-bin")]
impl Hasher for ahash::AHasher {
type Hash = u64;
fn write(&mut self, buf: &[u8]) {
std::hash::Hasher::write(self, buf);
}
fn finish(self) -> Self::Hash {
std::hash::Hasher::finish(&self)
}
}
#[cfg(feature = "build-bin")]
impl Hasher for highway::HighwayHasher {
type Hash = [u64; 4];
fn write(&mut self, buf: &[u8]) {
use highway::HighwayHash;
self.append(buf);
}
fn finish(self) -> Self::Hash {
use highway::HighwayHash;
self.finalize256()
}
}
#[cfg(feature = "build-bin")]
impl Hasher for metrohash::MetroHash128 {
type Hash = (u64, u64);
fn write(&mut self, buf: &[u8]) {
std::hash::Hasher::write(self, buf);
}
fn finish(self) -> Self::Hash {
self.finish128()
}
}
#[cfg(feature = "build-bin")]
impl Hasher for seahash::SeaHasher {
type Hash = u64;
fn write(&mut self, buf: &[u8]) {
std::hash::Hasher::write(self, buf);
}
fn finish(self) -> Self::Hash {
std::hash::Hasher::finish(&self)
}
}
#[cfg(feature = "build-bin")]
impl Hasher for twox_hash::xxhash3_128::Hasher {
type Hash = u128;
fn write(&mut self, buf: &[u8]) {
self.write(buf);
}
fn finish(self) -> Self::Hash {
self.finish_128()
}
}
#[cfg(feature = "build-bin")]
impl Hasher for blake3::Hasher {
type Hash = [u8; 32];
fn write(&mut self, buf: &[u8]) {
self.update(buf);
}
fn finish(self) -> Self::Hash {
self.finalize().into()
}
}