Struct xorf::BinaryFuse32

source ·
pub struct BinaryFuse32 {
    pub fingerprints: Box<[u32]>,
    /* private fields */
}
Expand description

A BinaryFuse32 filter is an Xor-like filter with 32-bit fingerprints arranged in a binary-partitioned fuse graph. BinaryFuse32s are similar to Fuse32s, but their construction is faster, uses less memory, and is more likely to succeed.

A BinaryFuse32 filter uses ≈36 bits per entry of the set is it constructed from, and has a false positive rate of effectively zero (1/2^32 =~ 1/4 billion). As with other probabilistic filters, a higher number of entries decreases the bits per entry but increases the false positive rate.

A BinaryFuse32 is constructed from a set of 64-bit unsigned integers and is immutable. Construction may fail, but usually only if there are duplicate keys.

use xorf::{Filter, BinaryFuse32};
use core::convert::TryFrom;

const SAMPLE_SIZE: usize = 1_000_000;
let keys: Vec<u64> = (0..SAMPLE_SIZE).map(|_| rng.gen()).collect();
let filter = BinaryFuse32::try_from(&keys).unwrap();

// no false negatives
for key in keys {
    assert!(filter.contains(&key));
}

// bits per entry
let bpe = (filter.len() as f64) * 32.0 / (SAMPLE_SIZE as f64);
assert!(bpe < 36.2, "Bits per entry is {}", bpe);

// false positive rate
let false_positives: usize = (0..SAMPLE_SIZE)
    .map(|_| rng.gen())
    .filter(|n| filter.contains(n))
    .count();
let fp_rate: f64 = (false_positives * 100) as f64 / SAMPLE_SIZE as f64;
assert!(fp_rate < 0.0000000000000001, "False positive rate is {}", fp_rate);

Serializing and deserializing BinaryFuse32 filters can be enabled with the serde feature.

Fields§

§fingerprints: Box<[u32]>

The fingerprints for the filter

Trait Implementations§

Formats the value using the given formatter. Read more

Returns true if the filter contains the specified key. Has a false positive rate of <0.4%. Has no false negatives.

Returns the number of fingerprints in the filter.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.