bloom-bitset 11.1.0

Zero-dependency probabilistic data structures: 512-bit cache-line-blocked Bloom filter, 4-bit saturating Counting Bloom filter, and HyperLogLog cardinality estimator.
Documentation
use super::*;

/// Finalizes a 64-bit integer with SplitMix64 bit-mixing.
///
/// # Arguments
///
/// - `u64` - Input word.
///
/// # Returns
///
/// - `u64` - Well-mixed 64-bit hash.
#[inline(always)]
pub(crate) fn mix64(mut x: u64) -> u64 {
    x = x.wrapping_add(MIX_INC);
    x = (x ^ (x >> 30)).wrapping_mul(MIX_M1);
    x = (x ^ (x >> 27)).wrapping_mul(MIX_M2);
    x ^ (x >> 31)
}

/// Computes two independent 64-bit hashes `(h1, h2)` of `bytes` in a single pass.
///
/// # Arguments
///
/// - `&[u8]` - Input byte slice.
///
/// # Returns
///
/// - `(u64, u64)` - Two independent 64-bit digests for double-hashing and block selection.
#[inline(always)]
pub(crate) fn hash_pair(bytes: &[u8]) -> (u64, u64) {
    let mut h1: u64 = FNV_OFFSET ^ (bytes.len() as u64);
    let mut h2: u64 = FNV_OFFSET ^ SECOND_SEED;
    for &b in bytes {
        let v: u64 = u64::from(b);
        h1 ^= v;
        h1 = h1.wrapping_mul(FNV_PRIME);
        h2 = h2.wrapping_mul(FNV_PRIME) ^ v.rotate_left(13);
    }
    (mix64(h1), mix64(h2))
}

/// Computes two independent 64-bit digests for any [`Hash`] key.
///
/// # Arguments
///
/// - `&K` - Key reference implementing [`Hash`].
///
/// # Returns
///
/// - `(u64, u64)` - Two independent 64-bit hashes.
#[inline(always)]
pub fn hash_key_pair<K>(key: &K) -> (u64, u64)
where
    K: Hash + ?Sized,
{
    let mut hasher: DefaultHasher = DefaultHasher::new();
    key.hash(&mut hasher);
    let raw: u64 = hasher.finish();
    (mix64(raw), mix64(raw ^ SECOND_SEED))
}