Implementation of Count-min sketch using Guava library in Java
We can implement the Count-min sketch using Java library provided by Guava. Below is the step by step implementation:
- Use below maven dependency.
XML
< dependency > < groupId >com.clearspring.analytics</ groupId > < artifactId >stream</ artifactId > < version >2.9.5</ version > </ dependency > |
- The detailed Java code is as follows:
Java
import com.clearspring.analytics .stream.frequency.CountMinSketch; public class CountMinSketchDemo { public static void main(String[] args) { CountMinSketch countMinSketch = new CountMinSketch( // epsilon 0.001 , // delta 0.99 , // seed 1 ); countMinSketch.add( "75.245.10.1" , 1 ); countMinSketch.add( "10.125.22.20" , 1 ); countMinSketch.add( "192.170.0.1" , 2 ); System.out.println( countMinSketch .estimateCount( "192.170.0.1" )); System.out.println( countMinSketch .estimateCount( "999.999.99.99" )); } } |
Above example takes three arguments in the constructor which are
- 0.001 = the epsilon i.e., error rate - 0.99 = the delta i.e., confidence or accuracy rate - 1 = the seed
Output:
Count-Min Sketch Data Structure with Implementation
The Count-Min Sketch is a probabilistic data structure and is defined as a simple technique to summarize large amounts of frequency data. Count-min sketch algorithm talks about keeping track of the count of things. i.e, How many times an element is present in the set.
Contact Us