pub struct Top<A, C: New> { /* private fields */ }Expand description
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
endwhileSee 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.
Implementations§
Source§impl<A: Hash + Eq + Clone, C: Ord + New + for<'a> UnionAssign<&'a C> + Intersect> Top<A, C>
impl<A: Hash + Eq + Clone, C: Ord + New + for<'a> UnionAssign<&'a C> + Intersect> Top<A, C>
Trait Implementations§
Source§impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect + IntersectPlusUnionIsPlus> Add for Top<A, C>
impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect + IntersectPlusUnionIsPlus> Add for Top<A, C>
Source§impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect + IntersectPlusUnionIsPlus> AddAssign for Top<A, C>
impl<A: Hash + Eq + Clone, C: Ord + New + Clone + for<'a> AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect + IntersectPlusUnionIsPlus> AddAssign for Top<A, C>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreSource§impl<A: Hash + Eq + Clone + Debug, C: Ord + New + Clone + for<'a> UnionAssign<&'a C> + Intersect + Debug> Debug for Top<A, C>
impl<A: Hash + Eq + Clone + Debug, C: Ord + New + Clone + for<'a> UnionAssign<&'a C> + Intersect + Debug> Debug for Top<A, C>
Source§impl<'de, A, C> Deserialize<'de> for Top<A, C>where
A: Hash + Eq + Deserialize<'de>,
C: Deserialize<'de> + New,
<C as New>::Config: Deserialize<'de>,
impl<'de, A, C> Deserialize<'de> for Top<A, C>where
A: Hash + Eq + Deserialize<'de>,
C: Deserialize<'de> + New,
<C as New>::Config: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<A, C> Freeze for Top<A, C>
impl<A, C> RefUnwindSafe for Top<A, C>
impl<A, C> Send for Top<A, C>
impl<A, C> Sync for Top<A, C>
impl<A, C> Unpin for Top<A, C>
impl<A, C> UnwindSafe for Top<A, C>
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