public final class TopHeavyHitters<T>
extends java.lang.Object
Mutable, open-addressing with linear-probing (though naive one which in theory could get pathological) heavily optimised "top N heavy hitters" data-structure.
Keeps a number of specific heavy hitters around in memory.
See also Section 5.2 of http://dimacs.rutgers.edu/~graham/pubs/papers/cm-full.pdf for a discussion about the assumptions made and guarantees about the Heavy Hitters made in this model. We assume the Cash Register model in which there are only additions, which simplifies HH detecion significantly.
This class is a hybrid data structure containing a hashmap and a heap pointing to slots in the hashmap. The capacity of the hashmap is twice that of the heap to reduce clumping of entries on collisions.
Modifier and Type | Class and Description |
---|---|
static class |
TopHeavyHitters.HashCodeVal
Value class to avoid mixing up count and hashCode in APIs.
|
static class |
TopHeavyHitters.HashCodeVal$ |
Constructor and Description |
---|
TopHeavyHitters(int max,
scala.reflect.ClassTag<T> classTag) |
Modifier and Type | Method and Description |
---|---|
int |
capacity() |
scala.collection.Iterator<T> |
iterator()
Iterates over the current heavy hitters, order is not of significance.
|
long |
lowestHitterWeight()
Weight of lowest heavy hitter, if a new inserted item has a weight greater than this, it is a heavy hitter.
|
int |
mask() |
int |
max() |
java.lang.String |
toDebugString() |
java.lang.String |
toString() |
boolean |
update(T item,
long count)
Attempt adding item to heavy hitters set, if it does not fit in the top yet,
it will be dropped and the method will return
false . |
public TopHeavyHitters(int max, scala.reflect.ClassTag<T> classTag)
public int max()
public int capacity()
public int mask()
public scala.collection.Iterator<T> iterator()
public java.lang.String toDebugString()
public boolean update(T item, long count)
false
.
WARNING: It is only allowed to *increase* the weight of existing elements, decreasing is disallowed.
item
- (undocumented)count
- (undocumented)true
if the added item has become a heavy hitter.public long lowestHitterWeight()
public java.lang.String toString()
toString
in class java.lang.Object