Skip to main content

http_compress/xx_hash3_64/
impl.rs

1use super::*;
2
3impl Default for XxHash3_64 {
4    /// Builds a hasher that allocates nothing.
5    ///
6    /// # Returns
7    ///
8    /// - `Self` - The hasher.
9    fn default() -> Self {
10        Self {
11            inner: RawHasher::new(SecretBuffer::default()),
12        }
13    }
14}
15
16impl XxHash3_64 {
17    /// Returns the hasher that holds the secret, the seed and the buffer.
18    ///
19    /// # Returns
20    ///
21    /// - `&RawHasher<&'static [u8; DEFAULT_SECRET_LENGTH]>` - The inner hasher.
22    pub(crate) fn get_inner(&self) -> &RawHasher<&'static [u8; DEFAULT_SECRET_LENGTH]> {
23        &self.inner
24    }
25
26    /// Returns the inner hasher for mutation.
27    ///
28    /// # Returns
29    ///
30    /// - `&mut RawHasher<&'static [u8; DEFAULT_SECRET_LENGTH]>` - The inner hasher.
31    pub(crate) fn get_mut_inner(&mut self) -> &mut RawHasher<&'static [u8; DEFAULT_SECRET_LENGTH]> {
32        &mut self.inner
33    }
34}
35
36impl core::hash::Hasher for XxHash3_64 {
37    /// Feeds bytes into the hasher.
38    ///
39    /// # Arguments
40    ///
41    /// - `&[u8]` - The bytes to hash.
42    #[inline]
43    fn write(&mut self, bytes: &[u8]) {
44        self.get_mut_inner().write(bytes);
45    }
46
47    /// Reports the hash of everything written so far.
48    ///
49    /// # Returns
50    ///
51    /// - `u64` - The hash.
52    #[inline]
53    fn finish(&self) -> u64 {
54        self.get_inner().finish()
55    }
56}