BloomFilter { public static int optimalNumOfBits(long inputEntries, double fpp) { int numBits = (int) (-inputEntries * Math.log(fpp) / (Math.log(2) * Math.log(2))); return numBits; } 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 testBloomNumBits() { assertEquals(0, BloomFilter.optimalNumOfBits(0, 0)); assertEquals(0, BloomFilter.optimalNumOfBits(0, 1)); assertEquals(0, BloomFilter.optimalNumOfBits(1, 1)); assertEquals(7, BloomFilter.optimalNumOfBits(1, 0.03)); assertEquals(72, BloomFilter.optimalNumOfBits(10, 0.03)); assertEquals(729, BloomFilter.optimalNumOfBits(100, 0.03)); assertEquals(7298, BloomFilter.optimalNumOfBits(1000, 0.03)); assertEquals(72984, BloomFilter.optimalNumOfBits(10000, 0.03)); assertEquals(729844, BloomFilter.optimalNumOfBits(100000, 0.03)); assertEquals(7298440, BloomFilter.optimalNumOfBits(1000000, 0.03)); assertEquals(6235224, BloomFilter.optimalNumOfBits(1000000, 0.05)); }