pub struct HyperLogLog { /* private fields */ }Expand description
HyperLogLog++ for cardinality estimation with sparse/dense hybrid
Standard error: 1.04 / sqrt(m) where m = 2^precision
- precision=10: m=1024, error ≈ 3.25%
- precision=12: m=4096, error ≈ 1.63%
- precision=14: m=16384, error ≈ 0.81%
Gap #2 Implementation: Starts in sparse mode for memory efficiency, automatically converts to dense mode when cardinality exceeds threshold.
Implementations§
Source§impl HyperLogLog
impl HyperLogLog
Sourcepub fn new(precision: u8) -> Self
pub fn new(precision: u8) -> Self
Create with specified precision (starts in sparse mode)
§Arguments
precision- Number of bits for register selection (4-18)- p=10: 1KB memory (dense), ~3.25% error
- p=12: 4KB memory (dense), ~1.63% error
- p=14: 16KB memory (dense), ~0.81% error
Gap #2: Starts in sparse mode for memory efficiency
Sourcepub fn new_dense(precision: u8) -> Self
pub fn new_dense(precision: u8) -> Self
Create with specified precision, forcing dense mode from start Use this when you know cardinality will be high
Sourcepub fn default_precision() -> Self
pub fn default_precision() -> Self
Create with default precision (14 = 0.81% error)
Sourcepub fn add_hash(&mut self, hash: u64)
pub fn add_hash(&mut self, hash: u64)
Add a pre-hashed value (for when you already have the hash)
Sourcepub fn cardinality(&self) -> u64
pub fn cardinality(&self) -> u64
Estimate cardinality with HLL++ bias correction
Gap #6 Fix: Implements proper HLL++ bias correction for small cardinalities using empirical bias estimates from the HyperLogLog++ paper.
Sourcepub fn merge(&mut self, other: &HyperLogLog)
pub fn merge(&mut self, other: &HyperLogLog)
Merge another HyperLogLog into this one
Critical for time bucket rollups Gap #2: Handles all combinations of sparse/dense merges efficiently
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Get memory usage in bytes
Sourcepub fn standard_error(&self) -> f64
pub fn standard_error(&self) -> f64
Get standard error percentage
Sourcepub fn non_zero_count(&self) -> usize
pub fn non_zero_count(&self) -> usize
Get number of non-zero registers (useful for debugging sparse mode)
Trait Implementations§
Source§impl Clone for HyperLogLog
impl Clone for HyperLogLog
Source§fn clone(&self) -> HyperLogLog
fn clone(&self) -> HyperLogLog
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HyperLogLog
impl Debug for HyperLogLog
Auto Trait Implementations§
impl Freeze for HyperLogLog
impl RefUnwindSafe for HyperLogLog
impl Send for HyperLogLog
impl Sync for HyperLogLog
impl Unpin for HyperLogLog
impl UnsafeUnpin for HyperLogLog
impl UnwindSafe for HyperLogLog
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more