Skip to content

Commit

Permalink
[core] Make fields private in BloomFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Apr 7, 2024
1 parent 58beebe commit 7ccc7dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 7ccc7dd

Please sign in to comment.