Struct xorf::Fuse16

source ·
pub struct Fuse16 {
    pub seed: u64,
    pub segment_length: usize,
    pub fingerprints: Box<[u16]>,
}
👎Deprecated since 0.8.0: prefer using a BinaryFuse16
Expand description

Xor filter using 16-bit fingerprints in a fuse graph. Requires less space than an Xor16.

A Fuse16 filter uses <18.202 bits per entry of the set is it constructed from, and has a false positive rate of <0.002%. As with other probabilistic filters, a higher number of entries decreases the bits per entry but increases the false positive rate.

A Fuse16 filter uses less space and is faster to construct than an Xor16 filter, but requires a large number of keys to be constructed. Experimentally, this number is somewhere >100_000. For smaller key sets, prefer the Xor16 filter. A Fuse16 filter may fail to be constructed.

A Fuse16 is constructed from a set of 64-bit unsigned integers and is immutable.

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

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

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

// bits per entry
let bpe = (filter.len() as f64) * 16.0 / (SAMPLE_SIZE as f64);
assert!(bpe < 18.202, "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.0025, "False positive rate is {}", fp_rate);

Serializing and deserializing Fuse16 filters can be enabled with the serde feature (or [bincode] for bincode).

Fields§

§seed: u64
👎Deprecated since 0.8.0: prefer using a BinaryFuse16

The seed for the filter

§segment_length: usize
👎Deprecated since 0.8.0: prefer using a BinaryFuse16

The number of blocks in the filter

§fingerprints: Box<[u16]>
👎Deprecated since 0.8.0: prefer using a BinaryFuse16

The fingerprints for the filter

Implementations§

source§

impl Fuse16

source

pub fn try_from_iterator<T>(keys: T) -> Result<Self, &'static str>
where T: ExactSizeIterator<Item = u64> + Clone,

Try to construct the filter from a key iterator. Can be used directly if you don’t have a contiguous array of u64 keys.

Note: the iterator will be iterated over multiple times while building the filter. If using a hash function to map the key, it may be cheaper just to create a scratch array of hashed keys that you pass in.

Trait Implementations§

source§

impl Clone for Fuse16

source§

fn clone(&self) -> Fuse16

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Fuse16

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Filter<u64> for Fuse16

source§

fn contains(&self, key: &u64) -> bool

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

source§

fn len(&self) -> usize

Returns the number of fingerprints in the filter.
source§

impl TryFrom<&[u64]> for Fuse16

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(keys: &[u64]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Vec<u64>> for Fuse16

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(v: &Vec<u64>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Vec<u64>> for Fuse16

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(v: Vec<u64>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V