Crate ofilter

source ·
Expand description

OFilter is a fast thread-safe Bloom filter.

OFilter icon

§Examples

Basic Bloom filter:

use ofilter::Bloom;

let mut filter: Bloom<usize> = Bloom::new(100);
filter.set(&42);
assert!(filter.check(&42));

Thread-safe version:

use ofilter::SyncBloom;

// does not need to be `mut`
let filter: SyncBloom<usize> = SyncBloom::new(100);
filter.set(&42);
assert!(filter.check(&42));

Streaming Bloom filter:

use ofilter::Stream;
use std::collections::HashSet;

let mut set: HashSet<usize> = HashSet::new();
let mut filter: Stream<usize> = Stream::new(100);
for i in 0..1_000 {
    for j in 0..1_000 {
        let item = i * 1_000 + j;
        filter.set(&item);
        set.insert(item);
    }
    set.retain(|x| filter.check(x));
}
println!("{}", set.len());
// Out of 1 million entries, only a few hundreds left
assert!(set.len() < 500);

Thread-safe streaming version:

use ofilter::SyncStream;
use std::collections::HashSet;

let mut set: HashSet<usize> = HashSet::new();
// does not need to be `mut`
let filter: SyncStream<usize> = SyncStream::new(100);
for i in 0..1_000 {
    for j in 0..1_000 {
        let item = i * 1_000 + j;
        filter.set(&item);
        set.insert(item);
    }
    set.retain(|x| filter.check(x));
}
println!("{}", set.len());
// Out of 1 million entries, only a few hundreds left
assert!(set.len() < 500);

Structs§

Constants§