TimingBloomFilter extends TimerTask { public void add(Object key) { add(key, time()); } TimingBloomFilter(int capacity, int decayTime);  TimingBloomFilter(int capacity, int decayTime, double error); void startDecay(); void decay(); @Override void run(); void add(Object key); void add(Object key, long timestamp); boolean membershipTest(Object key); double getError();  }
@Test @Ignore public void testAdd() { int capacity = 100000; TimingBloomFilter filter = new TimingBloomFilter(capacity*2, 10); filter.startDecay(); System.out.println("Adding"); for (int i=0; i<capacity; i++) filter.add("idx_" + i); System.out.println("MembershipTest(+)"); for (int i=0; i<capacity; i++) assertTrue("False negative", filter.membershipTest("idx_" + i)); System.out.println("MembershipTest(-)"); int c = 0; for (int i=capacity; i<2*capacity; i++) { c += (filter.membershipTest("idx_" + i) == true) ? 1 : 0; } double falsePos = ((double)c) / ((double)capacity); System.out.println("C: " + c); System.out.println("False positives: " + falsePos); System.out.println("Error threshold: " + filter.getError()); assertTrue("Too many false positives", falsePos <= filter.getError()); }