You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2019/10/28 03:00:31 UTC

[GitHub] [incubator-iotdb] fanhualta commented on a change in pull request #466: [IOTDB-208] Bloom filter

fanhualta commented on a change in pull request #466: [IOTDB-208] Bloom filter
URL: https://github.com/apache/incubator-iotdb/pull/466#discussion_r339388791
 
 

 ##########
 File path: tsfile/src/main/java/org/apache/iotdb/tsfile/utils/BloomFilter.java
 ##########
 @@ -0,0 +1,142 @@
+/*
+ * 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.iotdb.tsfile.utils;
+
+import java.util.BitSet;
+
+public class BloomFilter {
+
+  private static final int MINIMAL_SIZE = 256;
+  private static final int MAXIMAL_HASH_FUNCTION_SIZE = 8;
+  private static final int[] SEEDS = new int[]{5, 7, 11, 19, 31, 37, 43, 59};
+  private int size;
+  private int hashFunctionSize;
+  private BitSet bits;
+  private HashFunction[] func;
+
+  // do not try to initialize the filter by construction method
+  private BloomFilter(byte[] bytes, int size, int hashFunctionSize) {
+    this.size = size;
+    this.hashFunctionSize = hashFunctionSize;
+    func = new HashFunction[hashFunctionSize];
+    for (int i = 0; i < hashFunctionSize; i++) {
+      func[i] = new HashFunction(size, SEEDS[i]);
+    }
+
+    bits = BitSet.valueOf(bytes);
+  }
+
+  private BloomFilter(int size, int hashFunctionSize) {
+    this.size = size;
+    this.hashFunctionSize = hashFunctionSize;
+    func = new HashFunction[hashFunctionSize];
+    for (int i = 0; i < hashFunctionSize; i++) {
+      func[i] = new HashFunction(size, SEEDS[i]);
+    }
+    
+    bits = new BitSet(size);
+  }
+
+  /**
+   * get empty bloom filter
+   *
+   * @param errorPercent the tolerant percent of error of the bloom filter
+   * @param numOfString the number of string want to store in the bloom filter
+   * @return empty bloom
+   */
+  public static BloomFilter getEmptyBloomFilter(double errorPercent, int numOfString) {
+    errorPercent = Math.max(errorPercent, 0.01);
+    errorPercent = Math.min(errorPercent, 0.1);
 
 Review comment:
   I think it may be better to do these constraints in `TSFileDescriptor` like other parameters.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services