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 2019/09/20 22:17:20 UTC

[incubator-datasketches-java] branch master updated: Update license, add checking for nomEntries bounds.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f4764c6  Update license, add checking for nomEntries bounds.
f4764c6 is described below

commit f4764c6a9eed539ea56c6fe48c9effb11a02b813
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Fri Sep 20 15:16:41 2019 -0700

    Update license, add checking for nomEntries bounds.
---
 LICENSE                                            | 27 +++++++++++++++++++++-
 src/main/java/org/apache/datasketches/Util.java    | 16 +++++++++++++
 .../datasketches/theta/UpdateSketchBuilder.java    | 13 +++--------
 .../ArrayOfDoublesUpdatableSketchBuilder.java      | 15 ++++++------
 .../tuple/HeapArrayOfDoublesQuickSelectSketch.java |  4 +---
 .../datasketches/tuple/QuickSelectSketch.java      |  2 +-
 .../apache/datasketches/tuple/UpdatableSketch.java |  2 +-
 .../datasketches/tuple/UpdatableSketchBuilder.java |  5 ++--
 8 files changed, 59 insertions(+), 25 deletions(-)

diff --git a/LICENSE b/LICENSE
index 7c089a2..e2ce77a 100644
--- a/LICENSE
+++ b/LICENSE
@@ -212,7 +212,32 @@ APPENDIX B: Additional licenses relevant to Apache DataSketches-java (INCUBATING
 
     BSD-2-Clause License
     ================================
-    https://github.com/Cyan4973/xxHash/blob/dev/LICENSE
+    xxHash Library
+    Copyright (c) 2012-present, Yann Collet
+    All rights reserved.
+    
+    BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+    
+    Redistribution and use in source and binary forms, with or without modification,
+    are permitted provided that the following conditions are met:
+    
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+    
+    * Redistributions in binary form must reproduce the above copyright notice, this
+      list of conditions and the following disclaimer in the documentation and/or
+      other materials provided with the distribution.
+    
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+    ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     
     Code locations subject to the BSD-2-Clause License:
     -------------------------------------------------------------
diff --git a/src/main/java/org/apache/datasketches/Util.java b/src/main/java/org/apache/datasketches/Util.java
index a348244..47891a1 100644
--- a/src/main/java/org/apache/datasketches/Util.java
+++ b/src/main/java/org/apache/datasketches/Util.java
@@ -665,6 +665,22 @@ public final class Util {
     return next;
   }
 
+  /**
+   * Checks that the given nomLongs is within bounds and returns the Log2 of the ceiling power of 2
+   * of the given nomLongs.
+   * @param nomLongs the given number of nominal longs.  This can be any value from 16 to
+   * 67108864, inclusive.
+   * @return The Log2 of the ceiling power of 2 of the given nomLongs.
+   */
+  public static final int checkNomLongs(final int nomLongs) {
+    final int lgNomLongs = Integer.numberOfTrailingZeros(ceilingPowerOf2(nomLongs));
+    if ((lgNomLongs > MAX_LG_NOM_LONGS) || (lgNomLongs < MIN_LG_NOM_LONGS)) {
+      throw new SketchesArgumentException("Nominal Entries must be >= 16 and <= 67108864: "
+        + nomLongs);
+    }
+    return lgNomLongs;
+  }
+
   //Other checks
 
   /**
diff --git a/src/main/java/org/apache/datasketches/theta/UpdateSketchBuilder.java b/src/main/java/org/apache/datasketches/theta/UpdateSketchBuilder.java
index 99b2902..705af29 100644
--- a/src/main/java/org/apache/datasketches/theta/UpdateSketchBuilder.java
+++ b/src/main/java/org/apache/datasketches/theta/UpdateSketchBuilder.java
@@ -26,6 +26,7 @@ import static org.apache.datasketches.Util.MAX_LG_NOM_LONGS;
 import static org.apache.datasketches.Util.MIN_LG_NOM_LONGS;
 import static org.apache.datasketches.Util.TAB;
 import static org.apache.datasketches.Util.ceilingPowerOf2;
+import static org.apache.datasketches.Util.checkNomLongs;
 
 import org.apache.datasketches.Family;
 import org.apache.datasketches.ResizeFactor;
@@ -103,11 +104,7 @@ public class UpdateSketchBuilder {
    * @return this UpdateSketchBuilder
    */
   public UpdateSketchBuilder setNominalEntries(final int nomEntries) {
-    bLgNomLongs = Integer.numberOfTrailingZeros(ceilingPowerOf2(nomEntries));
-    if ((bLgNomLongs > MAX_LG_NOM_LONGS) || (bLgNomLongs < MIN_LG_NOM_LONGS)) {
-      throw new SketchesArgumentException("Nominal Entries must be >= 16 and <= 67108864: "
-        + nomEntries);
-    }
+    bLgNomLongs = checkNomLongs(nomEntries);
     return this;
   }
 
@@ -122,11 +119,7 @@ public class UpdateSketchBuilder {
    * @return this UpdateSketchBuilder
    */
   public UpdateSketchBuilder setLogNominalEntries(final int lgNomEntries) {
-    bLgNomLongs = lgNomEntries;
-    if ((bLgNomLongs > MAX_LG_NOM_LONGS) || (bLgNomLongs < MIN_LG_NOM_LONGS)) {
-      throw new SketchesArgumentException(
-          "Log Nominal Entries must be >= 4 and <= 26: " + lgNomEntries);
-    }
+    bLgNomLongs = checkNomLongs(1 << lgNomEntries);
     return this;
   }
 
diff --git a/src/main/java/org/apache/datasketches/tuple/ArrayOfDoublesUpdatableSketchBuilder.java b/src/main/java/org/apache/datasketches/tuple/ArrayOfDoublesUpdatableSketchBuilder.java
index 6608d74..342f3b2 100644
--- a/src/main/java/org/apache/datasketches/tuple/ArrayOfDoublesUpdatableSketchBuilder.java
+++ b/src/main/java/org/apache/datasketches/tuple/ArrayOfDoublesUpdatableSketchBuilder.java
@@ -21,6 +21,7 @@ package org.apache.datasketches.tuple;
 
 import static org.apache.datasketches.Util.DEFAULT_NOMINAL_ENTRIES;
 import static org.apache.datasketches.Util.DEFAULT_UPDATE_SEED;
+import static org.apache.datasketches.Util.checkNomLongs;
 
 import org.apache.datasketches.ResizeFactor;
 import org.apache.datasketches.SketchesArgumentException;
@@ -54,12 +55,12 @@ public class ArrayOfDoublesUpdatableSketchBuilder {
 
   /**
    * This is to set the nominal number of entries.
-   * @param nomEntries Nominal number of entries. Forced to the nearest power of 2 greater than 
-   * given value.
+   * @param nomEntries Nominal number of entries. Forced to the nearest power of 2 greater than
+   * or equal to given value.
    * @return this builder
    */
   public ArrayOfDoublesUpdatableSketchBuilder setNominalEntries(final int nomEntries) {
-    nomEntries_ = nomEntries;
+    nomEntries_ = 1 << checkNomLongs(nomEntries);
     return this;
   }
 
@@ -81,9 +82,9 @@ public class ArrayOfDoublesUpdatableSketchBuilder {
    * @param samplingProbability sampling probability from 0 to 1
    * @return this builder
    */
-  public ArrayOfDoublesUpdatableSketchBuilder 
+  public ArrayOfDoublesUpdatableSketchBuilder
         setSamplingProbability(final float samplingProbability) {
-    if (samplingProbability < 0 || samplingProbability > 1f) {
+    if ((samplingProbability < 0) || (samplingProbability > 1f)) {
       throw new SketchesArgumentException("sampling probability must be between 0 and 1");
     }
     samplingProbability_ = samplingProbability;
@@ -115,7 +116,7 @@ public class ArrayOfDoublesUpdatableSketchBuilder {
    * @return an ArrayOfDoublesUpdatableSketch
    */
   public ArrayOfDoublesUpdatableSketch build() {
-      return new HeapArrayOfDoublesQuickSelectSketch(nomEntries_, resizeFactor_.lg(), 
+      return new HeapArrayOfDoublesQuickSelectSketch(nomEntries_, resizeFactor_.lg(),
           samplingProbability_, numValues_, seed_);
   }
 
@@ -125,7 +126,7 @@ public class ArrayOfDoublesUpdatableSketchBuilder {
    * @return an ArrayOfDoublesUpdatableSketch
    */
   public ArrayOfDoublesUpdatableSketch build(final WritableMemory dstMem) {
-    return new DirectArrayOfDoublesQuickSelectSketch(nomEntries_, resizeFactor_.lg(), 
+    return new DirectArrayOfDoublesQuickSelectSketch(nomEntries_, resizeFactor_.lg(),
         samplingProbability_, numValues_, seed_, dstMem);
   }
 
diff --git a/src/main/java/org/apache/datasketches/tuple/HeapArrayOfDoublesQuickSelectSketch.java b/src/main/java/org/apache/datasketches/tuple/HeapArrayOfDoublesQuickSelectSketch.java
index 082d8d7..4869813 100644
--- a/src/main/java/org/apache/datasketches/tuple/HeapArrayOfDoublesQuickSelectSketch.java
+++ b/src/main/java/org/apache/datasketches/tuple/HeapArrayOfDoublesQuickSelectSketch.java
@@ -19,8 +19,6 @@
 
 package org.apache.datasketches.tuple;
 
-import static org.apache.datasketches.Util.ceilingPowerOf2;
-
 import java.nio.ByteOrder;
 import java.util.Arrays;
 
@@ -63,7 +61,7 @@ final class HeapArrayOfDoublesQuickSelectSketch extends ArrayOfDoublesQuickSelec
   HeapArrayOfDoublesQuickSelectSketch(final int nomEntries, final int lgResizeFactor,
       final float samplingProbability, final int numValues, final long seed) {
     super(numValues, seed);
-    nomEntries_ = ceilingPowerOf2(nomEntries);
+    nomEntries_ = nomEntries;
     lgResizeFactor_ = lgResizeFactor;
     samplingProbability_ = samplingProbability;
     theta_ = (long) (Long.MAX_VALUE * (double) samplingProbability);
diff --git a/src/main/java/org/apache/datasketches/tuple/QuickSelectSketch.java b/src/main/java/org/apache/datasketches/tuple/QuickSelectSketch.java
index 94bff68..e32b735 100644
--- a/src/main/java/org/apache/datasketches/tuple/QuickSelectSketch.java
+++ b/src/main/java/org/apache/datasketches/tuple/QuickSelectSketch.java
@@ -87,7 +87,7 @@ class QuickSelectSketch<S extends Summary> extends Sketch<S> {
    * This is to create an instance of a QuickSelectSketch with custom resize factor and sampling
    * probability
    * @param nomEntries Nominal number of entries. Forced to the nearest power of 2 greater than
-   * given value.
+   * or equal to the given value.
    * @param lgResizeFactor log2(resizeFactor) - value from 0 to 3:
    * <pre>
    * 0 - no resizing (max size allocated),
diff --git a/src/main/java/org/apache/datasketches/tuple/UpdatableSketch.java b/src/main/java/org/apache/datasketches/tuple/UpdatableSketch.java
index 11ec6f0..b7a8b11 100644
--- a/src/main/java/org/apache/datasketches/tuple/UpdatableSketch.java
+++ b/src/main/java/org/apache/datasketches/tuple/UpdatableSketch.java
@@ -43,7 +43,7 @@ public class UpdatableSketch<U, S extends UpdatableSummary<U>> extends QuickSele
   /**
    * This is to create a new instance of an UpdatableQuickSelectSketch.
    * @param nomEntries Nominal number of entries. Forced to the nearest power of 2 greater than
-   * given value.
+   * or equal to the given value.
    * @param lgResizeFactor log2(resizeFactor) - value from 0 to 3:
    * <pre>
    * 0 - no resizing (max size allocated),
diff --git a/src/main/java/org/apache/datasketches/tuple/UpdatableSketchBuilder.java b/src/main/java/org/apache/datasketches/tuple/UpdatableSketchBuilder.java
index 92df480..c0b8298 100644
--- a/src/main/java/org/apache/datasketches/tuple/UpdatableSketchBuilder.java
+++ b/src/main/java/org/apache/datasketches/tuple/UpdatableSketchBuilder.java
@@ -20,6 +20,7 @@
 package org.apache.datasketches.tuple;
 
 import static org.apache.datasketches.Util.DEFAULT_NOMINAL_ENTRIES;
+import static org.apache.datasketches.Util.checkNomLongs;
 
 import org.apache.datasketches.ResizeFactor;
 import org.apache.datasketches.SketchesArgumentException;
@@ -53,11 +54,11 @@ public class UpdatableSketchBuilder<U, S extends UpdatableSummary<U>> {
   /**
    * This is to set the nominal number of entries.
    * @param nomEntries Nominal number of entries. Forced to the nearest power of 2 greater than
-   * given value.
+   * or equal to the given value.
    * @return this UpdatableSketchBuilder
    */
   public UpdatableSketchBuilder<U, S> setNominalEntries(final int nomEntries) {
-    nomEntries_ = nomEntries;
+    nomEntries_ = 1 << checkNomLongs(nomEntries);
     return this;
   }
 


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