UnBloomFilter { public boolean containsOrAdd(@NotNull X element) { HashCode code = HASH_FUNC.hashBytes(asBytes.apply(element)); Object prev = array.getAndSet(code.asInt() & sizeMask, element); total++; if ((prev == null || !element.equals(prev))) { hit++; return false; } return true; } UnBloomFilter(int size, Function<X, byte[]> asBytes); boolean containsOrAdd(@NotNull X element); float hitrate(boolean reset);  }
@Test public void testTheBasics() { UnBloomFilter<String> filter = new UnBloomFilter<>(32, (String x) -> x.getBytes()); String twentyNineId = "abc"; String thirtyId = "def"; String thirtyThreeId = "ghi"; assertFalse("nothing should be contained at all", filter.containsOrAdd(twentyNineId)); assertTrue("now it should", filter.containsOrAdd(twentyNineId)); assertFalse("false unless the hash collides", filter.containsOrAdd(thirtyId)); assertTrue("original should still return true", filter.containsOrAdd(twentyNineId)); assertTrue("new array should still return true", filter.containsOrAdd(thirtyId)); assertFalse("colliding array returns false", filter.containsOrAdd(thirtyThreeId)); assertTrue( "colliding array returns true in second call", filter.containsOrAdd(thirtyThreeId)); assertTrue("original colliding array returns true", filter.containsOrAdd(thirtyId)); }