turbo_tasks_hash/
xxh3_hash64.rs1use std::hash::Hasher;
2
3use twox_hash::XxHash3_64;
4
5use crate::{DeterministicHash, DeterministicHasher};
6
7pub fn hash_xxh3_hash64<T: DeterministicHash>(input: T) -> u64 {
9 let mut hasher = Xxh3Hash64Hasher::new();
10 input.deterministic_hash(&mut hasher);
11 hasher.finish()
12}
13
14pub struct Xxh3Hash64Hasher(XxHash3_64);
16
17impl Xxh3Hash64Hasher {
18 pub fn new() -> Self {
20 Self(XxHash3_64::with_seed(0))
21 }
22
23 pub fn write_value<T: DeterministicHash>(&mut self, input: T) {
26 input.deterministic_hash(self);
27 }
28
29 pub fn write_ref<T: DeterministicHash>(&mut self, input: &T) {
32 input.deterministic_hash(self);
33 }
34
35 pub fn finish(&self) -> u64 {
37 self.0.finish()
38 }
39}
40
41impl DeterministicHasher for Xxh3Hash64Hasher {
42 fn finish(&self) -> u64 {
43 self.0.finish()
44 }
45
46 fn write_bytes(&mut self, bytes: &[u8]) {
47 self.0.write(bytes);
48 }
49}
50
51impl Default for Xxh3Hash64Hasher {
52 fn default() -> Self {
53 Self::new()
54 }
55}