Claudenw commented on a change in pull request #140: Bloomfilter updates2
URL: 
https://github.com/apache/commons-collections/pull/140#discussion_r392521338
 
 

 ##########
 File path: 
src/main/java/org/apache/commons/collections4/bloomfilter/hasher/Shape.java
 ##########
 @@ -81,34 +83,36 @@
     private final HashFunctionIdentity hashFunctionIdentity;
 
     /**
-     * Constructs a filter configuration with the specified number of items and
-     * probability.
+     * Constructs a filter configuration with a desired false-positive 
probability ({@code p}) and the
+     * specified number of bits ({@code m}) and hash functions ({@code k}).
      *
-     * @param hashFunctionIdentity The HashFunctionIdentity of the hash 
function this shape uses.
-     * @param probability The probability of duplicates. Must be in the range
-     * (0.0,1.0).
-     * @param numberOfBits The number of bits in the filter.
-     * @param numberOfHashFunctions The number of hash functions in the filter.
+     * <p>The number of items ({@code n}) to be stored in the filter is 
computed.
+     * <pre>n = ceil(m / (-k / log(1 - exp(log(p) / k))))</pre>
+     *
+     * <p>The actual probability will be approximately equal to the
+     * desired probability but will be dependent upon the calculated Bloom 
filter capacity
+     * (number of items). An exception is raised if this is greater than or 
equal to 1 (i.e. the
+     * shape is invalid for use as a Bloom filter).
+     *
+     * @param hashFunctionIdentity The identity of the hash function this 
shape uses
+     * @param probability The desired false-positive probability in the range 
{@code (0, 1)}
+     * @param numberOfBits The number of bits in the filter
+     * @param numberOfHashFunctions The number of hash functions in the filter
+     * @throws NullPointerException if the hash function identity is null
+     * @throws IllegalArgumentException if the desired probability is not in 
the range {@code (0, 1)}
+     * @throws IllegalArgumentException if the number of bits is not above 8
 
 Review comment:
   I used to think that we should filter out unreasonable shapes (thus the bits 
>= 8).  But now I think that we should just check the results to ensure that 
they do not fall outside of actual requirements.  Specifically:
   
   if the number of items is < 1
   if the number of hash function is < 1
   if the calculated number of hash function is < 1
   if the probability is <= 0 or >= 1
   
   The reasoning here is that the values outside of those values cause the 
functions to fail.  Anything else is valid and while we may look at it now and 
say that it is non-sense it may be reasonable in some situation we do not 
foresee.
   

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


With regards,
Apache Git Services

Reply via email to