Claudenw commented on a change in pull request #83: Initial bloom filter code contribution URL: https://github.com/apache/commons-collections/pull/83#discussion_r365577026
########## File path: src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java ########## @@ -0,0 +1,467 @@ +/* + * 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.Objects; + +import org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity; +import org.apache.commons.collections4.bloomfilter.hasher.StaticHasher; + +/** + * The interface that describes a Bloom filter. + * @since 4.5 + */ +public interface BloomFilter { + + /** + * The definition of a Bloom filter shape. + * + * <p> This class contains the values for the filter configuration and is used to + * convert a Hasher into a BloomFilter as well as verify that two Bloom filters are + * compatible. (i.e. can be compared or merged)</p> + * + * <h2>Interrelatedness of values</h2> + * + * <dl> <dt>Number of Items (AKA: {@code n})</dt> + * <dd>{@code n = ceil(m / (-k / log(1 - exp(log(p) / k))))}</dd> <dt>Probability of + * Collision (AKA: {@code p})</dt> <dd>{@code p = (1 - exp(-kn/m))^k}</dd> <dt>Number + * of Bits (AKA: {@code m})</dt> + * <dd>{@code m = ceil((n * log(p)) / log(1 / pow(2, log(2))))}</dd> <dt>Number of + * Functions (AKA: {@code k})</dt> <dd>{@code k = round((m / n) * log(2))}</dd> </dl> + * + * <h2>Comparisons</h2> <p> For purposes of equality checking and hashCode + * calculations a {@code Shape} is defined by the hashing function identity, the number of + * bits ({@code m}), and the number of functions ({@code k}). </p> + * + * @see <a href="http://hur.st/bloomfilter?n=3&p=1.0E-5">Bloom Filter calculator</a> + * @see <a href="https://en.wikipedia.org/wiki/Bloom_filter">Bloom filter + * [Wikipedia]</a> + * @since 4.5 + */ + class Shape { + + /** + * The natural logarithm of 2. Used in several calculations. approx 0.693147180 + */ + private static final double LOG_OF_2 = Math.log(2.0); + + /** + * 1 / 2^log(2) approx −0.090619058. Used in calculating the number of bits. Review comment: fixed. it was a long dahs copied from a calculation. ---------------------------------------------------------------- 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
