Skip to content

Commit

Permalink
Made flatten() part of BloomFilterProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw committed Jul 7, 2023
1 parent b8e4850 commit 7732ede
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ default boolean forEachBloomFilterPair(final BloomFilterProducer other,
return other.forEachBloomFilter(p) && p.forEachRemaining();
}

/**
* Create a standard (non-layered) Bloom filter by merging all of the layers. If
* the filter is empty this method will return an empty Bloom filter.
*
* @return the merged bloom filter.
*/
default BloomFilter flatten() {
BloomFilter bf[] = {null};
forEachBloomFilter( x -> {
if (bf[0]==null) {
bf[0] = new SimpleBloomFilter( x.getShape());
}
return bf[0].merge( x );
});
return bf[0];
}

/**
* Creates a BloomFilterProducer from an array of Bloom filters.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
public abstract class WrappedBloomFilter implements BloomFilter {
final BloomFilter wrapped;

/**
* Wraps a Bloom filter. The wrapped filter is maintained as a reference
* not a copy. Changes in one will be reflected in the other.
* @param bf The Bloom filter.
*/
public WrappedBloomFilter(BloomFilter bf) {
this.wrapped = bf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setup() {
one.clear();
one.merge(IndexProducer.fromIndexArray(1));
two.clear();
two.merge(IndexProducer.fromIndexArray(1, 2));
two.merge(IndexProducer.fromIndexArray(2, 3));
nullCount[0] = 0;
nullCount[1] = 0;
equalityCount[0] = 0;
Expand Down Expand Up @@ -123,4 +123,12 @@ public void testForEachPairReturnFalseEarly() {
assertFalse(createUnderTest().forEachBloomFilterPair(BloomFilterProducer.fromBloomFilterArray(one, two, one),
(x, y) -> false));
}

@Test
public void testFlatten() {
BloomFilter underTest = createUnderTest().flatten();
BloomFilter expected = new SimpleBloomFilter(shape);
expected.merge(IndexProducer.fromIndexArray(1, 2, 3));
assertArrayEquals(expected.asBitMapArray(), underTest.asBitMapArray());
}
}

0 comments on commit 7732ede

Please sign in to comment.