Struct streaming_algorithms::Top [−][src]
pub struct Top<A: Hash + Eq + Clone, C: Ord + New + for<'a> UnionAssign<&'a C> + Intersect> { /* fields omitted */ }
This probabilistic data structure tracks the n top keys given a stream of (key,value) tuples, ordered by the sum of the values for each key (the "aggregated value"). It uses only O(n) space.
Its implementation is two parts:
- a doubly linked hashmap, mapping the top
nkeys to their aggregated values, and ordered by their aggregated values. This is used to keep a more precise track of the aggregated value of the topnkeys, and reduce collisions in the count-min sketch. - a count-min sketch to track all of the keys outside the top
n. This data structure is also known as a counting Bloom filter. It uses conservative updating for increased accuracy.
The algorithm is as follows:
while a key and value from the input stream arrive:
if H[key] exists
increment aggregated value associated with H[key]
elsif number of items in H < k
put H[key] into map with its associated value
else
add C[key] into the count-min sketch with its associated value
if aggregated value associated with C[key] is > the lowest aggregated value in H
move the lowest key and value from H into C
move C[key] and value from C into H
endwhile
See An Improved Data Stream Summary: The Count-Min Sketch and its Applications and New Directions in Traffic Measurement and Accounting for background on the count-min sketch with conservative updating.
Methods
impl<A: Hash + Eq + Clone, C: Ord + New + for<'a> UnionAssign<&'a C> + Intersect> Top<A, C>[src]
impl<A: Hash + Eq + Clone, C: Ord + New + for<'a> UnionAssign<&'a C> + Intersect> Top<A, C>pub fn new(
n: usize,
probability: f64,
tolerance: f64,
config: <C as New>::Config
) -> Self[src]
pub fn new(
n: usize,
probability: f64,
tolerance: f64,
config: <C as New>::Config
) -> SelfCreate an empty Top data structure with the specified n capacity.
pub fn capacity(&self) -> usize[src]
pub fn capacity(&self) -> usizeThe n most frequent elements we have capacity to track.
pub fn push<V: ?Sized>(&mut self, item: A, value: &V) where
C: for<'a> AddAssign<&'a V>, [src]
pub fn push<V: ?Sized>(&mut self, item: A, value: &V) where
C: for<'a> AddAssign<&'a V>, "Visit" an element.
pub fn clear(&mut self)[src]
pub fn clear(&mut self)Clears the Top data structure, as if it was new.
ⓘImportant traits for TopIter<'a, A, C>pub fn iter(&self) -> TopIter<A, C>[src]
pub fn iter(&self) -> TopIter<A, C>An iterator visiting all elements and their counts in descending order of frequency. The iterator element type is (&'a A, usize).
Trait Implementations
impl<A: Clone + Hash + Eq + Clone, C: Clone + Ord + New + for<'a> UnionAssign<&'a C> + Intersect> Clone for Top<A, C>[src]
impl<A: Clone + Hash + Eq + Clone, C: Clone + Ord + New + for<'a> UnionAssign<&'a C> + Intersect> Clone for Top<A, C>fn clone(&self) -> Top<A, C>[src]
fn clone(&self) -> Top<A, C>Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl<A: Hash + Eq + Clone + Debug, C: Ord + New + Clone + for<'a> UnionAssign<&'a C> + Intersect + Debug> Debug for Top<A, C>[src]
impl<A: Hash + Eq + Clone + Debug, C: Ord + New + Clone + for<'a> UnionAssign<&'a C> + Intersect + Debug> Debug for Top<A, C>fn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect> Sum for Top<A, C>[src]
impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect> Sum for Top<A, C>fn sum<I>(iter: I) -> Self where
I: Iterator<Item = Self>, [src]
fn sum<I>(iter: I) -> Self where
I: Iterator<Item = Self>, Method which takes an iterator and generates Self from the elements by "summing up" the items. Read more
impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect> Add for Top<A, C>[src]
impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect> Add for Top<A, C>type Output = Self
The resulting type after applying the + operator.
fn add(self, other: Self) -> Self[src]
fn add(self, other: Self) -> SelfPerforms the + operation.
impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect> AddAssign for Top<A, C>[src]
impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect> AddAssign for Top<A, C>fn add_assign(&mut self, other: Self)[src]
fn add_assign(&mut self, other: Self)Performs the += operation.