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

 ##########
 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:
   Maybe we should swap these exception conditions around to those that 
actually create the exception:
   ```
   if the number of items is not strictly positive
   if the number of hash function is not strictly positive
   if the number of bits is not >= 8
   if the calculated probability is not below 1
   if the calculated number of hash function is below 1
   
   if the probability is not in the range (0, 1)
   ```
   Becomes
   ```
   if the number of items is < 1
   if the number of hash function is < 1
   if the number of bits is < 8
   if the calculated probability is >= 1
   if the calculated number of hash function is < 1
   
   if the probability is <= 0 or >= 1
   ```
   I think the last one is clearer as a negation (i.e the original).

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