Skip to main content

ModuleLayout

Struct ModuleLayout 

Source
pub struct ModuleLayout { /* private fields */ }
Expand description

The shape of a modular Bloom filter.

This is the metadata a caller persists alongside the module words and hands back when reloading. It describes the filter as it was built, independently of how many modules a particular reader chooses to keep resident.

All modules are the same size. Equal sizing is what keeps the ratio of hashes to bits constant as modules are dropped, and therefore what keeps every rung of the ladder optimally configured.

Implementations§

Source§

impl ModuleLayout

Source

pub fn new( total_modules: u32, words_per_module: u32, hashes_per_module: u32, ) -> Result<Self, LayoutError>

Describes a filter of total_modules modules, each words_per_module 64-bit words wide, with hashes_per_module hashes set per key in each.

The filter’s effective hash count is total_modules * hashes_per_module.

Source

pub fn for_keys( estimated_keys: u64, target_false_positive_rate: f64, modules: u32, ) -> Result<Self, LayoutError>

Chooses a layout that holds estimated_keys keys at target_false_positive_rate when all modules modules are resident.

The hash count is rounded to a multiple of modules so that dropping a module removes a whole number of hashes. Bits are then sized to hit the requested rate exactly at that rounded hash count, which costs a fraction of a percent of memory against the unrounded optimum.

Source

pub fn monolithic(num_hashes: u32, words: usize) -> Result<Self, LayoutError>

Describes a monolithic fastbloom filter of words words using num_hashes hashes as a one-module filter.

Source

pub fn with_modules(&self, modules: u32) -> Result<Self, LayoutError>

Returns the same layout with modules modules.

Useful for costing a hypothetical residency without holding the bits.

Source

pub fn total_modules(&self) -> u32

Modules the filter was built with.

Source

pub fn words_per_module(&self) -> u32

64-bit words each module occupies.

Source

pub fn hashes_per_module(&self) -> u32

Hashes set per key within each module.

Source

pub fn bits_per_module(&self) -> u64

Bits each module occupies.

Source

pub fn bytes_per_module(&self) -> usize

Bytes each module occupies.

Source

pub fn total_words(&self) -> u64

Words the complete filter occupies.

Source

pub fn total_bytes(&self) -> usize

Bytes the complete filter occupies.

Source

pub fn total_hashes(&self) -> u32

Hashes set per key across the complete filter.

Source

pub fn bits_per_key(&self, keys: u64) -> f64

Bits per key the complete filter spends on keys keys.

Trait Implementations§

Source§

impl Clone for ModuleLayout

Source§

fn clone(&self) -> ModuleLayout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for ModuleLayout

Source§

impl Debug for ModuleLayout

Source§

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

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

impl Eq for ModuleLayout

Source§

impl Hash for ModuleLayout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ModuleLayout

Source§

fn eq(&self, other: &ModuleLayout) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ModuleLayout

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.