pub trait BinaryBloomFilter: BloomFilterwhere
Self::Set: BinaryBloomSet,{
// Required methods
fn union<Other>(&mut self, other: &Other)
where Other: BinaryBloomFilter<Set = Self::Set, Hasher = Self::Hasher>;
fn intersect<Other>(&mut self, other: &Other)
where Other: BinaryBloomFilter<Set = Self::Set, Hasher = Self::Hasher>;
}
Expand description
Trait for types which act as Bloom filters and support set operations.
Required Methods§
Sourcefn union<Other>(&mut self, other: &Other)
fn union<Other>(&mut self, other: &Other)
Inserts all values from other
into self
. other
and
self
must have the same BuildHasher
s for this to work,
and this cannot be checked in general (for instance,
RandomState
does
not implement PartialEq
).
§Example
use generic_bloom::{BloomFilter, BinaryBloomFilter, SimpleBloomFilter};
use bitvec::prelude::*;
let mut f1: SimpleBloomFilter<BitBox<usize, Lsb0>> = SimpleBloomFilter::new(10, 20);
f1.insert(&48);
f1.insert(&32);
let mut f2: SimpleBloomFilter<BitBox<usize, Lsb0>> =
SimpleBloomFilter::with_hashers(f1.hashers().clone(), 20);
f2.insert(&39);
assert!(f1.contains(&48));
assert!(f1.contains(&32));
// May fail if 39 is a false positive
assert!(!f1.contains(&39));
assert!(f2.contains(&39));
f1.union(&f2);
assert!(f1.contains(&48));
assert!(f1.contains(&32));
assert!(f1.contains(&39));
Sourcefn intersect<Other>(&mut self, other: &Other)
fn intersect<Other>(&mut self, other: &Other)
Keeps only values in self
which are also in
other
. other
and self
must have the same
BuildHasher
s for this to work, and this cannot be checked
in general (for instance,
RandomState
does
not implement PartialEq
).
§Example
use generic_bloom::{BloomFilter, BinaryBloomFilter, SimpleBloomFilter};
use bitvec::prelude::*;
let mut f1: SimpleBloomFilter<BitBox<usize, Lsb0>> = SimpleBloomFilter::new(10, 20);
f1.insert(&48);
f1.insert(&32);
let mut f2: SimpleBloomFilter<BitBox<usize, Lsb0>> =
SimpleBloomFilter::with_hashers(f1.hashers().clone(), 20);
f2.insert(&32);
f2.insert(&39);
assert!(f1.contains(&48));
assert!(f1.contains(&32));
// May fail if 39 is a false positive
assert!(!f1.contains(&39));
assert!(f2.contains(&39));
f1.intersect(&f2);
// May fail if 48 is a false positive
assert!(!f1.contains(&48));
assert!(f1.contains(&32));
// May fail if 39 is a false positive
assert!(!f1.contains(&39));
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.