BloomFilter { static int optimalNumOfHashFunctions(long expectEntries, long bitSize) { return Math.max(1, (int) Math.round((double) bitSize / expectEntries * Math.log(2))); } BloomFilter(int expectedEntries, int byteSize); void setBitsLocation(MemorySegment memorySegment, int offset); static int optimalNumOfBits(long inputEntries, double fpp); static double estimateFalsePositiveProbability(long inputEntries, int bitSize); void addHash(int hash32); boolean testHash(int hash32); void reset(); @Override String toString();  }
@Test public void testBloomFilterNumHashFunctions() { assertEquals(1, BloomFilter.optimalNumOfHashFunctions(-1, -1)); assertEquals(1, BloomFilter.optimalNumOfHashFunctions(0, 0)); assertEquals(1, BloomFilter.optimalNumOfHashFunctions(10, 0)); assertEquals(1, BloomFilter.optimalNumOfHashFunctions(10, 10)); assertEquals(7, BloomFilter.optimalNumOfHashFunctions(10, 100)); assertEquals(1, BloomFilter.optimalNumOfHashFunctions(100, 100)); assertEquals(1, BloomFilter.optimalNumOfHashFunctions(1000, 100)); assertEquals(1, BloomFilter.optimalNumOfHashFunctions(10000, 100)); assertEquals(1, BloomFilter.optimalNumOfHashFunctions(100000, 100)); assertEquals(1, BloomFilter.optimalNumOfHashFunctions(1000000, 100)); }