pub struct SpaceSaving<T: Hash + Eq + Clone + Debug> { /* private fields */ }Available on crate features
frequency and std only.Expand description
Space-Saving algorithm for finding frequent items
The Space-Saving algorithm maintains a summary of the k most frequent items with the following guarantees:
- Any item with true frequency > n/k is guaranteed to be in the summary
- The maximum overcount error for any item is at most n/k
§Example
use flowstats::frequency::SpaceSaving;
use flowstats::traits::HeavyHitters;
let mut ss = SpaceSaving::new(10); // Track top 10
// Add some items
for _ in 0..100 { ss.add("apple"); }
for _ in 0..50 { ss.add("banana"); }
for _ in 0..25 { ss.add("cherry"); }
for _ in 0..10 { ss.add("date"); }
// Get top 3 items
let top = ss.top_k(3);
println!("Top items: {:?}", top);Implementations§
Source§impl<T: Hash + Eq + Clone + Debug> SpaceSaving<T>
impl<T: Hash + Eq + Clone + Debug> SpaceSaving<T>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new Space-Saving structure with the given capacity
§Arguments
capacity- Maximum number of items to track (k)
Sourcepub fn num_tracked(&self) -> usize
pub fn num_tracked(&self) -> usize
Get the number of distinct items currently tracked
Sourcepub fn total_count(&self) -> u64
pub fn total_count(&self) -> u64
Get the total count
Sourcepub fn guaranteed_count(&self, item: &T) -> u64
pub fn guaranteed_count(&self, item: &T) -> u64
Get guaranteed minimum count for an item
Returns (count - error), which is guaranteed to be at most the true count.
Trait Implementations§
Source§impl<T: Clone + Hash + Eq + Clone + Debug> Clone for SpaceSaving<T>
impl<T: Clone + Hash + Eq + Clone + Debug> Clone for SpaceSaving<T>
Source§fn clone(&self) -> SpaceSaving<T>
fn clone(&self) -> SpaceSaving<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Hash + Eq + Clone + Debug> FrequencySketch for SpaceSaving<T>
impl<T: Hash + Eq + Clone + Debug> FrequencySketch for SpaceSaving<T>
Source§impl<T: Hash + Eq + Clone + Debug> HeavyHitters for SpaceSaving<T>
impl<T: Hash + Eq + Clone + Debug> HeavyHitters for SpaceSaving<T>
Auto Trait Implementations§
impl<T> Freeze for SpaceSaving<T>
impl<T> RefUnwindSafe for SpaceSaving<T>where
T: RefUnwindSafe,
impl<T> Send for SpaceSaving<T>where
T: Send,
impl<T> Sync for SpaceSaving<T>where
T: Sync,
impl<T> Unpin for SpaceSaving<T>where
T: Unpin,
impl<T> UnwindSafe for SpaceSaving<T>where
T: UnwindSafe,
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