pub struct HeavyHitters { /* private fields */ }Expand description
Top-k frequent-value sketch.
Implementations§
Source§impl HeavyHitters
impl HeavyHitters
Sourcepub fn new(name: impl Into<String>) -> HeavyHitters
pub fn new(name: impl Into<String>) -> HeavyHitters
Create a heavy-hitters index with the default CMS size and
[DEFAULT_K].
Sourcepub fn with_params(
name: impl Into<String>,
k: usize,
cms_width: usize,
cms_depth: usize,
) -> HeavyHitters
pub fn with_params( name: impl Into<String>, k: usize, cms_width: usize, cms_depth: usize, ) -> HeavyHitters
Fully-configurable constructor. k is the top-k size,
width/depth size the CMS (more width = tighter estimates).
Sourcepub fn observe(&mut self, key: &[u8])
pub fn observe(&mut self, key: &[u8])
Record one observation of key. Frequency estimate and top-k cache
are updated atomically — callers never see a stale state.
Sourcepub fn observe_n(&mut self, key: &[u8], count: u64)
pub fn observe_n(&mut self, key: &[u8], count: u64)
Record count observations of key. Bulk-load variant.
Sourcepub fn top_k(&self) -> Vec<(Vec<u8>, u64)>
pub fn top_k(&self) -> Vec<(Vec<u8>, u64)>
Return the current top-k entries, highest frequency first.
Sourcepub fn estimate(&self, key: &[u8]) -> u64
pub fn estimate(&self, key: &[u8]) -> u64
Estimate the frequency of a single key (never underestimates).
Sourcepub fn total_observed(&self) -> u64
pub fn total_observed(&self) -> u64
Total number of observations recorded (including keys outside the top-k).
Sourcepub fn relative_frequency(&self, key: &[u8]) -> f64
pub fn relative_frequency(&self, key: &[u8]) -> f64
Relative frequency of key as a fraction of all observations.
Returns 0.0 for an empty sketch.
Trait Implementations§
Source§impl IndexBase for HeavyHitters
impl IndexBase for HeavyHitters
Source§fn stats(&self) -> IndexStats
fn stats(&self) -> IndexStats
Current statistics (cardinality, estimated selectivity, memory).
Source§fn bloom(&self) -> Option<&BloomFilter>
fn bloom(&self) -> Option<&BloomFilter>
Optional bloom filter for fast negative lookups. Cross-structure
pruning relies on this.
Source§fn definitely_absent(&self, key_bytes: &[u8]) -> bool
fn definitely_absent(&self, key_bytes: &[u8]) -> bool
Returns
true iff the key is guaranteed to be absent from this
index. Default implementation consults IndexBase::bloom and falls
back to false when no bloom is available (meaning “don’t know —
caller must probe”). Read moreAuto Trait Implementations§
impl Freeze for HeavyHitters
impl RefUnwindSafe for HeavyHitters
impl Send for HeavyHitters
impl Sync for HeavyHitters
impl Unpin for HeavyHitters
impl UnsafeUnpin for HeavyHitters
impl UnwindSafe for HeavyHitters
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request