FlajoletMartin { public boolean offer(Object o) { boolean affected = false; for (int i=0; i<numHashGroups; i++) { for (int j=0; j<numHashFunctionsInHashGroup; j++) { HashFunction f = hashes[i][j]; long v = f.hash(o); int index = rho(v); if (!bitmaps[i][j][index]) { bitmaps[i][j][index] = true; affected = true; } } } return affected; } FlajoletMartin(int bitmapSize, int numHashGroups, int numHashFunctionsInEachGroup); boolean offer(Object o); long cardinality();  }
@Test public void testOffer() { System.out.println("offer"); FlajoletMartin instance = new FlajoletMartin(32, 1024, 32); long cardinality = 500L; for (long i = 0; i < cardinality; i++) { instance.offer(Long.valueOf(i)); if (i % 50 == 0) { System.out.println("actual: " + i + ", estimated: " + instance.cardinality()); } } System.out.println("actual: " + cardinality + ", estimated: " + instance.cardinality()); assertEquals(cardinality, instance.cardinality(), 100); }