/rust/registry/src/index.crates.io-1949cf8c6b5b557f/phf_shared-0.14.0/src/hasher.rs
Line | Count | Source |
1 | | use core::hash::Hasher; |
2 | | use siphasher::sip128::{Hash128, Hasher128}; |
3 | | |
4 | | pub struct PortableSipHasher<H> { |
5 | | inner: H, |
6 | | } |
7 | | |
8 | | impl<H> PortableSipHasher<H> { |
9 | 1.94M | pub fn new(inner: H) -> Self { |
10 | 1.94M | Self { inner } |
11 | 1.94M | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<siphasher::sip128::SipHasher13>>::new Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_>>::new <phf_shared::hasher::PortableSipHasher<siphasher::sip128::SipHasher13>>::new Line | Count | Source | 9 | 1.94M | pub fn new(inner: H) -> Self { | 10 | 1.94M | Self { inner } | 11 | 1.94M | } |
Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_>>::new |
12 | | } |
13 | | |
14 | | impl<H: Hasher> Hasher for PortableSipHasher<H> { |
15 | 0 | fn finish(&self) -> u64 { |
16 | 0 | self.inner.finish() |
17 | 0 | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::finish Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::finish |
18 | | |
19 | 1.94M | fn write(&mut self, bytes: &[u8]) { |
20 | 1.94M | self.inner.write(bytes) |
21 | 1.94M | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<siphasher::sip128::SipHasher13> as core::hash::Hasher>::write Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write <phf_shared::hasher::PortableSipHasher<siphasher::sip128::SipHasher13> as core::hash::Hasher>::write Line | Count | Source | 19 | 1.94M | fn write(&mut self, bytes: &[u8]) { | 20 | 1.94M | self.inner.write(bytes) | 21 | 1.94M | } |
Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write |
22 | | |
23 | 0 | fn write_u8(&mut self, i: u8) { |
24 | 0 | self.inner.write_u8(i) |
25 | 0 | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u8 Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u8 |
26 | | |
27 | | // `SipHasher` invokes `to_le` on integers before encoding them, treating them as byte arrays |
28 | | // rather than values, which is not the right interpretation for us; fix that by flipping |
29 | | // endianness twice. |
30 | 0 | fn write_u16(&mut self, i: u16) { |
31 | 0 | self.inner.write_u16(i.to_le()); |
32 | 0 | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u16 Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u16 |
33 | 0 | fn write_u32(&mut self, i: u32) { |
34 | 0 | self.inner.write_u32(i.to_le()); |
35 | 0 | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u32 Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u32 |
36 | 1.94M | fn write_u64(&mut self, i: u64) { |
37 | 1.94M | self.inner.write_u64(i.to_le()); |
38 | 1.94M | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<siphasher::sip128::SipHasher13> as core::hash::Hasher>::write_u64 Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u64 <phf_shared::hasher::PortableSipHasher<siphasher::sip128::SipHasher13> as core::hash::Hasher>::write_u64 Line | Count | Source | 36 | 1.94M | fn write_u64(&mut self, i: u64) { | 37 | 1.94M | self.inner.write_u64(i.to_le()); | 38 | 1.94M | } |
Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u64 |
39 | 0 | fn write_u128(&mut self, i: u128) { |
40 | 0 | self.inner.write_u128(i.to_le()); |
41 | 0 | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u128 Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_u128 |
42 | | |
43 | 0 | fn write_usize(&mut self, i: usize) { |
44 | 0 | self.inner.write_u64((i as u64).to_le()); |
45 | 0 | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_usize Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_usize |
46 | | // The default `write_isize` implementation casts to `usize` first, so we end up with |
47 | | // `i as usize as u64`, which is different on 32-bit and 64-bit architectures: |
48 | | // |
49 | | // 32-bit: `-1` -> `2^32 - 1` -> `2^32 - 1` |
50 | | // 64-bit: `-1` -> `2^64 - 1` -> `2^64 - 1` |
51 | 0 | fn write_isize(&mut self, i: isize) { |
52 | 0 | self.inner.write_u64((i as u64).to_le()); |
53 | 0 | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_isize Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as core::hash::Hasher>::write_isize |
54 | | |
55 | | // Fixed-size signed integers correctly forward to unsigned implementations. |
56 | | } |
57 | | |
58 | | impl<H: Hasher128> Hasher128 for PortableSipHasher<H> { |
59 | 1.94M | fn finish128(&self) -> Hash128 { |
60 | 1.94M | self.inner.finish128() |
61 | 1.94M | } Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<siphasher::sip128::SipHasher13> as siphasher::sip128::Hasher128>::finish128 Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as siphasher::sip128::Hasher128>::finish128 <phf_shared::hasher::PortableSipHasher<siphasher::sip128::SipHasher13> as siphasher::sip128::Hasher128>::finish128 Line | Count | Source | 59 | 1.94M | fn finish128(&self) -> Hash128 { | 60 | 1.94M | self.inner.finish128() | 61 | 1.94M | } |
Unexecuted instantiation: <phf_shared::hasher::PortableSipHasher<_> as siphasher::sip128::Hasher128>::finish128 |
62 | | } |