pub struct BloomParams {
pub byte_size: usize,
pub k_hashes: usize,
}
Expand description
Optimal bloom parameters for some false positive rate at a maximum number of elements added, or for some byte size with target element count, etc.
Captures the bloom filter byte size needed as well as the number of hash function evaluations needed per item to insert.
To construct this, use
BloomParams::new_from_fpr
for constructing this from a given false positive rate and desired capacity,- similarly
BloomParams::new_from_fpr_po2
, but with power-of-two sizes, BloomParams::new_from_size
for constructing from desired size and capacity.
Fields§
§byte_size: usize
size of the bloom filter in bytes, non-zero
k_hashes: usize
hashing functions used/number of bits set per element, non-zero
Implementations§
Source§impl BloomParams
impl BloomParams
Sourcepub fn new_from_fpr(n_elems: u64, fpr: f64) -> Self
pub fn new_from_fpr(n_elems: u64, fpr: f64) -> Self
Construct optimal bloom parameters for given number maximum elements that the bloom filter will hold as well as the approximate false positive rate it should have at that capacity.
n_elems
must be non-zero, and fpr
must be between 0 and 1, exclusive.
This will generate non-power-of-two sizes for bloom filters.
For a variant that power-of-two (po2) sizes, see BloomParams::new_from_fpr_po2
.
§Example
use deterministic_bloom::common::BloomParams;
// figure out bloom parameters for 47 elements with a one in a billion false positive rate:
let params = BloomParams::new_from_fpr(47, 1.0 / 1_000_000_000.0);
assert_eq!(params, BloomParams {
byte_size: 254,
k_hashes: 30,
})
Sourcepub fn new_from_fpr_po2(n_elems: u64, fpr: f64) -> Self
pub fn new_from_fpr_po2(n_elems: u64, fpr: f64) -> Self
Construct optimal bloom parameters for given capacity n_elems
and false positive rate,
where the target size will always be a power-of-two.
n_elems
must be non-zero, and fpr
must be between 0.0 and 1.0, exclusive.
It is often desirable to go for power-of-two sizes, since that simplifies generating bit indices by not requiring rejection sampling.
§Example
use deterministic_bloom::common::BloomParams;
// Generate some bloom parameters
let params = BloomParams::new_from_fpr_po2(1_000_000, 0.0001);
assert_eq!(params.byte_size, params.byte_size.next_power_of_two());
Sourcepub fn new_from_size(byte_size: usize, n_elems: u64) -> Self
pub fn new_from_size(byte_size: usize, n_elems: u64) -> Self
Construct optimal bloom parameters for given bloom filter byte_size
and capacity n_elems
.
Sourcepub fn false_positive_rate_at(&self, n_elems: u64) -> f64
pub fn false_positive_rate_at(&self, n_elems: u64) -> f64
Compute the approximate false positive rate at n_elems
.
n_elems
must be non-zero.
Returns the false positive rate as a number between 0.0 and 1.0.
Trait Implementations§
Source§impl Clone for BloomParams
impl Clone for BloomParams
Source§fn clone(&self) -> BloomParams
fn clone(&self) -> BloomParams
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for BloomParams
impl Debug for BloomParams
Source§impl Ord for BloomParams
impl Ord for BloomParams
Source§fn cmp(&self, other: &BloomParams) -> Ordering
fn cmp(&self, other: &BloomParams) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for BloomParams
impl PartialEq for BloomParams
Source§impl PartialOrd for BloomParams
impl PartialOrd for BloomParams
impl Eq for BloomParams
impl StructuralPartialEq for BloomParams
Auto Trait Implementations§
impl Freeze for BloomParams
impl RefUnwindSafe for BloomParams
impl Send for BloomParams
impl Sync for BloomParams
impl Unpin for BloomParams
impl UnwindSafe for BloomParams
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.