bloomz 0.1.0

A fast, flexible Bloom filter library for Rust with parallel operations support
Documentation
use core::hash::{BuildHasher, Hash, Hasher};

/// Generates two hash values from a single item using a `BuildHasher`.
/// This is a form of double hashing, useful for bloom filters.
/// The second hash is generated by hashing the first hash and the item itself.
pub fn hash2<T: Hash, S: BuildHasher>(state: &S, item: &T) -> (u64, u64) {
    let v1 = state.hash_one(item);

    let mut h2 = state.build_hasher();
    v1.hash(&mut h2);
    item.hash(&mut h2);
    let mut v2 = h2.finish();

    // ensure v2 is odd to avoid pathological cycles in some corner cases
    if v2 & 1 == 0 {
        v2 |= 1;
    }

    (v1, v2)
}