diff --git a/paimon-common/src/main/java/org/apache/paimon/utils/BloomFilter.java b/paimon-common/src/main/java/org/apache/paimon/utils/BloomFilter.java index acd4b3050de7..1cfab654dd49 100644 --- a/paimon-common/src/main/java/org/apache/paimon/utils/BloomFilter.java +++ b/paimon-common/src/main/java/org/apache/paimon/utils/BloomFilter.java @@ -26,17 +26,20 @@ /** Bloom filter based on one memory segment. */ public class BloomFilter { - protected BitSet bitSet; - protected long expectedEntries; - protected int numHashFunctions; + private final BitSet bitSet; + private final int numHashFunctions; public BloomFilter(long expectedEntries, int byteSize) { checkArgument(expectedEntries > 0, "expectedEntries should be > 0"); - this.expectedEntries = expectedEntries; this.numHashFunctions = optimalNumOfHashFunctions(expectedEntries, (long) byteSize << 3); this.bitSet = new BitSet(byteSize); } + @VisibleForTesting + int numHashFunctions() { + return numHashFunctions; + } + public void setMemorySegment(MemorySegment memorySegment, int offset) { this.bitSet.setMemorySegment(memorySegment, offset); } diff --git a/paimon-common/src/test/java/org/apache/paimon/utils/BloomFilterTest.java b/paimon-common/src/test/java/org/apache/paimon/utils/BloomFilterTest.java index a4c0f46dcf38..2c67f41e6852 100644 --- a/paimon-common/src/test/java/org/apache/paimon/utils/BloomFilterTest.java +++ b/paimon-common/src/test/java/org/apache/paimon/utils/BloomFilterTest.java @@ -46,19 +46,19 @@ public void testOneSegmentBuilder() { @Test public void testEstimatedHashFunctions() { - Assertions.assertThat(BloomFilter.builder(1000, 0.01).getFilter().numHashFunctions) + Assertions.assertThat(BloomFilter.builder(1000, 0.01).getFilter().numHashFunctions()) .isEqualTo(7); - Assertions.assertThat(BloomFilter.builder(10_000, 0.01).getFilter().numHashFunctions) + Assertions.assertThat(BloomFilter.builder(10_000, 0.01).getFilter().numHashFunctions()) .isEqualTo(7); - Assertions.assertThat(BloomFilter.builder(100_000, 0.01).getFilter().numHashFunctions) + Assertions.assertThat(BloomFilter.builder(100_000, 0.01).getFilter().numHashFunctions()) .isEqualTo(7); - Assertions.assertThat(BloomFilter.builder(100_000, 0.01).getFilter().numHashFunctions) + Assertions.assertThat(BloomFilter.builder(100_000, 0.01).getFilter().numHashFunctions()) .isEqualTo(7); - Assertions.assertThat(BloomFilter.builder(100_000, 0.05).getFilter().numHashFunctions) + Assertions.assertThat(BloomFilter.builder(100_000, 0.05).getFilter().numHashFunctions()) .isEqualTo(4); - Assertions.assertThat(BloomFilter.builder(1_000_000, 0.01).getFilter().numHashFunctions) + Assertions.assertThat(BloomFilter.builder(1_000_000, 0.01).getFilter().numHashFunctions()) .isEqualTo(7); - Assertions.assertThat(BloomFilter.builder(1_000_000, 0.05).getFilter().numHashFunctions) + Assertions.assertThat(BloomFilter.builder(1_000_000, 0.05).getFilter().numHashFunctions()) .isEqualTo(4); }