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
81
82
83
84
85
86
87
88
89
90
91
92
use seahash;
pub use seahash::{SeaHasher as SeaHasher64, hash as hash64, hash_seeded as hash_with_seeds};
use hasher::{FastHash, FastHasher, StreamHasher};
pub struct SeaHash {}
impl FastHash for SeaHash {
type Value = u64;
type Seed = (u64, u64, u64, u64);
#[inline]
fn hash<T: AsRef<[u8]>>(bytes: &T) -> u64 {
seahash::hash(bytes.as_ref())
}
#[inline]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: &T, seed: (u64, u64, u64, u64)) -> u64 {
seahash::hash_seeded(bytes.as_ref(), seed.0, seed.1, seed.2, seed.3)
}
}
impl_fasthash!(SeaHasher64, SeaHash);
impl FastHasher for SeaHasher64 {
type Seed = (u64, u64, u64, u64);
#[inline]
fn new() -> Self {
SeaHasher64::new()
}
#[inline]
fn with_seed(seed: Self::Seed) -> Self {
SeaHasher64::with_seeds(seed.0, seed.1, seed.2, seed.3)
}
}
impl StreamHasher for SeaHasher64 {}
#[cfg(test)]
mod tests {
use std::hash::Hasher;
use hasher::FastHash;
use super::*;
#[test]
fn test_seahash64() {
assert_eq!(SeaHash::hash(b"hello"), 153251464476911497);
assert_eq!(SeaHash::hash_with_seed(b"hello", (12, 34, 56, 78)),
3117749726954423822);
assert_eq!(SeaHash::hash(b"helloworld"), 9532038143498849405);
let mut h = SeaHasher64::new();
h.write(b"hello");
assert_eq!(h.finish(), 11332652286493249837);
h.write(b"world");
assert_eq!(h.finish(), 4332207266370068704);
}
}