bloom-sol 0.0.3

Counting bloom filter, aimed for solana
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::bloom_sol::struct_def::CountingBloomFilter;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

impl CountingBloomFilter {
    /// Computes the hash indices for a given item.
    pub fn get_hash_indices<T: Hash>(&self, item: &T) -> Vec<usize> {
        (0..self.num_hashes)
            .map(|i| {
                let mut hasher = DefaultHasher::new();
                item.hash(&mut hasher);
                // Seed with the hash index to simulate multiple hash functions.
                hasher.write_u32(i as u32);
                (hasher.finish() % self.size as u64) as usize
            })
            .collect()
    }
}