Claudenw commented on a change in pull request #258:
URL: 
https://github.com/apache/commons-collections/pull/258#discussion_r804908010



##########
File path: 
src/main/java/org/apache/commons/collections4/bloomfilter/hasher/filter/Filter.java
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections4.bloomfilter.hasher.filter;
+
+import java.util.function.IntPredicate;
+
+import org.apache.commons.collections4.bloomfilter.BitMap;
+import org.apache.commons.collections4.bloomfilter.Shape;
+
+/**
+ * A convenience class for Hasher implementations to filter out duplicate 
indices.
+ *
+ * <p><em>If the index is negative the behavior is not defined.</em></p>
+ *
+ * <p>This is conceptually a unique filter implemented as a {@code 
Predicate<int>}.</p>
+ * @since 4.5
+ */
+public final class Filter implements IntPredicate {
+    private IndexTracker tracker;
+    private int size;
+    private IntPredicate consumer;
+
+    /**
+     * Creates an instance optimized for the specified shape.
+     * @param shape The shape that is being generated.
+     * @param consumer The consumer to accept the values.
+     * @return a Filter optimized for the shape.
+     */
+    public Filter(Shape shape, IntPredicate consumer) {
+        this.size = shape.getNumberOfBits();
+        this.consumer = consumer;
+        if (BitMap.numberOfBitMaps(shape.getNumberOfBits()) * Long.BYTES < 
shape.getNumberOfHashFunctions()
+                * Integer.BYTES) {
+            this.tracker = new BitMapTracker(shape);
+        } else {
+            this.tracker = new ArrayTracker(shape);
+        }
+    }
+
+    /**
+     * Creates an instance of Filter with the specified IndexTracker.
+     *
+     * @param shape The shape that is being generated.
+     * @param consumer The consumer to accept the values
+     * @param tracker The index tracker to use.
+     */
+    public Filter(Shape shape, IntPredicate consumer, IndexTracker tracker) {
+        this.size = shape.getNumberOfBits();
+        this.consumer = consumer;
+        this.tracker = tracker;
+    }
+
+    /**
+     * Test if the number has not been seen.
+     *
+     * <p>The first time a number is tested the method returns {@code true} 
and returns

Review comment:
       Moved IndexFilter into Hasher interface.  Along with numerous other 
changes as described in various comments.  Also the requirement for Hashers to 
remove duplicates has been moved to a new method `IndexProducer 
uniqueIndices(Shape)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to