summaryrefslogtreecommitdiffstats
path: root/vendor/odht/src/unhash.rs
blob: 2d1f905ebf24ac98570e0567106b08291b87efb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use crate::HashFn;
use std::convert::TryInto;

/// A hash function that simply takes the last 4 bytes of a given key as the
/// hash value.
#[derive(Eq, PartialEq)]
pub struct UnHashFn;

impl HashFn for UnHashFn {
    #[inline]
    fn hash(bytes: &[u8]) -> u32 {
        let len = bytes.len();
        u32::from_le_bytes(bytes[len - 4..].try_into().unwrap())
    }
}