AMSSketch implements ISimpleFrequency<Long>, Comparable<AMSSketch> { public boolean add(Long item) { return add(item, 1); } AMSSketch(int depth, int buckets); boolean add(Long item); boolean add(Long item, long incrementCount); int compareTo(AMSSketch o); long estimateCount(Long item); long size(); long estimateF2(); long innerProduct(AMSSketch b); boolean add(AMSSketch source); boolean subtract(AMSSketch source); boolean contains(Long item);  }
@Test public void testAdd() { int n = 1048575; int range = 12345; AMSSketch sketch = new AMSSketch(5, 512); StreamGenerator gen = new StreamGenerator(0.8, n, range); gen.generate(); gen.exact(); long[] stream = gen.stream; long sumsq = gen.sumsq; for (int i=1; i<=range; i++) sketch.add(stream[i], 1); RealCounting<Long> actualFreq = new RealCounting<Long>(); for (int i=1; i<=range; i++) actualFreq.add(stream[i], 1); List<CountEntry<Long>> topk = actualFreq.peek(10); System.out.println("Frequency Table\n" + StringUtils.repeat("-", 80)); System.out.println("Item\tactual\testimated"); for (CountEntry<Long> item : topk) { System.out.println(item.getItem() + "\t" + item.getFrequency() + "\t" + sketch.estimateCount(item.getItem())); } System.out.println("Exact F2: " + sumsq); System.out.println("Estimated F2: " + sketch.estimateF2()); }