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



##########
File path: 
src/main/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilter.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import java.util.function.Function;
+
+import org.apache.commons.collections4.bloomfilter.hasher.DynamicHasher;
+import org.apache.commons.collections4.bloomfilter.hasher.Hasher;
+import org.apache.commons.collections4.bloomfilter.hasher.Shape;
+import 
org.apache.commons.collections4.bloomfilter.hasher.function.Murmur128x64Cyclic;
+
+/**
+ * A bloom filter that uses a BitSetBloomFilter to create a Bloom filter that
+ * can merge instances of a specific class.
+ *
+ * @param <T> The Class to merge.
+ * @since 4.5
+ */
+public class SimpleBloomFilter<T> extends BitSetBloomFilter implements 
BloomFilter {
+
+    /**
+     * The function that converts the instance of T to the SimpleBuilder.
+     * <p>
+     * If the object T is to be considered as a single item in the filter then
+     * function must create the {@code SimpleBuilder} and only call a single 
{@code with()}
+     * method.</p>
+     * <p>
+     * If the object T is to be considered as several items then the function 
must
+     * create the {@code SimpleBuilder} and call the {@code with()} method 
once for each item.</p>
+     */
+    private Function<T, SimpleBuilder> func;
+
+    /**
+     * Constructs a SimpleBloomFilter from the shape and function.  This 
constructor
+     * creates an empty Bloom filter.
+     * @param hasher the Hasher to use.
+     * @param shape the Shape of the Bloom filter.
+     * @param func a Function to convert T to a SimpleBuilder.
+     * @see #func
+     */
+    public SimpleBloomFilter(Hasher hasher, Shape shape, Function<T, 
SimpleBuilder> func) {
+        super(hasher, shape);
+        this.func = func;
+    }
+
+    /**
+     * Constructs a SimpleBloomFilter from the shape and function.  This 
constructor
+     * creates an empty Bloom filter.
+     * @param shape the Shape of the Bloom filter.
+     * @param func a Function to convert T to a SimpleBuilder.
+     * @see #func
+     */
+    public SimpleBloomFilter(Shape shape, Function<T, SimpleBuilder> func) {
+        super(shape);
+        this.func = func;
+    }
+
+    /**
+     * Constructs a SimpleBloomFilter from the shape, function and a data 
object.
+     * This constructor creates an Bloom filter populated with the data from 
the
+     * {@code data} parameter.
+     * @param shape the Shape of the Bloom filter.
+     * @param func a Function to convert T to a SimpleBuilder.
+     * @param data the data object to populate the filter with.
+     * @see #func
+     */
+    public SimpleBloomFilter(Shape shape, Function<T, SimpleBuilder> func, T 
data) {
+        this(shape, func);
+        this.merge( data );

Review comment:
       The purpose of the SimpleBloomFilter was to provide a class that is 
simple to use and works for a great many users.  It is, in some ways, patterned 
after the Guava Bloom filter implementation.
   
   The goal is to construct a Bloom filter that accepts objects of type T.  So 
there is a `merge( T )` and a `contains( T )` method.
   
   Whether or not there is a constructor for an ArrayList that accepts a single 
item as well as a capacity is immaterial here.  By definition the Bloom filter 
has a concept of the number of items that will be added.  That concept is 
mathematically tied to other factors such as the number of hash functions for 
each item, the number of bits, and the probability of false positives.  Yes the 
shape has all 4 values.  No, you don't need all 4 values all the time. But, 
they are mathematically bound together and so make sense to be represented as 
the Shape.
   
   This constructor is simply a short hand for `new SimpleBloomFilter(Shape 
shape, Function<T, SimpleBuilder> func).merge( T )` and does not restrict the 
user from creating another BloomFilter and merging it with this one.
   
   If you are asking for another constructor that takes an existing BloomFilter 
as a parameter to provide the shape and an initial data load, that could be 
provided, but is not a reason not to have this constructor.  Is that what you 
are asking for?
   
   
    




----------------------------------------------------------------
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.

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


Reply via email to