1use crate::alloc::HashMap;
4
5use core::hash::{BuildHasher, Hasher};
6
7const SEED: u64 = 18446744073709551557u64;
8
9#[doc(inline)]
10pub use rune_core::hash::{Hash, IntoHash, ParametersBuilder, ToTypeHash, TooManyParameters};
11
12pub(crate) type Map<T> = HashMap<Hash, T, HashBuildHasher>;
14
15#[derive(Default, Clone, Copy)]
16pub(crate) struct HashBuildHasher;
17
18impl BuildHasher for HashBuildHasher {
19 type Hasher = HashHasher;
20
21 #[inline]
22 fn build_hasher(&self) -> Self::Hasher {
23 HashHasher(SEED)
24 }
25}
26
27pub(crate) struct HashHasher(u64);
28
29impl Hasher for HashHasher {
30 #[inline]
31 fn finish(&self) -> u64 {
32 self.0
33 }
34
35 #[inline]
36 fn write(&mut self, _: &[u8]) {
37 panic!("Hash hashers assume that 64-bit hashes are already random")
38 }
39
40 #[inline]
41 fn write_u64(&mut self, hash: u64) {
42 self.0 ^= hash;
43 }
44}