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

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


The following commit(s) were added to refs/heads/fix_getMaxCompactSketchBytes 
by this push:
     new 980c132d Add test for new method
980c132d is described below

commit 980c132d3aa0caf36cdda0c6e750ca466b2b2d8b
Author: Lee Rhodes <[email protected]>
AuthorDate: Fri May 10 12:07:01 2024 -0700

    Add test for new method
---
 .../java/org/apache/datasketches/theta/Sketch.java |  2 ++
 .../org/apache/datasketches/theta/Sketches.java    | 27 ++++++++++++++++++----
 .../apache/datasketches/theta/SketchesTest.java    |  6 +++++
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/theta/Sketch.java 
b/src/main/java/org/apache/datasketches/theta/Sketch.java
index 960878fc..b949169c 100644
--- a/src/main/java/org/apache/datasketches/theta/Sketch.java
+++ b/src/main/java/org/apache/datasketches/theta/Sketch.java
@@ -297,7 +297,9 @@ public abstract class Sketch {
    * @param numberOfEntries the actual number of entries stored with the 
CompactSketch.
    * @return the maximum number of storage bytes required for a CompactSketch 
with the given number
    * of entries.
+   * @deprecated as a public method. Use {@link #getCompactSketchMaxBytes(int) 
instead}
    */
+  @Deprecated
   public static int getMaxCompactSketchBytes(final int numberOfEntries) {
     if (numberOfEntries == 0) { return 8; }
     if (numberOfEntries == 1) { return 16; }
diff --git a/src/main/java/org/apache/datasketches/theta/Sketches.java 
b/src/main/java/org/apache/datasketches/theta/Sketches.java
index a5862e4a..4b146187 100644
--- a/src/main/java/org/apache/datasketches/theta/Sketches.java
+++ b/src/main/java/org/apache/datasketches/theta/Sketches.java
@@ -79,15 +79,32 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link Sketch#getMaxCompactSketchBytes(int)}
-   * @param numberOfEntries  Ref: {@link Sketch#getMaxCompactSketchBytes(int)},
-   * {@code numberOfEntries}
-   * @return Ref: {@link Sketch#getMaxCompactSketchBytes(int)}
-   */
+   * Returns the maximum number of storage bytes required for a CompactSketch 
with the given
+   * number of actual entries. Note that this assumes the worse case of the 
sketch in
+   * estimation mode, which requires storing theta and count.
+   * @param numberOfEntries the actual number of entries stored with the 
CompactSketch.
+   * @return the maximum number of storage bytes required for a CompactSketch 
with the given number
+   * of entries.
+   * @see Sketch#getMaxCompactSketchBytes(int)
+   * @deprecated as a public method. Use {@link #getCompactSketchMaxBytes(int) 
instead}
+   */
+  @Deprecated
   public static int getMaxCompactSketchBytes(final int numberOfEntries) {
     return Sketch.getMaxCompactSketchBytes(numberOfEntries);
   }
 
+  /**
+   * Returns the maximum number of storage bytes required for a CompactSketch 
given the configured
+   * number of nominal entries (power of 2).
+   * @param nomEntries <a 
href="{@docRoot}/resources/dictionary.html#nomEntries">Nominal Entries</a>
+   * @return the maximum number of storage bytes required for a CompactSketch 
with the given
+   * nomEntries.
+   * @see Sketch#getCompactSketchMaxBytes(int)
+   */
+  public static int getCompactSketchMaxBytes(final int nomEntries) {
+    return Sketch.getCompactSketchMaxBytes(nomEntries);
+  }
+
   /**
    * Ref: {@link SetOperation#getMaxIntersectionBytes(int)}
    * @param nomEntries Ref: {@link SetOperation#getMaxIntersectionBytes(int)}, 
{@code nomEntries}
diff --git a/src/test/java/org/apache/datasketches/theta/SketchesTest.java 
b/src/test/java/org/apache/datasketches/theta/SketchesTest.java
index 6b887448..cd51b50e 100644
--- a/src/test/java/org/apache/datasketches/theta/SketchesTest.java
+++ b/src/test/java/org/apache/datasketches/theta/SketchesTest.java
@@ -20,6 +20,7 @@
 package org.apache.datasketches.theta;
 
 import static 
org.apache.datasketches.theta.BackwardConversions.convertSerVer3toSerVer1;
+import static org.apache.datasketches.theta.Sketches.getCompactSketchMaxBytes;
 import static org.apache.datasketches.theta.Sketches.getMaxCompactSketchBytes;
 import static org.apache.datasketches.theta.Sketches.getMaxIntersectionBytes;
 import static org.apache.datasketches.theta.Sketches.getMaxUnionBytes;
@@ -35,6 +36,7 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
+import org.apache.datasketches.common.Family;
 import org.apache.datasketches.common.SketchesArgumentException;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.WritableMemory;
@@ -141,6 +143,10 @@ public class SketchesTest {
     final int maxCompSkBytes = getMaxCompactSketchBytes(k+1);
     assertEquals(24+(k+1)*8, maxCompSkBytes);
 
+    final int compSkMaxBytes = getCompactSketchMaxBytes(k); {
+      assertEquals(compSkMaxBytes, ((k << 4) * 15) / 16 + 
(Family.QUICKSELECT.getMaxPreLongs() << 3));
+    }
+
     final int maxSkBytes = getMaxUpdateSketchBytes(k);
     assertEquals(24+2*k*8, maxSkBytes);
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to