Skip to main content

BloomFilter

Struct BloomFilter 

Source
pub struct BloomFilter<const N: usize, const K: usize = 2> { /* private fields */ }
Expand description

A Bloom filter, parameterized by number of u64 segments N and number of hash functions K.

N should be based on how much you plan to insert into the filter. N * 64 should be at least the number of items you plan to insert.

K if how little you can tolerate false positives. 2, the default, should work for most uses. Increase K to reduce false positives, at a pretty large compute cost.

§Examples

use bevy_utils::BloomFilter;

let mut filter = BloomFilter::<1>::new();
filter.insert(&"hello");
assert!(filter.contains(&"hello"));
assert!(!filter.contains(&"world"));

Implementations§

Source§

impl<const N: usize, const K: usize> BloomFilter<N, K>

Source

pub const fn new() -> Self

Creates a new, empty filter.

Source

pub fn insert(&mut self, item: &impl Hash)

Inserts a value into the filter.

Source

pub fn contains(&self, item: &impl Hash) -> bool

Checks if the filter might contain the value.

Source

pub fn check_insert(&mut self, item: &impl Hash) -> bool

Combined Self::contains and Self::insert.

Returns true if the value was already in the filter. Adds the value to the filter if it was not already present.

Trait Implementations§

Source§

impl<const N: usize, const K: usize> Clone for BloomFilter<N, K>

Source§

fn clone(&self) -> BloomFilter<N, K>

Returns a duplicate 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<const N: usize, const K: usize> Debug for BloomFilter<N, K>

Source§

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

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

impl<const N: usize, const K: usize> Default for BloomFilter<N, K>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize, const K: usize> Copy for BloomFilter<N, K>

Auto Trait Implementations§

§

impl<const N: usize, const K: usize> Freeze for BloomFilter<N, K>

§

impl<const N: usize, const K: usize> RefUnwindSafe for BloomFilter<N, K>

§

impl<const N: usize, const K: usize> Send for BloomFilter<N, K>

§

impl<const N: usize, const K: usize> Sync for BloomFilter<N, K>

§

impl<const N: usize, const K: usize> Unpin for BloomFilter<N, K>

§

impl<const N: usize, const K: usize> UnsafeUnpin for BloomFilter<N, K>

§

impl<const N: usize, const K: usize> UnwindSafe for BloomFilter<N, K>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.