pub struct CountMinSketch { /* private fields */ }Expand description
Count-Min Sketch for approximate frequency queries.
Answers “how many times did item X appear?” with bounded over-estimation. Mergeable across shards: element-wise addition of tables.
Implementations§
Source§impl CountMinSketch
impl CountMinSketch
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a sketch with default parameters (width=1024, depth=4).
Error ≤ e/1024 ≈ 0.27% of total count, confidence ≥ 1 − e^(−4) ≈ 98.2%.
Sourcepub fn with_params(width: usize, depth: usize) -> Self
pub fn with_params(width: usize, depth: usize) -> Self
Create with custom width and depth.
width— number of counters per row (controls accuracy; larger = less error)depth— number of hash functions/rows (controls confidence; larger = higher)
Sourcepub fn estimate(&self, item: u64) -> u64
pub fn estimate(&self, item: u64) -> u64
Estimate the frequency of an item.
Returns the minimum count across all hash rows (point query).
This is always ≥ the true count and ≤ true_count + ε·N.
Sourcepub fn merge(&mut self, other: &CountMinSketch)
pub fn merge(&mut self, other: &CountMinSketch)
Merge another sketch (element-wise addition).
Both sketches must have the same width and depth.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Memory usage in bytes.
Sourcepub fn table_bytes(&self) -> Vec<u8> ⓘ
pub fn table_bytes(&self) -> Vec<u8> ⓘ
Serialize the table as a flat byte array (row-major, little-endian u64).
Sourcepub fn from_table_bytes(data: &[u8], width: usize, depth: usize) -> Self
pub fn from_table_bytes(data: &[u8], width: usize, depth: usize) -> Self
Reconstruct from serialized table bytes.
Trait Implementations§
Source§impl Debug for CountMinSketch
impl Debug for CountMinSketch
Auto Trait Implementations§
impl Freeze for CountMinSketch
impl RefUnwindSafe for CountMinSketch
impl Send for CountMinSketch
impl Sync for CountMinSketch
impl Unpin for CountMinSketch
impl UnsafeUnpin for CountMinSketch
impl UnwindSafe for CountMinSketch
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.