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
impl ModuleLayout
Sourcepub fn new(
total_modules: u32,
words_per_module: u32,
hashes_per_module: u32,
) -> Result<Self, LayoutError>
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.
Sourcepub fn for_keys(
estimated_keys: u64,
target_false_positive_rate: f64,
modules: u32,
) -> Result<Self, LayoutError>
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.
Sourcepub fn monolithic(num_hashes: u32, words: usize) -> Result<Self, LayoutError>
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.
Sourcepub fn with_modules(&self, modules: u32) -> Result<Self, LayoutError>
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.
Sourcepub fn total_modules(&self) -> u32
pub fn total_modules(&self) -> u32
Modules the filter was built with.
Sourcepub fn words_per_module(&self) -> u32
pub fn words_per_module(&self) -> u32
64-bit words each module occupies.
Sourcepub fn hashes_per_module(&self) -> u32
pub fn hashes_per_module(&self) -> u32
Hashes set per key within each module.
Sourcepub fn bits_per_module(&self) -> u64
pub fn bits_per_module(&self) -> u64
Bits each module occupies.
Sourcepub fn bytes_per_module(&self) -> usize
pub fn bytes_per_module(&self) -> usize
Bytes each module occupies.
Sourcepub fn total_words(&self) -> u64
pub fn total_words(&self) -> u64
Words the complete filter occupies.
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Bytes the complete filter occupies.
Sourcepub fn total_hashes(&self) -> u32
pub fn total_hashes(&self) -> u32
Hashes set per key across the complete filter.
Sourcepub fn bits_per_key(&self, keys: u64) -> f64
pub fn bits_per_key(&self, keys: u64) -> f64
Bits per key the complete filter spends on keys keys.