KMinValues implements IBaseCardinality { public boolean offer(Object key) { int idx = index(key); if (kMin.size() < k) { if (!kMin.contains(idx)) { kMin.add(idx); return true; } } else { if (idx < kMin.last()) if (!kMin.contains(idx)) { kMin.pollLast(); kMin.add(idx); return true; } } return false; } KMinValues(int k);  KMinValues(int k, Hash hasher); boolean offer(Object key); long cardinality(); void union(KMinValues... others); double jaccard(KMinValues other); double cardinalityUnion(KMinValues... others);  }
@Test public void testOffer() { System.out.println("offer"); KMinValues instance = new KMinValues(20); System.out.println("Approx.\tReal"); for (int i=0; i<100; i++) { instance.offer(String.valueOf(i)); System.out.println(instance.cardinality() + "\t" + (i+1)); } }