[GitHub] [commons-collections] garydgregory commented on a change in pull request #83: WIP: Initial bloom filter code contribution

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [commons-collections] garydgregory commented on a change in pull request #83: WIP: Initial bloom filter code contribution

GitBox
garydgregory commented on a change in pull request #83: WIP: Initial bloom filter code contribution
URL: https://github.com/apache/commons-collections/pull/83#discussion_r323908083
 
 

 ##########
 File path: src/main/java/org/apache/commons/collections4/bloomfilters/ProtoBloomFilter.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.bloomfilters;
+
+import java.io.Serializable;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+
+/**
+ * A prototypical bloom filter definition.
+ *
+ * This is the information necessary to create a concrete bloom filter given a
+ * filter configuration.
+ *
+ * The construction of the ProtoBloomFilter is far more compute expensive than
+ * making the concrete bloom filter from the proto.  
+ *
+ */
+public class ProtoBloomFilter implements Comparable<ProtoBloomFilter>, Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1293273984765868571L;
+ private Set<Hash> hashes;
+ private transient Integer hashCode;
+
+ /**
+ * Constructor
+ *
+ * @param hashes the two longs that were created by the murmur hash function.
+ */
+ public ProtoBloomFilter(Set<Hash> hashes) {
+ this.hashes = new TreeSet<Hash>();
+ this.hashes.addAll(hashes);
+ }
+
+ /**
+ * Create a concrete bloom filter from this proto type given the filter
+ * configuration.
+ *
+ * @param cfg The filter configuration to use.
+ * @return the Concreate Bloom Filter.
+ */
+ public final BloomFilter create(FilterConfig cfg) {
+ BitSet set = new BitSet(cfg.getNumberOfBits());
+ for (Hash hash : hashes) {
+ hash.populate(set, cfg);
+ }
+ return new BloomFilter(set);
+ }
+
+ /**
+ * Get a list of the hashes that this proto bloom filter uses.
+ *
+ * @return the list of hashes.
+ */
+ public Set<Hash> getHashes() {
+ return Collections.unmodifiableSet(hashes);
+ }
+
+ @Override
+ public int hashCode() {
+ if (hashCode == null) {
+ HashCodeBuilder hb = new HashCodeBuilder();
+ for (Hash hash : hashes) {
+ hb.append(hash);
+ }
+ hashCode = hb.build();
 
 Review comment:
   `hashCode = Objects.hash(hashes.toArray());`

----------------------------------------------------------------
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:
[hidden email]


With regards,
Apache Git Services