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



##########
File path: 
src/test/java/org/apache/commons/collections4/bloomfilter/hasher/AbstractHasherTest.java
##########
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.commons.collections4.bloomfilter.AbstractIndexProducerTest;
+import org.apache.commons.collections4.bloomfilter.IndexProducer;
+import org.apache.commons.collections4.bloomfilter.Shape;
+import org.junit.Test;
+
+public abstract class AbstractHasherTest extends AbstractIndexProducerTest {
+
+    protected abstract Hasher createHasher();
+
+    protected abstract Hasher createEmptyHasher();
+
+    /**
+     * The shape of the Hashers filters for testing.
+     * <ul>
+     *  <li>Hash functions (k) = 17
+     *  <li>Number of bits (m) = 72
+     * </ul>
+     * @return the testing shape.
+     */
+    protected final Shape getTestShape() {
+        return Shape.fromKM(17, 72);
+    }
+
+    @Override
+    protected IndexProducer createProducer() {
+        return createHasher().indices(getTestShape());
+    }
+
+    @Override
+    protected IndexProducer createEmptyProducer() {
+        return createEmptyHasher().indices(getTestShape());
+    }
+
+    @Test
+    public void testSize() {
+        assertEquals(1, createHasher().size());
+        assertEquals(0, createEmptyHasher().size());
+    }
+
+    @Test
+    public void testIsEmpty() {
+        assertFalse(createHasher().isEmpty());
+        assertTrue(createEmptyHasher().isEmpty());
+    }
+}

Review comment:
       When used with a counting filter you get a different result.
   In the HasherCollection each Hasher added is a single item.  So for 
`uniqueIndices()` HasherCollection pushes the uniqueness requirement down to 
the contained Hashers.  So you can get duplicate values if two contained hasher 
produce the same value.  The HasherCollection is a simple collection and 
functions as though you called `uniqueIndices()` on each of the hashers in the 
collection.  
   
   The SingleItemHasherCollection does not push the uniqueness down but applies 
it just before returning, so there are no duplicates.
   
   To a CountingBloom filter the HasherCollection will appear to add as many 
items as there are Hashers in the collection items.  The 
SingleItemHashCollection will appear to add one item and it will have the same 
values as though a BloomFilter was constructed from the collection and the 
result added to the CountingBloom filter.  
   
   In your example, if I send you 1000 HasherCollections composed of 10 hashers 
then your filter will probably be over filled as well.  You are still going to 
have 10,000 items inserted.
   
   So the question for keeping the SingleItemHasherCollection really comes down 
to is it faster to execute _N_ `uniqueIndices()`, or to `filter` the result of 
_N_ `indices()`.  It may be that it is just as (or more) efficient (for the 
merge operations) to create a BloomFilter using the HasherCollection.indices() 
and then merge (or add) that to the CountingFilter.  This is assuming you want 
the Collection to appear to the CountingFilter as a single item.
   
   I have convinced myself to remove it again.  Do you agree or do you see 
anything in the above that says to keep it.
   
   




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