mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-09 11:35:28 +00:00
COLLECTIONS-831: Add BloomFilter clear() method
This commit is contained in:
parent
fe783da49f
commit
5a31023eae
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.commons.collections4.bloomfilter;
|
package org.apache.commons.collections4.bloomfilter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.IntPredicate;
|
import java.util.function.IntPredicate;
|
||||||
import java.util.function.LongPredicate;
|
import java.util.function.LongPredicate;
|
||||||
@ -104,6 +105,11 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
|
|||||||
this.counts = source.counts.clone();
|
this.counts = source.counts.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
Arrays.fill(counts, 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayCountingBloomFilter copy() {
|
public ArrayCountingBloomFilter copy() {
|
||||||
return new ArrayCountingBloomFilter(this);
|
return new ArrayCountingBloomFilter(this);
|
||||||
|
@ -60,6 +60,11 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
|||||||
*/
|
*/
|
||||||
Shape getShape();
|
Shape getShape();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the filter to its initial, unpopulated state.
|
||||||
|
*/
|
||||||
|
void clear();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns {@code true} if this filter contains the specified filter.
|
* Returns {@code true} if this filter contains the specified filter.
|
||||||
*
|
*
|
||||||
|
@ -117,6 +117,12 @@ public final class SimpleBloomFilter implements BloomFilter {
|
|||||||
this.cardinality = source.cardinality;
|
this.cardinality = source.cardinality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
Arrays.fill(bitMap, 0L);
|
||||||
|
cardinality = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long[] asBitMapArray() {
|
public long[] asBitMapArray() {
|
||||||
return Arrays.copyOf(bitMap, bitMap.length);
|
return Arrays.copyOf(bitMap, bitMap.length);
|
||||||
|
@ -174,6 +174,11 @@ public final class SparseBloomFilter implements BloomFilter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
indices.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Shape getShape() {
|
public Shape getShape() {
|
||||||
return shape;
|
return shape;
|
||||||
|
@ -18,6 +18,7 @@ package org.apache.commons.collections4.bloomfilter;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@ -178,6 +179,14 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
|||||||
assertTrue(bf4.contains(bf1));
|
assertTrue(bf4.contains(bf1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClear() {
|
||||||
|
BloomFilter bf1 = createFilter(getTestShape(), from1);
|
||||||
|
assertNotEquals(0, bf1.cardinality());
|
||||||
|
bf1.clear();
|
||||||
|
assertEquals(0, bf1.cardinality());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the andCardinality calculations are correct.
|
* Tests that the andCardinality calculations are correct.
|
||||||
*
|
*
|
||||||
|
@ -112,6 +112,11 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
indices.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forEachIndex(IntPredicate consumer) {
|
public boolean forEachIndex(IntPredicate consumer) {
|
||||||
for (Integer i : indices) {
|
for (Integer i : indices) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user