Class CountMinSketch
java.lang.Object
org.infinispan.server.resp.commands.countmin.CountMinSketch
A Count-Min Sketch implementation compatible with Redis CMS commands.
Count-Min Sketch is a probabilistic data structure that serves as a frequency table of events in a stream of data. It uses hash functions to map events to frequencies, but unlike a hash table, uses only sub-linear space at the expense of overcounting some events due to collisions.
- Since:
- 16.2
-
Constructor Summary
ConstructorsConstructorDescriptionCountMinSketch(int width, int depth) Creates a Count-Min Sketch with specified dimensions. -
Method Summary
Modifier and TypeMethodDescriptionlong[]intgetDepth()longintgetWidth()longincrBy(byte[] item, long increment) Increments the count of an item by the specified amount.voidmerge(CountMinSketch other, double weight) Merges another sketch into this one with a weight multiplier.longquery(byte[] item) Returns the estimated count of an item.
-
Constructor Details
-
CountMinSketch
public CountMinSketch(int width, int depth) Creates a Count-Min Sketch with specified dimensions.- Parameters:
width- number of counters in each row (determines error rate)depth- number of rows/hash functions (determines probability)
-
-
Method Details
-
getWidth
@ProtoField(number=1, defaultValue="2000") public int getWidth() -
getDepth
@ProtoField(number=2, defaultValue="7") public int getDepth() -
getCounters
@ProtoField(number=3) public long[] getCounters() -
getTotalCount
@ProtoField(number=4, defaultValue="0") public long getTotalCount() -
incrBy
public long incrBy(byte[] item, long increment) Increments the count of an item by the specified amount.- Parameters:
item- the item to incrementincrement- the amount to add- Returns:
- the estimated count after increment
-
query
public long query(byte[] item) Returns the estimated count of an item.- Parameters:
item- the item to query- Returns:
- the estimated count (minimum across all hash functions)
-
merge
Merges another sketch into this one with a weight multiplier.- Parameters:
other- the sketch to mergeweight- the weight multiplier for the other sketch- Throws:
IllegalArgumentException- if dimensions don't match
-