BJKST implements Serializable { public void offer(Object o) { for ( int i =0 ; i < numMedians; i++) { String binaryRepr = Long.toBinaryString(hHashers.get(i).hash(o)); int zereosP = binaryRepr.length() - binaryRepr.lastIndexOf('1'); int currentZ = limits.get(i); if (zereosP >= currentZ) { HashSet<String> currentBuffer = buffers.get(i); currentBuffer.add(String.format(lengthOfIntegerRepresentation, gHashers.get(i).hash(o)) + String.format(lengthOfIntegerRepresentation, zereosP)); while (currentBuffer.size() > bufferSize) { currentZ = currentZ + 1; for (Iterator<String> itr = currentBuffer.iterator(); itr.hasNext();) { String element = itr.next(); long zeroesOld = Long.parseLong(element.substring(intLength)); if (zeroesOld < currentZ) { itr.remove(); } } } } } } BJKST(int numberOfMedianAttempts, int sizeOfEachMedianSet);  BJKST(int numberOfMedianAttempts, int sizeOfEachMedianSet, double allowedError); void offer(Object o); long cardinality();  }
@Test public void testOffer() { System.out.println("offer"); BJKST instance = new BJKST(1024, 64, 0.3); long cardinality = 500L; System.out.println("First batch:"); 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("Second batch:"); 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); }