Skip to content

Commit

Permalink
Change default NDV to 1024
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Dai <[email protected]>
  • Loading branch information
dai-chen committed Mar 8, 2024
1 parent c697cf3 commit 11be2f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AdaptiveBloomFilter implements BloomFilter {
public AdaptiveBloomFilter(int numCandidate, double fpp) {
this.candidates = new BloomFilterCandidate[numCandidate];

int expectedNumItems = 128;
int expectedNumItems = 1024;
for (int i = 0; i < candidates.length; i++) {
candidates[i] =
new BloomFilterCandidate(
Expand All @@ -48,7 +48,7 @@ public AdaptiveBloomFilter(int numCandidate, double fpp) {
this.total = total;
this.candidates = new BloomFilterCandidate[candidates.length];

int expectedNumItems = 128;
int expectedNumItems = 1024;
for (int i = 0; i < candidates.length; i++) {
this.candidates[i] = new BloomFilterCandidate(expectedNumItems, candidates[i]);
expectedNumItems *= 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ public class AdaptiveBloomFilterTest {

@Test
public void shouldChooseBestCandidateAdaptively() {
// Insert 50 items
for (int i = 0; i < 50; i++) {
// Insert 500 items
for (int i = 0; i < 500; i++) {
bloomFilter.put(i);
}
BloomFilterCandidate candidate1 = bloomFilter.bestCandidate();
assertEquals(128, candidate1.expectedNumItems);
assertEquals(1024, candidate1.expectedNumItems);

// Insert 100 (total 150)
for (int i = 50; i < 150; i++) {
// Insert 1000 (total 1500)
for (int i = 500; i < 1500; i++) {
bloomFilter.put(i);
}
BloomFilterCandidate candidate2 = bloomFilter.bestCandidate();
assertEquals(256, candidate2.expectedNumItems);
assertEquals(2048, candidate2.expectedNumItems);

// Insert 400 (total 550)
for (int i = 150; i < 550; i++) {
// Insert 4000 (total 5500)
for (int i = 1500; i < 5500; i++) {
bloomFilter.put(i);
}
BloomFilterCandidate candidate3 = bloomFilter.bestCandidate();
assertEquals(1024, candidate3.expectedNumItems);
assertEquals(8192, candidate3.expectedNumItems);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BloomFilterSkippingStrategySuite
test("parameters") {
strategy.parameters shouldBe Map(
BLOOM_FILTER_ADAPTIVE_KEY -> DEFAULT_BLOOM_FILTER_ADAPTIVE.toString,
ADAPTIVE_NUMBER_CANDIDATE_KEY -> DEFAULT_ADAPTIVE_NUMBER_CANDIDATE.toString,
CLASSIC_BLOOM_FILTER_FPP_KEY -> DEFAULT_CLASSIC_BLOOM_FILTER_FPP.toString)
}
}

0 comments on commit 11be2f9

Please sign in to comment.