#[inline]
pub fn selector_hash(bytes: &[u8]) -> u32 {
let mut hash: u32 = 2_166_136_261; for &byte in bytes {
hash ^= byte as u32;
hash = hash.wrapping_mul(16_777_619); }
hash
}
#[inline]
pub fn class_bloom_bit(class_bytes: &[u8]) -> u64 {
1u64 << (selector_hash(class_bytes) % 64)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hash_deterministic() {
assert_eq!(selector_hash(b"hello"), selector_hash(b"hello"));
}
#[test]
fn hash_different_inputs() {
assert_ne!(selector_hash(b"hello"), selector_hash(b"world"));
}
#[test]
fn hash_empty() {
assert_eq!(selector_hash(b""), 2_166_136_261);
}
#[test]
fn bloom_bit_single_bit() {
let bit = class_bloom_bit(b"content");
assert_eq!(bit.count_ones(), 1);
}
#[test]
fn bloom_bit_in_range() {
let bit = class_bloom_bit(b"test");
assert!(bit != 0);
assert!(bit.is_power_of_two());
}
}