You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2024/03/07 23:35:42 UTC

(datasketches-java) 01/01: minor cleanups.

This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch add_packageInfo_remove_cast
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git

commit c269ffcc3e5b3a7e6cdd9ec3e1f4aee234a8990c
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Thu Mar 7 15:35:24 2024 -0800

    minor cleanups.
---
 .../datasketches/filters/bloomfilter/BitArray.java   | 14 +++++++-------
 .../filters/bloomfilter/BloomFilterBuilder.java      |  6 +++---
 .../filters/bloomfilter/package-info.java            | 20 ++++++++++++++++++++
 3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/filters/bloomfilter/BitArray.java b/src/main/java/org/apache/datasketches/filters/bloomfilter/BitArray.java
index b4362ec3..91c4f5ef 100644
--- a/src/main/java/org/apache/datasketches/filters/bloomfilter/BitArray.java
+++ b/src/main/java/org/apache/datasketches/filters/bloomfilter/BitArray.java
@@ -27,13 +27,13 @@ import org.apache.datasketches.memory.WritableBuffer;
 
 /**
  * This class holds an array of bits suitable for use in a Bloom Filter
- * 
+ *
  * <p>Rounds the number of bits up to the smallest multiple of 64 (one long)
  * that is not smaller than the specified number.
  */
 final class BitArray {
   // MAX_BITS using longs, based on array indices being capped at Integer.MAX_VALUE
-  private static final long MAX_BITS = Integer.MAX_VALUE * (long) Long.SIZE; 
+  private static final long MAX_BITS = Integer.MAX_VALUE * (long) Long.SIZE;
 
   private long numBitsSet_;  // if -1, need to recompute value
   private boolean isDirty_;
@@ -68,10 +68,10 @@ final class BitArray {
     if (numLongs < 0) {
       throw new SketchesArgumentException("Possible corruption: Must have strictly positive array size. Found: " + numLongs);
     }
-    
+
     if (isEmpty) {
       return new BitArray((long) numLongs * Long.SIZE);
-    }    
+    }
 
     buffer.getInt(); // unused
 
@@ -120,7 +120,7 @@ final class BitArray {
       numBitsSet_ = 0;
       for (final long val : data_) {
         numBitsSet_ += Long.bitCount(val);
-      }  
+      }
     }
     return numBitsSet_;
   }
@@ -184,7 +184,7 @@ final class BitArray {
   void writeToBuffer(final WritableBuffer wbuf) {
     wbuf.putInt(data_.length);
     wbuf.putInt(0); // unused
-    
+
     if (!isEmpty()) {
       wbuf.putLong(isDirty_ ? -1 : numBitsSet_);
       wbuf.putLongArray(data_, 0, data_.length);
@@ -204,7 +204,7 @@ final class BitArray {
   }
 
   // prints a long as a series of 0s and 1s as little endian
-  private String printLong(final long val) {
+  private static String printLong(final long val) {
     final StringBuilder sb = new StringBuilder();
     for (int j = 0; j < Long.SIZE; ++j) {
       sb.append((val & (1L << j)) != 0 ? "1" : "0");
diff --git a/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java b/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java
index 12552e9a..3e3659bd 100644
--- a/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java
+++ b/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java
@@ -26,7 +26,7 @@ import org.apache.datasketches.common.SketchesArgumentException;
 /**
  * <p>This class provides methods to help estimate the correct paramters to use when
  * creating a Bloom filter, and methods to create the filter using those values.</p>
- * 
+ *
  * <p>The underlying math is described in the
  * <a href='https://en.wikipedia.org/wiki/Bloom_filter#Optimal_number_of_hash_functions'>
  * Wikipedia article on Bloom filters</a>.</p>
@@ -75,7 +75,7 @@ public final class BloomFilterBuilder {
     if (targetFalsePositiveProb <= 0.0 || targetFalsePositiveProb > 1.0) {
       throw new SketchesArgumentException("targetFalsePositiveProb must be a valid probability and strictly greater than 0");
     }
-    return (long) Math.round(-maxDistinctItems * Math.log(targetFalsePositiveProb) / (Math.log(2) * Math.log(2)));
+    return Math.round(-maxDistinctItems * Math.log(targetFalsePositiveProb) / (Math.log(2) * Math.log(2)));
   }
 
   /**
@@ -93,7 +93,7 @@ public final class BloomFilterBuilder {
    * using the provided base seed for the hash function.
    * @param maxDistinctItems The maximum expected number of distinct items to add to the filter
    * @param targetFalsePositiveProb A desired false positive probability per item
-   * @param seed A base hash seed 
+   * @param seed A base hash seed
    * @return A new BloomFilter configured for the given input parameters
    */
   public static BloomFilter createByAccuracy(final long maxDistinctItems, final double targetFalsePositiveProb, final long seed) {
diff --git a/src/main/java/org/apache/datasketches/filters/bloomfilter/package-info.java b/src/main/java/org/apache/datasketches/filters/bloomfilter/package-info.java
new file mode 100644
index 00000000..8a752e16
--- /dev/null
+++ b/src/main/java/org/apache/datasketches/filters/bloomfilter/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.datasketches.filters.bloomfilter;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org