This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch kll_longs_sketch
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
The following commit(s) were added to refs/heads/kll_longs_sketch by this push:
new f9ad53a6 Corrections from Zac's code.
f9ad53a6 is described below
commit f9ad53a60f7fc65e56f21e50475a6160239e7cf7
Author: Lee Rhodes <[email protected]>
AuthorDate: Wed May 22 19:17:52 2024 -0700
Corrections from Zac's code.
In the main code, nearly all the corrections are in the Javadocs.
However, in the test code, there were many places where he was comparing
a long vs a float ('cause he copied the code from the float classes).
Also, he didn't check the test classes with printing enabled. There were
numerous places where the printf format expected an "%f" that should
have been a "%d".
Nonetheless, Zac did an amazing job of creating this KllLongsSketch,
considering the complexity of the code!
I also did a coverage tests and made sure that the coverage of the
"longs" classes were very close to the coverage of the comparable
"doubles" and "floats" classes -- and they were! This means that he was
able to faithfully translate all the relevant tests from float to longs
and I did not find any gaps in testing.
---
.../datasketches/kll/KllDirectLongsSketch.java | 41 +-
.../datasketches/kll/KllHeapLongsSketch.java | 27 +-
.../org/apache/datasketches/kll/KllHelper.java | 14 +-
.../apache/datasketches/kll/KllLongsHelper.java | 36 +-
.../apache/datasketches/kll/KllLongsSketch.java | 1115 ++++++++++----------
.../apache/datasketches/kll/KllPreambleUtil.java | 5 +-
.../org/apache/datasketches/kll/KllSketch.java | 5 +-
.../quantilescommon/DoublesSortedView.java | 5 +-
.../quantilescommon/LongsSketchSortedView.java | 8 +-
.../quantilescommon/LongsSortedView.java | 12 +-
.../quantilescommon/QuantilesLongsAPI.java | 496 ++++-----
.../quantilescommon/QuantilesUtil.java | 4 +-
.../kll/KllDirectCompactLongsSketchTest.java | 48 +-
.../kll/KllDirectLongsSketchIteratorTest.java | 15 +-
.../kll/KllDoublesSketchSerDeTest.java | 12 +-
.../datasketches/kll/KllLongsSketchSerDeTest.java | 30 +-
.../datasketches/kll/KllLongsSketchTest.java | 86 +-
.../datasketches/kll/KllMiscDirectLongsTest.java | 78 +-
.../apache/datasketches/kll/KllMiscLongsTest.java | 50 +-
19 files changed, 1080 insertions(+), 1007 deletions(-)
diff --git
a/src/main/java/org/apache/datasketches/kll/KllDirectLongsSketch.java
b/src/main/java/org/apache/datasketches/kll/KllDirectLongsSketch.java
index a3edf319..bf91baab 100644
--- a/src/main/java/org/apache/datasketches/kll/KllDirectLongsSketch.java
+++ b/src/main/java/org/apache/datasketches/kll/KllDirectLongsSketch.java
@@ -19,6 +19,30 @@
package org.apache.datasketches.kll;
+import static org.apache.datasketches.common.ByteArrayUtil.copyBytes;
+import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR;
+import static
org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR_SINGLE_ITEM;
+import static org.apache.datasketches.kll.KllPreambleUtil.getMemoryK;
+import static
org.apache.datasketches.kll.KllPreambleUtil.getMemoryLevelZeroSortedFlag;
+import static org.apache.datasketches.kll.KllPreambleUtil.getMemoryM;
+import static org.apache.datasketches.kll.KllPreambleUtil.getMemoryMinK;
+import static org.apache.datasketches.kll.KllPreambleUtil.getMemoryN;
+import static org.apache.datasketches.kll.KllPreambleUtil.getMemoryNumLevels;
+import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryFamilyID;
+import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryK;
+import static
org.apache.datasketches.kll.KllPreambleUtil.setMemoryLevelZeroSortedFlag;
+import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryM;
+import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryMinK;
+import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryN;
+import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryNumLevels;
+import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryPreInts;
+import static org.apache.datasketches.kll.KllPreambleUtil.setMemorySerVer;
+import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_EMPTY;
+import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_FULL;
+import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_SINGLE;
+import static org.apache.datasketches.kll.KllSketch.SketchStructure.UPDATABLE;
+import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
+
import org.apache.datasketches.common.ByteArrayUtil;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
@@ -26,11 +50,6 @@ import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;
-import static org.apache.datasketches.common.ByteArrayUtil.copyBytes;
-import static org.apache.datasketches.kll.KllPreambleUtil.*;
-import static org.apache.datasketches.kll.KllSketch.SketchStructure.*;
-import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
-
/**
* This class implements an off-heap, updatable KllLongsSketch using
WritableMemory.
*
@@ -101,7 +120,7 @@ class KllDirectLongsSketch extends KllLongsSketch {
@Override
String getItemAsString(final int index) {
- if (isEmpty()) { return "NaN"; }
+ if (isEmpty()) { return "Null"; }
return Long.toString(getLongItemsArray()[index]);
}
@@ -111,7 +130,7 @@ class KllDirectLongsSketch extends KllLongsSketch {
}
//MinMax Methods
-
+
@Override
public long getMaxItem() {
if (sketchStructure == COMPACT_EMPTY || isEmpty()) { throw new
SketchesArgumentException(EMPTY_MSG); }
@@ -129,7 +148,7 @@ class KllDirectLongsSketch extends KllLongsSketch {
final int offset = DATA_START_ADR + getLevelsArrSizeBytes(sketchStructure)
+ ITEM_BYTES;
return wmem.getLong(offset);
}
-
+
@Override
String getMaxItemAsString() {
final long maxItem = getMaxItemInternal();
@@ -173,9 +192,9 @@ class KllDirectLongsSketch extends KllLongsSketch {
final int offset = DATA_START_ADR + getLevelsArrSizeBytes(sketchStructure);
wmem.putLong(offset, item);
}
-
+
//END MinMax Methods
-
+
@Override
public long getN() {
if (sketchStructure == COMPACT_EMPTY) { return 0; }
@@ -329,7 +348,7 @@ class KllDirectLongsSketch extends KllLongsSketch {
final int offset = DATA_START_ADR + getLevelsArrSizeBytes(sketchStructure)
+ (index + 2) * ITEM_BYTES;
wmem.putLongArray(offset, items, srcOffset, length);
}
-
+
@Override
void setLevelZeroSorted(final boolean sorted) {
if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG);
}
diff --git a/src/main/java/org/apache/datasketches/kll/KllHeapLongsSketch.java
b/src/main/java/org/apache/datasketches/kll/KllHeapLongsSketch.java
index fbb3c550..c4e09134 100644
--- a/src/main/java/org/apache/datasketches/kll/KllHeapLongsSketch.java
+++ b/src/main/java/org/apache/datasketches/kll/KllHeapLongsSketch.java
@@ -19,20 +19,23 @@
package org.apache.datasketches.kll;
-import org.apache.datasketches.common.SketchesArgumentException;
-import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.MemoryRequestServer;
-import org.apache.datasketches.memory.WritableMemory;
-
-import java.util.Arrays;
-import java.util.Objects;
-
import static org.apache.datasketches.common.ByteArrayUtil.putLongLE;
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR;
import static
org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR_SINGLE_ITEM;
-import static org.apache.datasketches.kll.KllSketch.SketchStructure.*;
+import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_EMPTY;
+import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_FULL;
+import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_SINGLE;
+import static org.apache.datasketches.kll.KllSketch.SketchStructure.UPDATABLE;
import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.apache.datasketches.common.SketchesArgumentException;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.WritableMemory;
+
/**
* This class implements an on-heap longs KllSketch.
*
@@ -159,7 +162,7 @@ final class KllHeapLongsSketch extends KllLongsSketch {
@Override
String getItemAsString(final int index) {
- if (isEmpty()) { return "NaN"; }
+ if (isEmpty()) { return "Null"; }
return Long.toString(longItems[index]);
}
@@ -208,9 +211,7 @@ final class KllHeapLongsSketch extends KllLongsSketch {
void setMaxItem(final long item) { this.maxLongItem = item; }
@Override
- void setMinItem(final long item) {
- this.minLongItem = item;
- }
+ void setMinItem(final long item) { this.minLongItem = item; }
//END MinMax Methods
diff --git a/src/main/java/org/apache/datasketches/kll/KllHelper.java
b/src/main/java/org/apache/datasketches/kll/KllHelper.java
index 52c36c32..21188255 100644
--- a/src/main/java/org/apache/datasketches/kll/KllHelper.java
+++ b/src/main/java/org/apache/datasketches/kll/KllHelper.java
@@ -39,7 +39,10 @@ import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_EMPT
import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_FULL;
import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_SINGLE;
import static org.apache.datasketches.kll.KllSketch.SketchStructure.UPDATABLE;
-import static org.apache.datasketches.kll.KllSketch.SketchType.*;
+import static org.apache.datasketches.kll.KllSketch.SketchType.DOUBLES_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.FLOATS_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.ITEMS_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
import static
org.apache.datasketches.quantilescommon.QuantilesAPI.UNSUPPORTED_MSG;
import java.nio.ByteOrder;
@@ -614,7 +617,8 @@ final class KllHelper {
maxFloat = fltSk.getMaxItem();
//assert we are following a certain growth scheme
assert myCurFloatItemsArr.length == myCurTotalItemsCapacity;
- } else if (sketchType == LONGS_SKETCH) {
+ }
+ else if (sketchType == LONGS_SKETCH) {
final KllLongsSketch lngSk = (KllLongsSketch) sketch;
myCurLongItemsArr = lngSk.getLongItemsArray();
minLong = lngSk.getMinItem();
@@ -664,7 +668,8 @@ final class KllHelper {
myNewFloatItemsArr = new float[myNewTotalItemsCapacity];
// copy and shift the current items data into the new array
System.arraycopy(myCurFloatItemsArr, 0, myNewFloatItemsArr,
deltaItemsCap, myCurTotalItemsCapacity);
- } else if (sketchType == LONGS_SKETCH) {
+ }
+ else if (sketchType == LONGS_SKETCH) {
myNewLongItemsArr = new long[myNewTotalItemsCapacity];
// copy and shift the current items data into the new array
System.arraycopy(myCurLongItemsArr, 0, myNewLongItemsArr, deltaItemsCap,
myCurTotalItemsCapacity);
@@ -695,7 +700,8 @@ final class KllHelper {
fltSk.setMinItem(minFloat);
fltSk.setMaxItem(maxFloat);
fltSk.setFloatItemsArray(myNewFloatItemsArr);
- } else if (sketchType == LONGS_SKETCH) {
+ }
+ else if (sketchType == LONGS_SKETCH) {
final KllLongsSketch lngSk = (KllLongsSketch) sketch;
lngSk.setMinItem(minLong);
lngSk.setMaxItem(maxLong);
diff --git a/src/main/java/org/apache/datasketches/kll/KllLongsHelper.java
b/src/main/java/org/apache/datasketches/kll/KllLongsHelper.java
index cffedd06..ec67b55d 100644
--- a/src/main/java/org/apache/datasketches/kll/KllLongsHelper.java
+++ b/src/main/java/org/apache/datasketches/kll/KllLongsHelper.java
@@ -19,19 +19,20 @@
package org.apache.datasketches.kll;
-import org.apache.datasketches.memory.WritableMemory;
-
-import java.util.Arrays;
-import java.util.Random;
-
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.apache.datasketches.common.Util.isEven;
import static org.apache.datasketches.common.Util.isOdd;
import static org.apache.datasketches.kll.KllHelper.findLevelToCompact;
+import java.util.Arrays;
+import java.util.Random;
+
+import org.apache.datasketches.memory.WritableMemory;
+
/**
* Static methods to support KllLongsSketch
+ * @author Lee Rhodes
* @author Zac Blanco
*/
final class KllLongsHelper {
@@ -237,9 +238,9 @@ final class KllLongsHelper {
}
private static void mergeSortedLongArrays( //only bufC is modified
- final long[] bufA, final int
startA, final int lenA,
- final long[] bufB, final int
startB, final int lenB,
- final long[] bufC, final int
startC) {
+ final long[] bufA, final int startA, final int lenA,
+ final long[] bufB, final int startB, final int lenB,
+ final long[] bufC, final int startC) {
final int lenC = lenA + lenB;
final int limA = startA + lenA;
final int limB = startB + lenB;
@@ -276,7 +277,7 @@ final class KllLongsHelper {
*/
//NOTE For validation Method: Need to modify to run.
private static void randomlyHalveDownLongs(final long[] buf, final int
start, final int length,
- final Random random) {
+ final Random random) {
assert isEven(length);
final int half_length = length / 2;
final int offset = random.nextInt(2); // disable for validation
@@ -297,7 +298,7 @@ final class KllLongsHelper {
*/
//NOTE For validation Method: Need to modify to run.
private static void randomlyHalveUpLongs(final long[] buf, final int start,
final int length,
- final Random random) {
+ final Random random) {
assert isEven(length);
final int half_length = length / 2;
final int offset = random.nextInt(2); // disable for validation
@@ -464,4 +465,19 @@ final class KllLongsHelper {
}
}
}
+
+ /*
+ * Validation Method.
+ * The following must be enabled for use with the KllDoublesValidationTest,
+ * which is only enabled for manual testing. In addition, two Validation
Methods
+ * above need to be modified.
+ */ //NOTE Validation Method: Need to uncomment to use
+ // static int nextOffset = 0;
+ //
+ // private static int deterministicOffset() {
+ // final int result = nextOffset;
+ // nextOffset = 1 - nextOffset;
+ // return result;
+ // }
+
}
diff --git a/src/main/java/org/apache/datasketches/kll/KllLongsSketch.java
b/src/main/java/org/apache/datasketches/kll/KllLongsSketch.java
index 7e4b8387..0f6fa7d8 100644
--- a/src/main/java/org/apache/datasketches/kll/KllLongsSketch.java
+++ b/src/main/java/org/apache/datasketches/kll/KllLongsSketch.java
@@ -23,7 +23,7 @@ import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.apache.datasketches.common.ByteArrayUtil.putLongLE;
import static org.apache.datasketches.kll.KllSketch.SketchStructure.UPDATABLE;
-import static org.apache.datasketches.kll.KllSketch.SketchType.*;
+import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
import java.util.Arrays;
import java.util.Objects;
@@ -36,7 +36,10 @@ import
org.apache.datasketches.memory.DefaultMemoryRequestServer;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;
-import org.apache.datasketches.quantilescommon.*;
+import org.apache.datasketches.quantilescommon.LongsSketchSortedView;
+import org.apache.datasketches.quantilescommon.QuantileSearchCriteria;
+import org.apache.datasketches.quantilescommon.QuantilesLongsAPI;
+import org.apache.datasketches.quantilescommon.QuantilesLongsSketchIterator;
/**
* This variation of the KllSketch implements primitive longs.
@@ -44,599 +47,623 @@ import org.apache.datasketches.quantilescommon.*;
* @see org.apache.datasketches.kll.KllSketch
*/
public abstract class KllLongsSketch extends KllSketch implements
QuantilesLongsAPI {
- private LongsSketchSortedView longsSV = null;
- final static int ITEM_BYTES = Long.BYTES;
+ private LongsSketchSortedView longsSV = null;
+ final static int ITEM_BYTES = Long.BYTES;
+
+ KllLongsSketch(
+ final SketchStructure sketchStructure) {
+ super(SketchType.LONGS_SKETCH, sketchStructure);
+ }
+
+ //Factories for new heap instances.
+
+ /**
+ * Create a new heap instance of this sketch with the default <em>k =
200</em>.
+ * The default <em>k</em> = 200 results in a normalized rank error of about
+ * 1.65%. Larger K will have smaller error but the sketch will be larger
(and slower).
+ * @return new KllLongsSketch on the Java heap.
+ */
+ public static KllLongsSketch newHeapInstance() {
+ return newHeapInstance(DEFAULT_K);
+ }
+
+ /**
+ * Create a new heap instance of this sketch with a given parameter
<em>k</em>.
+ * <em>k</em> can be between 8, inclusive, and 65535, inclusive.
+ * The default <em>k</em> = 200 results in a normalized rank error of about
+ * 1.65%. Larger K will have smaller error but the sketch will be larger
(and slower).
+ * @param k parameter that controls size of the sketch and accuracy of
estimates.
+ * @return new KllLongsSketch on the Java heap.
+ */
+ public static KllLongsSketch newHeapInstance(final int k) {
+ return new KllHeapLongsSketch(k, DEFAULT_M);
+ }
+
+ //Factories for new direct instances.
+
+ /**
+ * Create a new direct updatable instance of this sketch with the default
<em>k</em>.
+ * The default <em>k</em> = 200 results in a normalized rank error of about
+ * 1.65%. Larger <em>k</em> will have smaller error but the sketch will be
larger (and slower).
+ * @param dstMem the given destination WritableMemory object for use by the
sketch
+ * @param memReqSvr the given MemoryRequestServer to request a larger
WritableMemory
+ * @return a new direct instance of this sketch
+ */
+ public static KllLongsSketch newDirectInstance(
+ final WritableMemory dstMem,
+ final MemoryRequestServer memReqSvr) {
+ return newDirectInstance(DEFAULT_K, dstMem, memReqSvr);
+ }
+
+ /**
+ * Create a new direct updatable instance of this sketch with a given
<em>k</em>.
+ * @param k parameter that controls size of the sketch and accuracy of
estimates.
+ * @param dstMem the given destination WritableMemory object for use by the
sketch
+ * @param memReqSvr the given MemoryRequestServer to request a larger
WritableMemory
+ * @return a new direct instance of this sketch
+ */
+ public static KllLongsSketch newDirectInstance(
+ final int k,
+ final WritableMemory dstMem,
+ final MemoryRequestServer memReqSvr) {
+ Objects.requireNonNull(dstMem, "Parameter 'dstMem' must not be null");
+ Objects.requireNonNull(memReqSvr, "Parameter 'memReqSvr' must not be
null");
+ return KllDirectLongsSketch.newDirectUpdatableInstance(k, DEFAULT_M,
dstMem, memReqSvr);
+ }
+
+ //Factory to create an heap instance from a Memory image
+
+ /**
+ * Factory heapify takes a compact sketch image in Memory and instantiates
an on-heap sketch.
+ * The resulting sketch will not retain any link to the source Memory.
+ * @param srcMem a compact Memory image of a sketch serialized by this
sketch.
+ * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
+ * @return a heap-based sketch based on the given Memory.
+ */
+ public static KllLongsSketch heapify(final Memory srcMem) {
+ Objects.requireNonNull(srcMem, "Parameter 'srcMem' must not be null");
+ return KllHeapLongsSketch.heapifyImpl(srcMem);
+ }
+
+ //Factory to wrap a Read-Only Memory
+
+ /**
+ * Wrap a sketch around the given read only compact source Memory containing
sketch data
+ * that originated from this sketch.
+ * @param srcMem the read only source Memory
+ * @return instance of this sketch
+ */
+ public static KllLongsSketch wrap(final Memory srcMem) {
+ Objects.requireNonNull(srcMem, "Parameter 'srcMem' must not be null");
+ final KllMemoryValidate memVal = new KllMemoryValidate(srcMem,
LONGS_SKETCH, null);
+ if (memVal.sketchStructure == UPDATABLE) {
+ final MemoryRequestServer memReqSvr = new DefaultMemoryRequestServer();
//dummy
+ return new KllDirectLongsSketch(memVal.sketchStructure,
(WritableMemory)srcMem, memReqSvr, memVal);
+ } else {
+ return new KllDirectCompactLongsSketch(memVal.sketchStructure, srcMem,
memVal);
+ }
+ }
+
+ //Factory to wrap a WritableMemory image
+
+ /**
+ * Wrap a sketch around the given source Writable Memory containing sketch
data
+ * that originated from this sketch.
+ * @param srcMem a WritableMemory that contains data.
+ * @param memReqSvr the given MemoryRequestServer to request a larger
WritableMemory
+ * @return instance of this sketch
+ */
+ public static KllLongsSketch writableWrap(
+ final WritableMemory srcMem,
+ final MemoryRequestServer memReqSvr) {
+ Objects.requireNonNull(srcMem, "Parameter 'srcMem' must not be null");
+ Objects.requireNonNull(memReqSvr, "Parameter 'memReqSvr' must not be
null");
+ final KllMemoryValidate memVal = new KllMemoryValidate(srcMem,
LONGS_SKETCH);
+ if (memVal.sketchStructure == UPDATABLE) {
+ return new KllDirectLongsSketch(UPDATABLE, srcMem, memReqSvr, memVal);
+ } else {
+ return new KllDirectCompactLongsSketch(memVal.sketchStructure, srcMem,
memVal);
+ }
+ }
+
+ //END of Constructors
+
+ @Override
+ public double[] getCDF(final long[] splitPoints, final
QuantileSearchCriteria searchCrit) {
+ if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
+ refreshSortedView();
+ return longsSV.getCDF(splitPoints, searchCrit);
+ }
+
+ @Override
+ public double[] getPMF(final long[] splitPoints, final
QuantileSearchCriteria searchCrit) {
+ if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
+ refreshSortedView();
+ return longsSV.getPMF(splitPoints, searchCrit);
+ }
+
+ @Override
+ public long getQuantile(final double rank, final QuantileSearchCriteria
searchCrit) {
+ if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
+ refreshSortedView();
+ return longsSV.getQuantile(rank, searchCrit);
+ }
+
+ @Override
+ public long[] getQuantiles(final double[] ranks, final
QuantileSearchCriteria searchCrit) {
+ if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
+ refreshSortedView();
+ final int len = ranks.length;
+ final long[] quantiles = new long[len];
+ for (int i = 0; i < len; i++) {
+ quantiles[i] = longsSV.getQuantile(ranks[i], searchCrit);
+ }
+ return quantiles;
+ }
+
+ /**
+ * {@inheritDoc}
+ * The approximate probability that the true quantile is within the
confidence interval
+ * specified by the upper and lower quantile bounds for this sketch is 0.99.
+ */
+ @Override
+ public long getQuantileLowerBound(final double rank) {
+ return getQuantile(max(0, rank -
KllHelper.getNormalizedRankError(getMinK(), false)));
+ }
+
+ /**
+ * {@inheritDoc}
+ * The approximate probability that the true quantile is within the
confidence interval
+ * specified by the upper and lower quantile bounds for this sketch is 0.99.
+ */
+ @Override
+ public long getQuantileUpperBound(final double rank) {
+ return getQuantile(min(1.0, rank +
KllHelper.getNormalizedRankError(getMinK(), false)));
+ }
+
+ @Override
+ public double getRank(final long quantile, final QuantileSearchCriteria
searchCrit) {
+ if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
+ refreshSortedView();
+ return longsSV.getRank(quantile, searchCrit);
+ }
+
+ /**
+ * {@inheritDoc}
+ * The approximate probability that the true rank is within the confidence
interval
+ * specified by the upper and lower rank bounds for this sketch is 0.99.
+ */
+ @Override
+ public double getRankLowerBound(final double rank) {
+ return max(0.0, rank - KllHelper.getNormalizedRankError(getMinK(), false));
+ }
+
+ /**
+ * {@inheritDoc}
+ * The approximate probability that the true rank is within the confidence
interval
+ * specified by the upper and lower rank bounds for this sketch is 0.99.
+ */
+ @Override
+ public double getRankUpperBound(final double rank) {
+ return min(1.0, rank + KllHelper.getNormalizedRankError(getMinK(), false));
+ }
+
+ @Override
+ public double[] getRanks(final long[] quantiles, final
QuantileSearchCriteria searchCrit) {
+ if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
+ refreshSortedView();
+ final int len = quantiles.length;
+ final double[] ranks = new double[len];
+ for (int i = 0; i < len; i++) {
+ ranks[i] = longsSV.getRank(quantiles[i], searchCrit);
+ }
+ return ranks;
+ }
+
+ @Override
+ public QuantilesLongsSketchIterator iterator() {
+ return new KllLongsSketchIterator(
+ getLongItemsArray(), getLevelsArray(SketchStructure.UPDATABLE),
getNumLevels());
+ }
+
+ @Override
+ public final void merge(final KllSketch other) {
+ if (readOnly || sketchStructure != UPDATABLE) { throw new
SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
+ if (this == other) { throw new SketchesArgumentException(SELF_MERGE_MSG); }
+ final KllLongsSketch otherLngSk = (KllLongsSketch)other;
+ if (otherLngSk.isEmpty()) { return; }
+ KllLongsHelper.mergeLongsImpl(this, otherLngSk);
+ longsSV = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>The parameter <i>k</i> will not change.</p>
+ */
+ @Override
+ public final void reset() {
+ if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG);
}
+ final int k = getK();
+ setN(0);
+ setMinK(k);
+ setNumLevels(1);
+ setLevelZeroSorted(false);
+ setLevelsArray(new int[] {k, k});
+ setMinItem(Long.MAX_VALUE);
+ setMaxItem(Long.MIN_VALUE);
+ setLongItemsArray(new long[k]);
+ longsSV = null;
+ }
+
+ @Override
+ public byte[] toByteArray() {
+ return KllHelper.toByteArray(this, false);
+ }
+
+ @Override
+ public String toString(final boolean withLevels, final boolean
withLevelsAndItems) {
+ KllSketch sketch = this;
+ if (withLevelsAndItems && sketchStructure != UPDATABLE) {
+ final Memory mem = getWritableMemory();
+ assert mem != null;
+ sketch = KllLongsSketch.heapify(getWritableMemory());
+ }
+ return KllHelper.toStringImpl(sketch, withLevels, withLevelsAndItems,
getSerDe());
+ }
+
+ //SINGLE UPDATE
+
+ @Override
+ public void update(final long item) {
+ // Align with KllDoublesSketch
+ if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG);
}
+ updateLong(this, item);
+ longsSV = null;
+ }
+
+ //Also Called from KllLongsHelper::merge
+ static void updateLong(final KllLongsSketch lngSk, final long item) {
+ lngSk.updateMinMax(item);
+ int freeSpace = lngSk.levelsArr[0];
+ assert (freeSpace >= 0);
+ if (freeSpace == 0) {
+ KllLongsHelper.compressWhileUpdatingSketch(lngSk);
+ freeSpace = lngSk.levelsArr[0];
+ assert (freeSpace > 0);
+ }
+ lngSk.incN(1);
+ lngSk.setLevelZeroSorted(false);
+ final int nextPos = freeSpace - 1;
+ lngSk.setLevelsArrayAt(0, nextPos);
+ lngSk.setLongItemsArrayAt(nextPos, item);
+ }
+
+ /**
+ * Single update of min and max
+ * @param item the source item, it must not be a NaN.
+ */
+ final void updateMinMax(final long item) {
+ if (isEmpty()) {
+ setMinItem(item);
+ setMaxItem(item);
+ } else {
+ setMinItem(min(getMinItemInternal(), item));
+ setMaxItem(max(getMaxItemInternal(), item));
+ }
+ }
+
+ //WEIGHTED UPDATE
+
+ /**
+ * Weighted update. Updates this sketch with the given item the number of
times specified by the given integer weight.
+ * @param item the item to be repeated. NaNs are ignored.
+ * @param weight the number of times the update of item is to be repeated.
It must be ≥ one.
+ */
+ public void update(final long item, final long weight) {
+ //
+ if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG);
}
+ if (weight < 1L) { throw new SketchesArgumentException("Weight is less
than one."); }
+ if (weight == 1L) { updateLong(this, item); }
+ else {
+ if (weight < levelsArr[0]) {
+ for (int i = 0; i < (int)weight; i++) { updateLong(this, item); }
+ } else {
+ final KllHeapLongsSketch tmpSk = new KllHeapLongsSketch(getK(),
DEFAULT_M, item, weight);
+ merge(tmpSk);
+ }
+ }
+ longsSV = null;
+ }
+
+ // VECTOR UPDATE
+
+ /**
+ * Vector update. Updates this sketch with the given array (vector) of
items, starting at the items
+ * offset for a length number of items. This is not supported for direct
sketches.
+ * @param items the vector of items
+ * @param offset the starting index of the items[] array
+ * @param length the number of items
+ */
+ public void update(final long[] items, final int offset, final int length) {
+ if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG);
}
+ if (length == 0) { return; }
+ updateLong(items, offset, length);
+ longsSV = null;
+ }
+ /* Align with KllDoublesSketch
- KllLongsSketch(
- final SketchStructure sketchStructure) {
- super(SketchType.LONGS_SKETCH, sketchStructure);
- }
- //Factories for new heap instances.
- /**
- * Create a new heap instance of this sketch with the default <em>k =
200</em>.
- * The default <em>k</em> = 200 results in a normalized rank error of about
- * 1.65%. Larger K will have smaller error but the sketch will be larger
(and slower).
- * @return new KllLongsSketch on the Java heap.
- */
- public static KllLongsSketch newHeapInstance() {
- return newHeapInstance(DEFAULT_K);
- }
- /**
- * Create a new heap instance of this sketch with a given parameter
<em>k</em>.
- * <em>k</em> can be between 8, inclusive, and 65535, inclusive.
- * The default <em>k</em> = 200 results in a normalized rank error of about
- * 1.65%. Larger K will have smaller error but the sketch will be larger
(and slower).
- * @param k parameter that controls size of the sketch and accuracy of
estimates.
- * @return new KllLongsSketch on the Java heap.
- */
- public static KllLongsSketch newHeapInstance(final int k) {
- return new KllHeapLongsSketch(k, DEFAULT_M);
- }
- //Factories for new direct instances.
-
- /**
- * Create a new direct updatable instance of this sketch with the default
<em>k</em>.
- * The default <em>k</em> = 200 results in a normalized rank error of about
- * 1.65%. Larger <em>k</em> will have smaller error but the sketch will be
larger (and slower).
- * @param dstMem the given destination WritableMemory object for use by
the sketch
- * @param memReqSvr the given MemoryRequestServer to request a larger
WritableMemory
- * @return a new direct instance of this sketch
- */
- public static KllLongsSketch newDirectInstance(
- final WritableMemory dstMem,
- final MemoryRequestServer memReqSvr) {
- return newDirectInstance(DEFAULT_K, dstMem, memReqSvr);
- }
- /**
- * Create a new direct updatable instance of this sketch with a given
<em>k</em>.
- * @param k parameter that controls size of the sketch and accuracy of
estimates.
- * @param dstMem the given destination WritableMemory object for use by
the sketch
- * @param memReqSvr the given MemoryRequestServer to request a larger
WritableMemory
- * @return a new direct instance of this sketch
- */
- public static KllLongsSketch newDirectInstance(
- final int k,
- final WritableMemory dstMem,
- final MemoryRequestServer memReqSvr) {
- Objects.requireNonNull(dstMem, "Parameter 'dstMem' must not be null");
- Objects.requireNonNull(memReqSvr, "Parameter 'memReqSvr' must not be
null");
- return KllDirectLongsSketch.newDirectUpdatableInstance(k, DEFAULT_M,
dstMem, memReqSvr);
- }
- //Factory to create an heap instance from a Memory image
-
- /**
- * Factory heapify takes a compact sketch image in Memory and instantiates
an on-heap sketch.
- * The resulting sketch will not retain any link to the source Memory.
- * @param srcMem a compact Memory image of a sketch serialized by this
sketch.
- * <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
- * @return a heap-based sketch based on the given Memory.
- */
- public static KllLongsSketch heapify(final Memory srcMem) {
- Objects.requireNonNull(srcMem, "Parameter 'srcMem' must not be null");
- return KllHeapLongsSketch.heapifyImpl(srcMem);
- }
- //Factory to wrap a Read-Only Memory
-
- /**
- * Wrap a sketch around the given read only compact source Memory
containing sketch data
- * that originated from this sketch.
- * @param srcMem the read only source Memory
- * @return instance of this sketch
- */
- public static KllLongsSketch wrap(final Memory srcMem) {
- Objects.requireNonNull(srcMem, "Parameter 'srcMem' must not be null");
- final KllMemoryValidate memVal = new KllMemoryValidate(srcMem,
LONGS_SKETCH, null);
- if (memVal.sketchStructure == UPDATABLE) {
- final MemoryRequestServer memReqSvr = new
DefaultMemoryRequestServer(); //dummy
- return new KllDirectLongsSketch(memVal.sketchStructure,
(WritableMemory)srcMem, memReqSvr, memVal);
- } else {
- return new KllDirectCompactLongsSketch(memVal.sketchStructure,
srcMem, memVal);
- }
- }
- //Factory to wrap a WritableMemory image
-
- /**
- * Wrap a sketch around the given source Writable Memory containing sketch
data
- * that originated from this sketch.
- * @param srcMem a WritableMemory that contains data.
- * @param memReqSvr the given MemoryRequestServer to request a larger
WritableMemory
- * @return instance of this sketch
- */
- public static KllLongsSketch writableWrap(
- final WritableMemory srcMem,
- final MemoryRequestServer memReqSvr) {
- Objects.requireNonNull(srcMem, "Parameter 'srcMem' must not be null");
- Objects.requireNonNull(memReqSvr, "Parameter 'memReqSvr' must not be
null");
- final KllMemoryValidate memVal = new KllMemoryValidate(srcMem,
LONGS_SKETCH);
- if (memVal.sketchStructure == UPDATABLE) {
- return new KllDirectLongsSketch(UPDATABLE, srcMem, memReqSvr,
memVal);
- } else {
- return new KllDirectCompactLongsSketch(memVal.sketchStructure,
srcMem, memVal);
- }
- }
- //END of Constructors
- @Override
- public double[] getCDF(final long[] splitPoints, final
QuantileSearchCriteria searchCrit) {
- if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
- refreshSortedView();
- return longsSV.getCDF(splitPoints, searchCrit);
- }
- @Override
- public double[] getPMF(final long[] splitPoints, final
QuantileSearchCriteria searchCrit) {
- if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
- refreshSortedView();
- return longsSV.getPMF(splitPoints, searchCrit);
+ */
+ private void updateLong(final long[] srcItems, final int srcOffset, final
int length) {
+ if (isEmpty()) {
+ setMinItem(srcItems[srcOffset]); //initialize with a real value
+ setMaxItem(srcItems[srcOffset]);
}
- @Override
- public long getQuantile(final double rank, final QuantileSearchCriteria
searchCrit) {
- if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
- refreshSortedView();
- return longsSV.getQuantile(rank, searchCrit);
+ int count = 0;
+ while (count < length) {
+ if (levelsArr[0] == 0) {
+ KllLongsHelper.compressWhileUpdatingSketch(this);
+ }
+ final int spaceNeeded = length - count;
+ final int freeSpace = levelsArr[0];
+ assert (freeSpace > 0);
+ final int numItemsToCopy = min(spaceNeeded, freeSpace);
+ final int dstOffset = freeSpace - numItemsToCopy;
+ final int localSrcOffset = srcOffset + count;
+ setLongItemsArrayAt(dstOffset, srcItems, localSrcOffset, numItemsToCopy);
+ updateMinMax(srcItems, localSrcOffset, numItemsToCopy);
+ count += numItemsToCopy;
+ incN(numItemsToCopy);
+ setLevelsArrayAt(0, dstOffset);
}
+ setLevelZeroSorted(false);
+ }
- @Override
- public long[] getQuantiles(final double[] ranks, final
QuantileSearchCriteria searchCrit) {
- if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
- refreshSortedView();
- final int len = ranks.length;
- final long[] quantiles = new long[len];
- for (int i = 0; i < len; i++) {
- quantiles[i] = longsSV.getQuantile(ranks[i], searchCrit);
- }
- return quantiles;
+ /**
+ * Vector update of min and max.
+ * @param srcItems the input source array of values, no NaNs allowed.
+ * @param srcOffset the starting offset in srcItems
+ * @param length the number of items to update min and max
+ */
+ private void updateMinMax(final long[] srcItems, final int srcOffset, final
int length) {
+ final int end = srcOffset + length;
+ for (int i = srcOffset; i < end; i++) {
+ setMinItem(min(getMinItemInternal(), srcItems[i]));
+ setMaxItem(max(getMaxItemInternal(), srcItems[i]));
}
+ }
+ /* Align with KllDoublesSketch
- /**
- * {@inheritDoc}
- * The approximate probability that the true quantile is within the
confidence interval
- * specified by the upper and lower quantile bounds for this sketch is
0.99.
- */
- @Override
- public long getQuantileLowerBound(final double rank) {
- return getQuantile(max(0, rank -
KllHelper.getNormalizedRankError(getMinK(), false)));
- }
- /**
- * {@inheritDoc}
- * The approximate probability that the true quantile is within the
confidence interval
- * specified by the upper and lower quantile bounds for this sketch is
0.99.
- */
- @Override
- public long getQuantileUpperBound(final double rank) {
- return getQuantile(min(1.0, rank +
KllHelper.getNormalizedRankError(getMinK(), false)));
- }
- @Override
- public double getRank(final long quantile, final QuantileSearchCriteria
searchCrit) {
- if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
- refreshSortedView();
- return longsSV.getRank(quantile, searchCrit);
- }
- /**
- * {@inheritDoc}
- * The approximate probability that the true rank is within the confidence
interval
- * specified by the upper and lower rank bounds for this sketch is 0.99.
- */
- @Override
- public double getRankLowerBound(final double rank) {
- return max(0.0, rank - KllHelper.getNormalizedRankError(getMinK(),
false));
- }
- /**
- * {@inheritDoc}
- * The approximate probability that the true rank is within the confidence
interval
- * specified by the upper and lower rank bounds for this sketch is 0.99.
- */
- @Override
- public double getRankUpperBound(final double rank) {
- return min(1.0, rank + KllHelper.getNormalizedRankError(getMinK(),
false));
- }
- @Override
- public double[] getRanks(final long[] quantiles, final
QuantileSearchCriteria searchCrit) {
- if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
- refreshSortedView();
- final int len = quantiles.length;
- final double[] ranks = new double[len];
- for (int i = 0; i < len; i++) {
- ranks[i] = longsSV.getRank(quantiles[i], searchCrit);
- }
- return ranks;
- }
- @Override
- public QuantilesLongsSketchIterator iterator() {
- return new KllLongsSketchIterator(
- getLongItemsArray(),
getLevelsArray(SketchStructure.UPDATABLE), getNumLevels());
- }
- @Override
- public final void merge(final KllSketch other) {
- if (readOnly || sketchStructure != UPDATABLE) { throw new
SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
- if (this == other) { throw new
SketchesArgumentException(SELF_MERGE_MSG); }
- final KllLongsSketch otherLngSk = (KllLongsSketch)other;
- if (otherLngSk.isEmpty()) { return; }
- KllLongsHelper.mergeLongsImpl(this, otherLngSk);
- longsSV = null;
- }
+ */
+ // END ALL UPDATE METHODS
- /**
- * {@inheritDoc}
- * <p>The parameter <i>k</i> will not change.</p>
- */
- @Override
- public final void reset() {
- if (readOnly) { throw new
SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
- final int k = getK();
- setN(0);
- setMinK(k);
- setNumLevels(1);
- setLevelZeroSorted(false);
- setLevelsArray(new int[] {k, k});
- setMinItem(Long.MAX_VALUE);
- setMaxItem(Long.MIN_VALUE);
- setLongItemsArray(new long[k]);
- longsSV = null;
- }
+ /**
+ * @return full size of internal items array including empty space at bottom.
+ */
+ abstract long[] getLongItemsArray();
- @Override
- public byte[] toByteArray() {
- return KllHelper.toByteArray(this, false);
- }
+ /**
+ * @return items array of retained items.
+ */
+ abstract long[] getLongRetainedItemsArray();
- @Override
- public String toString(final boolean withLevels, final boolean
withLevelsAndItems) {
- KllSketch sketch = this;
- if (withLevelsAndItems && sketchStructure != UPDATABLE) {
- final Memory mem = getWritableMemory();
- assert mem != null;
- sketch = KllLongsSketch.heapify(getWritableMemory());
- }
- return KllHelper.toStringImpl(sketch, withLevels, withLevelsAndItems,
getSerDe());
- }
+ abstract long getLongSingleItem();
- //SINGLE UPDATE
+ // Min & Max Methods
- @Override
- public void update(final long item) {
- if (readOnly) { throw new
SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
- updateLong(this, item);
- longsSV = null;
- }
+ abstract long getMaxItemInternal();
- //Also Called from KllLongsHelper::merge
- static void updateLong(final KllLongsSketch lngSk, final long item) {
- lngSk.updateMinMax(item);
- int freeSpace = lngSk.levelsArr[0];
- assert (freeSpace >= 0);
- if (freeSpace == 0) {
- KllLongsHelper.compressWhileUpdatingSketch(lngSk);
- freeSpace = lngSk.levelsArr[0];
- assert (freeSpace > 0);
- }
- lngSk.incN(1);
- lngSk.setLevelZeroSorted(false);
- final int nextPos = freeSpace - 1;
- lngSk.setLevelsArrayAt(0, nextPos);
- lngSk.setLongItemsArrayAt(nextPos, item);
- }
+ abstract void setMaxItem(long item);
- /**
- * Single update of min and max
- * @param item the source item, it must not be a NaN.
- */
- final void updateMinMax(final long item) {
- if (isEmpty()) {
- setMinItem(item);
- setMaxItem(item);
- } else {
- setMinItem(min(getMinItemInternal(), item));
- setMaxItem(max(getMaxItemInternal(), item));
- }
- }
+ abstract long getMinItemInternal();
- //WEIGHTED UPDATE
-
- /**
- * Weighted update. Updates this sketch with the given item the number of
times specified by the given integer weight.
- * @param item the item to be repeated. NaNs are ignored.
- * @param weight the number of times the update of item is to be repeated.
It must be ≥ one.
- */
- public void update(final long item, final long weight) {
- if (readOnly) { throw new
SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
- if (weight < 1L) { throw new SketchesArgumentException("Weight is less
than one."); }
- if (weight == 1L) { updateLong(this, item); }
- else {
- if (weight < levelsArr[0]) {
- for (int i = 0; i < (int)weight; i++) { updateLong(this,
item); }
- } else {
- final KllHeapLongsSketch tmpSk = new
KllHeapLongsSketch(getK(), DEFAULT_M, item, weight);
- merge(tmpSk);
- }
- }
- longsSV = null;
- }
+ abstract void setMinItem(long item);
- // VECTOR UPDATE
-
- /**
- * Vector update. Updates this sketch with the given array (vector) of
items, starting at the items
- * offset for a length number of items. This is not supported for direct
sketches.
- * @param items the vector of items
- * @param offset the starting index of the items[] array
- * @param length the number of items
- */
- public void update(final long[] items, final int offset, final int length)
{
- if (readOnly) { throw new
SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
- if (length == 0) { return; }
- updateLong(items, offset, length);
- longsSV = null;
- }
+ @Override
+ abstract byte[] getMinMaxByteArr();
- private void updateLong(final long[] srcItems, final int srcOffset, final
int length) {
- if (isEmpty()) {
- setMinItem(srcItems[srcOffset]); //initialize with a real value
- setMaxItem(srcItems[srcOffset]);
- }
+ @Override
+ int getMinMaxSizeBytes() {
+ return Long.BYTES * 2;
+ }
- int count = 0;
- while (count < length) {
- if (levelsArr[0] == 0) {
- KllLongsHelper.compressWhileUpdatingSketch(this);
- }
- final int spaceNeeded = length - count;
- final int freeSpace = levelsArr[0];
- assert (freeSpace > 0);
- final int numItemsToCopy = min(spaceNeeded, freeSpace);
- final int dstOffset = freeSpace - numItemsToCopy;
- final int localSrcOffset = srcOffset + count;
- setLongItemsArrayAt(dstOffset, srcItems, localSrcOffset,
numItemsToCopy);
- updateMinMax(srcItems, localSrcOffset, numItemsToCopy);
- count += numItemsToCopy;
- incN(numItemsToCopy);
- setLevelsArrayAt(0, dstOffset);
- }
- setLevelZeroSorted(false);
- }
+ //END Min & Max Methods
- /**
- * Vector update of min and max.
- * @param srcItems the input source array of values, no NaNs allowed.
- * @param srcOffset the starting offset in srcItems
- * @param length the number of items to update min and max
- */
- private void updateMinMax(final long[] srcItems, final int srcOffset,
final int length) {
- final int end = srcOffset + length;
- for (int i = srcOffset; i < end; i++) {
- setMinItem(min(getMinItemInternal(), srcItems[i]));
- setMaxItem(max(getMaxItemInternal(), srcItems[i]));
- }
- }
-
- // END ALL UPDATE METHODS
-
- /**
- * @return full size of internal items array including empty space at
bottom.
- */
- abstract long[] getLongItemsArray();
-
- /**
- * @return items array of retained items.
- */
- abstract long[] getLongRetainedItemsArray();
-
- abstract long getLongSingleItem();
-
- // Min & Max Methods
-
- abstract long getMaxItemInternal();
-
- abstract void setMaxItem(long item);
+ @Override
+ abstract byte[] getRetainedItemsByteArr();
- abstract long getMinItemInternal();
+ @Override
+ int getRetainedItemsSizeBytes() {
+ return getNumRetained() * Long.BYTES;
+ }
- abstract void setMinItem(long item);
+ @Override
+ ArrayOfItemsSerDe<?> getSerDe() { return null; }
- @Override
- abstract byte[] getMinMaxByteArr();
+ @Override
+ final byte[] getSingleItemByteArr() {
+ final byte[] bytes = new byte[ITEM_BYTES];
+ putLongLE(bytes, 0, getLongSingleItem());
+ return bytes;
+ }
+
+ @Override
+ int getSingleItemSizeBytes() {
+ return Long.BYTES;
+ }
- @Override
- int getMinMaxSizeBytes() {
- return Long.BYTES * 2;
- }
+ @Override
+ abstract byte[] getTotalItemsByteArr();
+
+ @Override
+ int getTotalItemsNumBytes() {
+ return levelsArr[getNumLevels()] * Long.BYTES;
+ }
- //END Min & Max Methods
+ abstract void setLongItemsArray(long[] longItems);
- @Override
- abstract byte[] getRetainedItemsByteArr();
+ abstract void setLongItemsArrayAt(int index, long item);
- @Override
- int getRetainedItemsSizeBytes() {
- return getNumRetained() * Long.BYTES;
- }
+ abstract void setLongItemsArrayAt(int dstIndex, long[] srcItems, int
srcOffset, int length);
- @Override
- ArrayOfItemsSerDe<?> getSerDe() { return null; }
+ // SORTED VIEW
- @Override
- final byte[] getSingleItemByteArr() {
- final byte[] bytes = new byte[ITEM_BYTES];
- putLongLE(bytes, 0, getLongSingleItem());
- return bytes;
- }
+ @Override
+ @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "OK in this
case.")
+ public LongsSketchSortedView getSortedView() {
+ refreshSortedView();
+ return longsSV;
+ }
- @Override
- int getSingleItemSizeBytes() {
- return Long.BYTES;
+ private final LongsSketchSortedView refreshSortedView() {
+ if (longsSV == null) {
+ final CreateSortedView csv = new CreateSortedView();
+ longsSV = csv.getSV();
}
+ return longsSV;
+ }
- @Override
- abstract byte[] getTotalItemsByteArr();
-
- @Override
- int getTotalItemsNumBytes() {
- return levelsArr[getNumLevels()] * Long.BYTES;
- }
+ private final class CreateSortedView {
+ long[] quantiles;
+ long[] cumWeights;
- abstract void setLongItemsArray(long[] longItems);
+ LongsSketchSortedView getSV() {
+ if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
+ final long[] srcQuantiles = getLongItemsArray();
+ final int[] srcLevels = levelsArr;
+ final int srcNumLevels = getNumLevels();
- abstract void setLongItemsArrayAt(int index, long item);
-
- abstract void setLongItemsArrayAt(int dstIndex, long[] srcItems, int
srcOffset, int length);
-
- // SORTED VIEW
-
- @Override
- @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "OK in this
case.")
- public LongsSketchSortedView getSortedView() {
- refreshSortedView();
- return longsSV;
- }
-
- private final LongsSketchSortedView refreshSortedView() {
- if (longsSV == null) {
- final CreateSortedView csv = new CreateSortedView();
- longsSV = csv.getSV();
+ if (!isLevelZeroSorted()) {
+ Arrays.sort(srcQuantiles, srcLevels[0], srcLevels[1]);
+ if (!hasMemory()) { setLevelZeroSorted(true); }
+ //we don't sort level0 in Memory, only our copy.
+ }
+ final int numQuantiles = getNumRetained();
+ quantiles = new long[numQuantiles];
+ cumWeights = new long[numQuantiles];
+ populateFromSketch(srcQuantiles, srcLevels, srcNumLevels, numQuantiles);
+ return new LongsSketchSortedView(
+ quantiles, cumWeights, KllLongsSketch.this);
+ }
+
+ private void populateFromSketch(final long[] srcQuantiles, final int[]
srcLevels,
+ final int srcNumLevels, final int numItems) {
+ final int[] myLevels = new int[srcNumLevels + 1];
+ final int offset = srcLevels[0];
+ System.arraycopy(srcQuantiles, offset, quantiles, 0, numItems);
+ int srcLevel = 0;
+ int dstLevel = 0;
+ long weight = 1;
+ while (srcLevel < srcNumLevels) {
+ final int fromIndex = srcLevels[srcLevel] - offset;
+ final int toIndex = srcLevels[srcLevel + 1] - offset; // exclusive
+ if (fromIndex < toIndex) { // if equal, skip empty level
+ Arrays.fill(cumWeights, fromIndex, toIndex, weight);
+ myLevels[dstLevel] = fromIndex;
+ myLevels[dstLevel + 1] = toIndex;
+ dstLevel++;
}
- return longsSV;
- }
-
- private final class CreateSortedView {
- long[] quantiles;
- long[] cumWeights;
-
- LongsSketchSortedView getSV() {
- if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
- final long[] srcQuantiles = getLongItemsArray();
- final int[] srcLevels = levelsArr;
- final int srcNumLevels = getNumLevels();
-
- if (!isLevelZeroSorted()) {
- Arrays.sort(srcQuantiles, srcLevels[0], srcLevels[1]);
- if (!hasMemory()) { setLevelZeroSorted(true); }
- //we don't sort level0 in Memory, only our copy.
- }
- final int numQuantiles = getNumRetained();
- quantiles = new long[numQuantiles];
- cumWeights = new long[numQuantiles];
- populateFromSketch(srcQuantiles, srcLevels, srcNumLevels,
numQuantiles);
- return new LongsSketchSortedView(
- quantiles, cumWeights, KllLongsSketch.this);
- }
-
- private void populateFromSketch(final long[] srcQuantiles, final int[]
srcLevels,
- final int srcNumLevels, final int
numItems) {
- final int[] myLevels = new int[srcNumLevels + 1];
- final int offset = srcLevels[0];
- System.arraycopy(srcQuantiles, offset, quantiles, 0, numItems);
- int srcLevel = 0;
- int dstLevel = 0;
- long weight = 1;
- while (srcLevel < srcNumLevels) {
- final int fromIndex = srcLevels[srcLevel] - offset;
- final int toIndex = srcLevels[srcLevel + 1] - offset; //
exclusive
- if (fromIndex < toIndex) { // if equal, skip empty level
- Arrays.fill(cumWeights, fromIndex, toIndex, weight);
- myLevels[dstLevel] = fromIndex;
- myLevels[dstLevel + 1] = toIndex;
- dstLevel++;
- }
- srcLevel++;
- weight *= 2;
- }
- final int numLevels = dstLevel;
- blockyTandemMergeSort(quantiles, cumWeights, myLevels, numLevels);
//create unit weights
- KllHelper.convertToCumulative(cumWeights);
- }
- } //End of class CreateSortedView
-
- private static void blockyTandemMergeSort(final long[] quantiles, final
long[] weights,
- final int[] levels, final int
numLevels) {
- if (numLevels == 1) { return; }
-
- // duplicate the input in preparation for the "ping-pong" copy
reduction strategy.
- final long[] quantilesTmp = Arrays.copyOf(quantiles, quantiles.length);
- final long[] weightsTmp = Arrays.copyOf(weights, quantiles.length); //
don't need the extra one
-
- blockyTandemMergeSortRecursion(quantilesTmp, weightsTmp, quantiles,
weights, levels, 0, numLevels);
- }
-
- private static void blockyTandemMergeSortRecursion(
- final long[] quantilesSrc, final long[] weightsSrc,
- final long[] quantilesDst, final long[] weightsDst,
- final int[] levels, final int startingLevel, final int numLevels) {
- if (numLevels == 1) { return; }
- final int numLevels1 = numLevels / 2;
- final int numLevels2 = numLevels - numLevels1;
- assert numLevels1 >= 1;
- assert numLevels2 >= numLevels1;
- final int startingLevel1 = startingLevel;
- final int startingLevel2 = startingLevel + numLevels1;
- // swap roles of src and dst
- blockyTandemMergeSortRecursion(
- quantilesDst, weightsDst,
- quantilesSrc, weightsSrc,
- levels, startingLevel1, numLevels1);
- blockyTandemMergeSortRecursion(
- quantilesDst, weightsDst,
- quantilesSrc, weightsSrc,
- levels, startingLevel2, numLevels2);
- tandemMerge(
- quantilesSrc, weightsSrc,
- quantilesDst, weightsDst,
- levels,
- startingLevel1, numLevels1,
- startingLevel2, numLevels2);
- }
-
- private static void tandemMerge(
- final long[] quantilesSrc, final long[] weightsSrc,
- final long[] quantilesDst, final long[] weightsDst,
- final int[] levelStarts,
- final int startingLevel1, final int numLevels1,
- final int startingLevel2, final int numLevels2) {
- final int fromIndex1 = levelStarts[startingLevel1];
- final int toIndex1 = levelStarts[startingLevel1 + numLevels1]; //
exclusive
- final int fromIndex2 = levelStarts[startingLevel2];
- final int toIndex2 = levelStarts[startingLevel2 + numLevels2]; //
exclusive
- int iSrc1 = fromIndex1;
- int iSrc2 = fromIndex2;
- int iDst = fromIndex1;
-
- while (iSrc1 < toIndex1 && iSrc2 < toIndex2) {
- if (quantilesSrc[iSrc1] < quantilesSrc[iSrc2]) {
- quantilesDst[iDst] = quantilesSrc[iSrc1];
- weightsDst[iDst] = weightsSrc[iSrc1];
- iSrc1++;
- } else {
- quantilesDst[iDst] = quantilesSrc[iSrc2];
- weightsDst[iDst] = weightsSrc[iSrc2];
- iSrc2++;
- }
- iDst++;
- }
- if (iSrc1 < toIndex1) {
- System.arraycopy(quantilesSrc, iSrc1, quantilesDst, iDst, toIndex1
- iSrc1);
- System.arraycopy(weightsSrc, iSrc1, weightsDst, iDst, toIndex1 -
iSrc1);
- } else if (iSrc2 < toIndex2) {
- System.arraycopy(quantilesSrc, iSrc2, quantilesDst, iDst, toIndex2
- iSrc2);
- System.arraycopy(weightsSrc, iSrc2, weightsDst, iDst, toIndex2 -
iSrc2);
- }
- }
-
- // END SORTED VIEW
+ srcLevel++;
+ weight *= 2;
+ }
+ final int numLevels = dstLevel;
+ blockyTandemMergeSort(quantiles, cumWeights, myLevels, numLevels);
//create unit weights
+ KllHelper.convertToCumulative(cumWeights);
+ }
+ } //End of class CreateSortedView
+
+ private static void blockyTandemMergeSort(final long[] quantiles, final
long[] weights,
+ final int[] levels, final int numLevels) {
+ if (numLevels == 1) { return; }
+
+ // duplicate the input in preparation for the "ping-pong" copy reduction
strategy.
+ final long[] quantilesTmp = Arrays.copyOf(quantiles, quantiles.length);
+ final long[] weightsTmp = Arrays.copyOf(weights, quantiles.length); //
don't need the extra one
+
+ blockyTandemMergeSortRecursion(quantilesTmp, weightsTmp, quantiles,
weights, levels, 0, numLevels);
+ }
+
+ private static void blockyTandemMergeSortRecursion(
+ final long[] quantilesSrc, final long[] weightsSrc,
+ final long[] quantilesDst, final long[] weightsDst,
+ final int[] levels, final int startingLevel, final int numLevels) {
+ if (numLevels == 1) { return; }
+ final int numLevels1 = numLevels / 2;
+ final int numLevels2 = numLevels - numLevels1;
+ assert numLevels1 >= 1;
+ assert numLevels2 >= numLevels1;
+ final int startingLevel1 = startingLevel;
+ final int startingLevel2 = startingLevel + numLevels1;
+ // swap roles of src and dst
+ blockyTandemMergeSortRecursion(
+ quantilesDst, weightsDst,
+ quantilesSrc, weightsSrc,
+ levels, startingLevel1, numLevels1);
+ blockyTandemMergeSortRecursion(
+ quantilesDst, weightsDst,
+ quantilesSrc, weightsSrc,
+ levels, startingLevel2, numLevels2);
+ tandemMerge(
+ quantilesSrc, weightsSrc,
+ quantilesDst, weightsDst,
+ levels,
+ startingLevel1, numLevels1,
+ startingLevel2, numLevels2);
+ }
+
+ private static void tandemMerge(
+ final long[] quantilesSrc, final long[] weightsSrc,
+ final long[] quantilesDst, final long[] weightsDst,
+ final int[] levelStarts,
+ final int startingLevel1, final int numLevels1,
+ final int startingLevel2, final int numLevels2) {
+ final int fromIndex1 = levelStarts[startingLevel1];
+ final int toIndex1 = levelStarts[startingLevel1 + numLevels1]; // exclusive
+ final int fromIndex2 = levelStarts[startingLevel2];
+ final int toIndex2 = levelStarts[startingLevel2 + numLevels2]; // exclusive
+ int iSrc1 = fromIndex1;
+ int iSrc2 = fromIndex2;
+ int iDst = fromIndex1;
+
+ while (iSrc1 < toIndex1 && iSrc2 < toIndex2) {
+ if (quantilesSrc[iSrc1] < quantilesSrc[iSrc2]) {
+ quantilesDst[iDst] = quantilesSrc[iSrc1];
+ weightsDst[iDst] = weightsSrc[iSrc1];
+ iSrc1++;
+ } else {
+ quantilesDst[iDst] = quantilesSrc[iSrc2];
+ weightsDst[iDst] = weightsSrc[iSrc2];
+ iSrc2++;
+ }
+ iDst++;
+ }
+ if (iSrc1 < toIndex1) {
+ System.arraycopy(quantilesSrc, iSrc1, quantilesDst, iDst, toIndex1 -
iSrc1);
+ System.arraycopy(weightsSrc, iSrc1, weightsDst, iDst, toIndex1 - iSrc1);
+ } else if (iSrc2 < toIndex2) {
+ System.arraycopy(quantilesSrc, iSrc2, quantilesDst, iDst, toIndex2 -
iSrc2);
+ System.arraycopy(weightsSrc, iSrc2, weightsDst, iDst, toIndex2 - iSrc2);
+ }
+ }
+
+ // END SORTED VIEW
}
diff --git a/src/main/java/org/apache/datasketches/kll/KllPreambleUtil.java
b/src/main/java/org/apache/datasketches/kll/KllPreambleUtil.java
index f486eabf..f2c3847a 100644
--- a/src/main/java/org/apache/datasketches/kll/KllPreambleUtil.java
+++ b/src/main/java/org/apache/datasketches/kll/KllPreambleUtil.java
@@ -25,7 +25,10 @@ import static org.apache.datasketches.common.Util.zeroPad;
import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_FULL;
import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_SINGLE;
import static org.apache.datasketches.kll.KllSketch.SketchStructure.UPDATABLE;
-import static org.apache.datasketches.kll.KllSketch.SketchType.*;
+import static org.apache.datasketches.kll.KllSketch.SketchType.DOUBLES_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.FLOATS_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.ITEMS_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
import java.util.Objects;
diff --git a/src/main/java/org/apache/datasketches/kll/KllSketch.java
b/src/main/java/org/apache/datasketches/kll/KllSketch.java
index c517a9e8..03b3a2be 100644
--- a/src/main/java/org/apache/datasketches/kll/KllSketch.java
+++ b/src/main/java/org/apache/datasketches/kll/KllSketch.java
@@ -31,7 +31,10 @@ import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_EMPT
import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_FULL;
import static
org.apache.datasketches.kll.KllSketch.SketchStructure.COMPACT_SINGLE;
import static org.apache.datasketches.kll.KllSketch.SketchStructure.UPDATABLE;
-import static org.apache.datasketches.kll.KllSketch.SketchType.*;
+import static org.apache.datasketches.kll.KllSketch.SketchType.DOUBLES_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.FLOATS_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.ITEMS_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
import java.util.Arrays;
import java.util.Random;
diff --git
a/src/main/java/org/apache/datasketches/quantilescommon/DoublesSortedView.java
b/src/main/java/org/apache/datasketches/quantilescommon/DoublesSortedView.java
index bdc3cc75..98616661 100644
---
a/src/main/java/org/apache/datasketches/quantilescommon/DoublesSortedView.java
+++
b/src/main/java/org/apache/datasketches/quantilescommon/DoublesSortedView.java
@@ -148,7 +148,7 @@ public interface DoublesSortedView extends SortedView {
* the quantile directly corresponding to the given rank.
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
- * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
+ * @see QuantileSearchCriteria
*/
double getQuantile(double rank, QuantileSearchCriteria searchCrit);
@@ -165,7 +165,7 @@ public interface DoublesSortedView extends SortedView {
* @param searchCrit if INCLUSIVE the given quantile is included into the
rank.
* @return the normalized rank corresponding to the given quantile.
* @throws IllegalArgumentException if sketch is empty.
- * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
+ * @see QuantileSearchCriteria
*/
double getRank(double quantile, QuantileSearchCriteria searchCrit);
@@ -173,4 +173,3 @@ public interface DoublesSortedView extends SortedView {
DoublesSortedViewIterator iterator();
}
-
diff --git
a/src/main/java/org/apache/datasketches/quantilescommon/LongsSketchSortedView.java
b/src/main/java/org/apache/datasketches/quantilescommon/LongsSketchSortedView.java
index 1fcd5cf7..efb4006f 100644
---
a/src/main/java/org/apache/datasketches/quantilescommon/LongsSketchSortedView.java
+++
b/src/main/java/org/apache/datasketches/quantilescommon/LongsSketchSortedView.java
@@ -19,16 +19,16 @@
package org.apache.datasketches.quantilescommon;
-import org.apache.datasketches.common.SketchesArgumentException;
-import org.apache.datasketches.quantilescommon.IncludeMinMax.LongsPair;
-
-import static
org.apache.datasketches.quantilescommon.IncludeMinMax.DoublesPair;
import static
org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
import static org.apache.datasketches.quantilescommon.QuantilesAPI.EMPTY_MSG;
import static
org.apache.datasketches.quantilescommon.QuantilesUtil.getNaturalRank;
+import org.apache.datasketches.common.SketchesArgumentException;
+import org.apache.datasketches.quantilescommon.IncludeMinMax.LongsPair;
+
/**
* The SortedView of the KllLongsSketch.
+ * @author Lee Rhodes
* @author Zac Blanco
*/
public final class LongsSketchSortedView implements LongsSortedView {
diff --git
a/src/main/java/org/apache/datasketches/quantilescommon/LongsSortedView.java
b/src/main/java/org/apache/datasketches/quantilescommon/LongsSortedView.java
index 8295635b..4823edd1 100644
--- a/src/main/java/org/apache/datasketches/quantilescommon/LongsSortedView.java
+++ b/src/main/java/org/apache/datasketches/quantilescommon/LongsSortedView.java
@@ -22,13 +22,14 @@ package org.apache.datasketches.quantilescommon;
/**
* The Sorted View for quantile sketches of primitive type long.
* @see SortedView
+ * @author Lee Rhodes
* @author Zac Blanco
*/
public interface LongsSortedView extends SortedView {
/**
* Returns an approximation to the Cumulative Distribution Function (CDF) of
the input stream
- * as a monotonically increasing array of long ranks (or cumulative
probabilities) on the interval [0.0, 1.0],
+ * as a monotonically increasing array of double ranks (or cumulative
probabilities) on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can
be obtained from the
@@ -56,7 +57,7 @@ public interface LongsSortedView extends SortedView {
* <p>It is not recommended to include either the minimum or maximum items
of the input stream.</p>
*
* @param searchCrit the desired search criteria.
- * @return a discrete CDF array of m+1 long ranks (or cumulative
probabilities) on the interval [0.0, 1.0].
+ * @return a discrete CDF array of m+1 double ranks (or cumulative
probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getCDF(long[] splitPoints, QuantileSearchCriteria
searchCrit) {
@@ -90,7 +91,7 @@ public interface LongsSortedView extends SortedView {
/**
* Returns an approximation to the Probability Mass Function (PMF) of the
input stream
- * as an array of probability masses as longs on the interval [0.0, 1.0],
+ * as an array of probability masses as doubles on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can
be obtained from the
@@ -125,7 +126,7 @@ public interface LongsSortedView extends SortedView {
* <p>It is not recommended to include either the minimum or maximum items
of the input stream.</p>
*
* @param searchCrit the desired search criteria.
- * @return a PMF array of m+1 probability masses as longs on the interval
[0.0, 1.0].
+ * @return a PMF array of m+1 probability masses as doubles on the interval
[0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getPMF(long[] splitPoints, QuantileSearchCriteria
searchCrit) {
@@ -140,7 +141,7 @@ public interface LongsSortedView extends SortedView {
/**
* Gets the approximate quantile of the given normalized rank and the given
search criterion.
*
- * @param rank the given normalized rank, a long in the range [0.0, 1.0].
+ * @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @param searchCrit If INCLUSIVE, the given rank includes all quantiles ≤
* the quantile directly corresponding to the given rank.
* If EXCLUSIVE, he given rank includes all quantiles <
@@ -172,4 +173,3 @@ public interface LongsSortedView extends SortedView {
LongsSortedViewIterator iterator();
}
-
diff --git
a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesLongsAPI.java
b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesLongsAPI.java
index 767e9e48..2b542a68 100644
---
a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesLongsAPI.java
+++
b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesLongsAPI.java
@@ -24,277 +24,277 @@ import static
org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INC
/**
* The Quantiles API for item type <i>long</i>.
* @see QuantilesAPI
- *
+ * @author Lee Rhodes
* @author Zac Blanco
*/
public interface QuantilesLongsAPI extends QuantilesAPI {
- /**
- * This is equivalent to {@link #getCDF(long[], QuantileSearchCriteria)
getCDF(splitPoints, INCLUSIVE)}
- * @param splitPoints an array of <i>m</i> unique, monotonically
increasing items.
- * @return a discrete CDF array of m+1 long ranks (or cumulative
probabilities) on the interval [0.0, 1.0].
- * @throws IllegalArgumentException if sketch is empty.
- */
- default double[] getCDF(long[] splitPoints) {
- return getCDF(splitPoints, INCLUSIVE);
- }
+ /**
+ * This is equivalent to {@link #getCDF(long[], QuantileSearchCriteria)
getCDF(splitPoints, INCLUSIVE)}
+ * @param splitPoints an array of <i>m</i> unique, monotonically increasing
items.
+ * @return a discrete CDF array of m+1 double ranks (or cumulative
probabilities) on the interval [0.0, 1.0].
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ default double[] getCDF(long[] splitPoints) {
+ return getCDF(splitPoints, INCLUSIVE);
+ }
- /**
- * Returns an approximation to the Cumulative Distribution Function (CDF)
of the input stream
- * as a monotonically increasing array of long ranks (or cumulative
probabilities) on the interval [0.0, 1.0],
- * given a set of splitPoints.
- *
- * <p>The resulting approximations have a probabilistic guarantee that can
be obtained from the
- * getNormalizedRankError(false) function.</p>
- *
- * @param splitPoints an array of <i>m</i> unique, monotonically
increasing items
- * (of the same type as the input items)
- * that divide the item input domain into <i>m+1</i> overlapping intervals.
- *
- * <p>The start of each interval is below the lowest item retained by the
sketch
- * corresponding to a zero rank or zero probability, and the end of the
interval
- * is the rank or cumulative probability corresponding to the split
point.</p>
- *
- * <p>The <i>(m+1)th</i> interval represents 100% of the distribution
represented by the sketch
- * and consistent with the definition of a cumulative probability
distribution, thus the <i>(m+1)th</i>
- * rank or probability in the returned array is always 1.0.</p>
- *
- * <p>If a split point exactly equals a retained item of the sketch and
the search criterion is:</p>
- *
- * <ul>
- * <li>INCLUSIVE, the resulting cumulative probability will include that
item.</li>
- * <li>EXCLUSIVE, the resulting cumulative probability will not include
the weight of that split point.</li>
- * </ul>
- *
- * <p>It is not recommended to include either the minimum or maximum items
of the input stream.</p>
- *
- * @param searchCrit the desired search criteria.
- * @return a discrete CDF array of m+1 long ranks (or cumulative
probabilities) on the interval [0.0, 1.0].
- * @throws IllegalArgumentException if sketch is empty.
- */
- double[] getCDF(long[] splitPoints, QuantileSearchCriteria searchCrit);
+ /**
+ * Returns an approximation to the Cumulative Distribution Function (CDF) of
the input stream
+ * as a monotonically increasing array of double ranks (or cumulative
probabilities) on the interval [0.0, 1.0],
+ * given a set of splitPoints.
+ *
+ * <p>The resulting approximations have a probabilistic guarantee that can
be obtained from the
+ * getNormalizedRankError(false) function.</p>
+ *
+ * @param splitPoints an array of <i>m</i> unique, monotonically increasing
items
+ * (of the same type as the input items)
+ * that divide the item input domain into <i>m+1</i> overlapping intervals.
+ *
+ * <p>The start of each interval is below the lowest item retained by the
sketch
+ * corresponding to a zero rank or zero probability, and the end of the
interval
+ * is the rank or cumulative probability corresponding to the split
point.</p>
+ *
+ * <p>The <i>(m+1)th</i> interval represents 100% of the distribution
represented by the sketch
+ * and consistent with the definition of a cumulative probability
distribution, thus the <i>(m+1)th</i>
+ * rank or probability in the returned array is always 1.0.</p>
+ *
+ * <p>If a split point exactly equals a retained item of the sketch and the
search criterion is:</p>
+ *
+ * <ul>
+ * <li>INCLUSIVE, the resulting cumulative probability will include that
item.</li>
+ * <li>EXCLUSIVE, the resulting cumulative probability will not include the
weight of that split point.</li>
+ * </ul>
+ *
+ * <p>It is not recommended to include either the minimum or maximum items
of the input stream.</p>
+ *
+ * @param searchCrit the desired search criteria.
+ * @return a discrete CDF array of m+1 double ranks (or cumulative
probabilities) on the interval [0.0, 1.0].
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ double[] getCDF(long[] splitPoints, QuantileSearchCriteria searchCrit);
- /**
- * Returns the maximum item of the stream. This is provided for
convenience and may be different from the
- * item returned by <i>getQuantile(1.0)</i>.
- *
- * @return the maximum item of the stream
- * @throws IllegalArgumentException if sketch is empty.
- */
- long getMaxItem();
+ /**
+ * Returns the maximum item of the stream. This is provided for convenience
and may be different from the
+ * item returned by <i>getQuantile(1.0)</i>.
+ *
+ * @return the maximum item of the stream
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ long getMaxItem();
- /**
- * Returns the minimum item of the stream. This is provided for
convenience and may be different from the
- * item returned by <i>getQuantile(0.0)</i>.
- *
- * @return the minimum item of the stream
- * @throws IllegalArgumentException if sketch is empty.
- */
- long getMinItem();
+ /**
+ * Returns the minimum item of the stream. This is provided for convenience
and may be different from the
+ * item returned by <i>getQuantile(0.0)</i>.
+ *
+ * @return the minimum item of the stream
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ long getMinItem();
- /**
- * This is equivalent to {@link #getPMF(long[], QuantileSearchCriteria)
getPMF(splitPoints, INCLUSIVE)}
- * @param splitPoints an array of <i>m</i> unique, monotonically
increasing items.
- * @return a PMF array of m+1 probability masses as longs on the interval
[0.0, 1.0].
- * @throws IllegalArgumentException if sketch is empty.
- */
- default double[] getPMF(long[] splitPoints) {
- return getPMF(splitPoints, INCLUSIVE);
- }
+ /**
+ * This is equivalent to {@link #getPMF(long[], QuantileSearchCriteria)
getPMF(splitPoints, INCLUSIVE)}
+ * @param splitPoints an array of <i>m</i> unique, monotonically increasing
items.
+ * @return a PMF array of m+1 probability masses as doubles on the interval
[0.0, 1.0].
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ default double[] getPMF(long[] splitPoints) {
+ return getPMF(splitPoints, INCLUSIVE);
+ }
- /**
- * Returns an approximation to the Probability Mass Function (PMF) of the
input stream
- * as an array of probability masses as longs on the interval [0.0, 1.0],
- * given a set of splitPoints.
- *
- * <p>The resulting approximations have a probabilistic guarantee that can
be obtained from the
- * getNormalizedRankError(true) function.</p>
- *
- * @param splitPoints an array of <i>m</i> unique, monotonically
increasing items
- * (of the same type as the input items)
- * that divide the item input domain into <i>m+1</i> consecutive,
non-overlapping intervals.
- *
- * <p>Each interval except for the end intervals starts with a split point
and ends with the next split
- * point in sequence.</p>
- *
- * <p>The first interval starts below the lowest item retained by the
sketch
- * corresponding to a zero rank or zero probability, and ends with the
first split point</p>
- *
- * <p>The last <i>(m+1)th</i> interval starts with the last split point
and ends after the last
- * item retained by the sketch corresponding to a rank or probability of
1.0. </p>
- *
- * <p>The sum of the probability masses of all <i>(m+1)</i> intervals is
1.0.</p>
- *
- * <p>If the search criterion is:</p>
- *
- * <ul>
- * <li>INCLUSIVE, and the upper split point of an interval equals an item
retained by the sketch, the interval
- * will include that item. If the lower split point equals an item
retained by the sketch, the interval will exclude
- * that item.</li>
- * <li>EXCLUSIVE, and the upper split point of an interval equals an item
retained by the sketch, the interval
- * will exclude that item. If the lower split point equals an item
retained by the sketch, the interval will include
- * that item.</li>
- * </ul>
- *
- * <p>It is not recommended to include either the minimum or maximum items
of the input stream.</p>
- *
- * @param searchCrit the desired search criteria.
- * @return a PMF array of m+1 probability masses as longs on the interval
[0.0, 1.0].
- * @throws IllegalArgumentException if sketch is empty.
- */
- double[] getPMF(long[] splitPoints, QuantileSearchCriteria searchCrit);
+ /**
+ * Returns an approximation to the Probability Mass Function (PMF) of the
input stream
+ * as an array of probability masses as doubles on the interval [0.0, 1.0],
+ * given a set of splitPoints.
+ *
+ * <p>The resulting approximations have a probabilistic guarantee that can
be obtained from the
+ * getNormalizedRankError(true) function.</p>
+ *
+ * @param splitPoints an array of <i>m</i> unique, monotonically increasing
items
+ * (of the same type as the input items)
+ * that divide the item input domain into <i>m+1</i> consecutive,
non-overlapping intervals.
+ *
+ * <p>Each interval except for the end intervals starts with a split point
and ends with the next split
+ * point in sequence.</p>
+ *
+ * <p>The first interval starts below the lowest item retained by the sketch
+ * corresponding to a zero rank or zero probability, and ends with the first
split point</p>
+ *
+ * <p>The last <i>(m+1)th</i> interval starts with the last split point and
ends after the last
+ * item retained by the sketch corresponding to a rank or probability of
1.0. </p>
+ *
+ * <p>The sum of the probability masses of all <i>(m+1)</i> intervals is
1.0.</p>
+ *
+ * <p>If the search criterion is:</p>
+ *
+ * <ul>
+ * <li>INCLUSIVE, and the upper split point of an interval equals an item
retained by the sketch, the interval
+ * will include that item. If the lower split point equals an item retained
by the sketch, the interval will exclude
+ * that item.</li>
+ * <li>EXCLUSIVE, and the upper split point of an interval equals an item
retained by the sketch, the interval
+ * will exclude that item. If the lower split point equals an item retained
by the sketch, the interval will include
+ * that item.</li>
+ * </ul>
+ *
+ * <p>It is not recommended to include either the minimum or maximum items
of the input stream.</p>
+ *
+ * @param searchCrit the desired search criteria.
+ * @return a PMF array of m+1 probability masses as doubles on the interval
[0.0, 1.0].
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ double[] getPMF(long[] splitPoints, QuantileSearchCriteria searchCrit);
- /**
- * This is equivalent to {@link #getQuantile(double,
QuantileSearchCriteria) getQuantile(rank, INCLUSIVE)}
- * @param rank the given normalized rank, a long in the range [0.0, 1.0].
- * @return the approximate quantile given the normalized rank.
- * @throws IllegalArgumentException if sketch is empty.
- */
- default long getQuantile(double rank) {
- return getQuantile(rank, INCLUSIVE);
- }
+ /**
+ * This is equivalent to {@link #getQuantile(double, QuantileSearchCriteria)
getQuantile(rank, INCLUSIVE)}
+ * @param rank the given normalized rank, a double in the range [0.0, 1.0].
+ * @return the approximate quantile given the normalized rank.
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ default long getQuantile(double rank) {
+ return getQuantile(rank, INCLUSIVE);
+ }
- /**
- * Gets the approximate quantile of the given normalized rank and the
given search criterion.
- *
- * @param rank the given normalized rank, a long in the range [0.0, 1.0].
- * @param searchCrit If INCLUSIVE, the given rank includes all quantiles
≤
- * the quantile directly corresponding to the given rank.
- * If EXCLUSIVE, he given rank includes all quantiles <
- * the quantile directly corresponding to the given rank.
- * @return the approximate quantile given the normalized rank.
- * @throws IllegalArgumentException if sketch is empty.
- * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
- */
- long getQuantile(double rank, QuantileSearchCriteria searchCrit);
+ /**
+ * Gets the approximate quantile of the given normalized rank and the given
search criterion.
+ *
+ * @param rank the given normalized rank, a double in the range [0.0, 1.0].
+ * @param searchCrit If INCLUSIVE, the given rank includes all quantiles ≤
+ * the quantile directly corresponding to the given rank.
+ * If EXCLUSIVE, he given rank includes all quantiles <
+ * the quantile directly corresponding to the given rank.
+ * @return the approximate quantile given the normalized rank.
+ * @throws IllegalArgumentException if sketch is empty.
+ * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
+ */
+ long getQuantile(double rank, QuantileSearchCriteria searchCrit);
- /**
- * Gets the lower bound of the quantile confidence interval in which the
quantile of the
- * given rank exists.
- *
- * <p>Although it is possible to estimate the probability that the true
quantile
- * exists within the quantile confidence interval specified by the upper
and lower quantile bounds,
- * it is not possible to guarantee the width of the quantile confidence
interval
- * as an additive or multiplicative percent of the true quantile.</p>
- *
- * @param rank the given normalized rank
- * @return the lower bound of the quantile confidence interval in which
the quantile of the
- * given rank exists.
- * @throws IllegalArgumentException if sketch is empty.
- */
- long getQuantileLowerBound(double rank);
+ /**
+ * Gets the lower bound of the quantile confidence interval in which the
quantile of the
+ * given rank exists.
+ *
+ * <p>Although it is possible to estimate the probability that the true
quantile
+ * exists within the quantile confidence interval specified by the upper and
lower quantile bounds,
+ * it is not possible to guarantee the width of the quantile confidence
interval
+ * as an additive or multiplicative percent of the true quantile.</p>
+ *
+ * @param rank the given normalized rank
+ * @return the lower bound of the quantile confidence interval in which the
quantile of the
+ * given rank exists.
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ long getQuantileLowerBound(double rank);
- /**
- * Gets the upper bound of the quantile confidence interval in which the
true quantile of the
- * given rank exists.
- *
- * <p>Although it is possible to estimate the probability that the true
quantile
- * exists within the quantile confidence interval specified by the upper
and lower quantile bounds,
- * it is not possible to guarantee the width of the quantile interval
- * as an additive or multiplicative percent of the true quantile.</p>
- *
- * @param rank the given normalized rank
- * @return the upper bound of the quantile confidence interval in which
the true quantile of the
- * given rank exists.
- * @throws IllegalArgumentException if sketch is empty.
- */
- long getQuantileUpperBound(double rank);
+ /**
+ * Gets the upper bound of the quantile confidence interval in which the
true quantile of the
+ * given rank exists.
+ *
+ * <p>Although it is possible to estimate the probability that the true
quantile
+ * exists within the quantile confidence interval specified by the upper and
lower quantile bounds,
+ * it is not possible to guarantee the width of the quantile interval
+ * as an additive or multiplicative percent of the true quantile.</p>
+ *
+ * @param rank the given normalized rank
+ * @return the upper bound of the quantile confidence interval in which the
true quantile of the
+ * given rank exists.
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ long getQuantileUpperBound(double rank);
- /**
- * This is equivalent to {@link #getQuantiles(double[],
QuantileSearchCriteria) getQuantiles(ranks, INCLUSIVE)}
- * @param ranks the given array of normalized ranks, each of which must be
- * in the interval [0.0,1.0].
- * @return an array of quantiles corresponding to the given array of
normalized ranks.
- * @throws IllegalArgumentException if sketch is empty.
- */
- default long[] getQuantiles(double[] ranks) {
- return getQuantiles(ranks, INCLUSIVE);
- }
+ /**
+ * This is equivalent to {@link #getQuantiles(double[],
QuantileSearchCriteria) getQuantiles(ranks, INCLUSIVE)}
+ * @param ranks the given array of normalized ranks, each of which must be
+ * in the interval [0.0,1.0].
+ * @return an array of quantiles corresponding to the given array of
normalized ranks.
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ default long[] getQuantiles(double[] ranks) {
+ return getQuantiles(ranks, INCLUSIVE);
+ }
- /**
- * Gets an array of quantiles from the given array of normalized ranks.
- *
- * @param ranks the given array of normalized ranks, each of which must be
- * in the interval [0.0,1.0].
- * @param searchCrit if INCLUSIVE, the given ranks include all quantiles
≤
- * the quantile directly corresponding to each rank.
- * @return an array of quantiles corresponding to the given array of
normalized ranks.
- * @throws IllegalArgumentException if sketch is empty.
- * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
- */
- long[] getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit);
+ /**
+ * Gets an array of quantiles from the given array of normalized ranks.
+ *
+ * @param ranks the given array of normalized ranks, each of which must be
+ * in the interval [0.0,1.0].
+ * @param searchCrit if INCLUSIVE, the given ranks include all quantiles ≤
+ * the quantile directly corresponding to each rank.
+ * @return an array of quantiles corresponding to the given array of
normalized ranks.
+ * @throws IllegalArgumentException if sketch is empty.
+ * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
+ */
+ long[] getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit);
- /**
- * This is equivalent to {@link #getRank(long, QuantileSearchCriteria)
getRank(quantile, INCLUSIVE)}
- * @param quantile the given quantile
- * @return the normalized rank corresponding to the given quantile
- * @throws IllegalArgumentException if sketch is empty.
- */
- default double getRank(long quantile) {
- return getRank(quantile, INCLUSIVE);
- }
+ /**
+ * This is equivalent to {@link #getRank(long, QuantileSearchCriteria)
getRank(quantile, INCLUSIVE)}
+ * @param quantile the given quantile
+ * @return the normalized rank corresponding to the given quantile
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ default double getRank(long quantile) {
+ return getRank(quantile, INCLUSIVE);
+ }
- /**
- * Gets the normalized rank corresponding to the given a quantile.
- *
- * @param quantile the given quantile
- * @param searchCrit if INCLUSIVE the given quantile is included into the
rank.
- * @return the normalized rank corresponding to the given quantile
- * @throws IllegalArgumentException if sketch is empty.
- * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
- */
- double getRank(long quantile, QuantileSearchCriteria searchCrit);
+ /**
+ * Gets the normalized rank corresponding to the given a quantile.
+ *
+ * @param quantile the given quantile
+ * @param searchCrit if INCLUSIVE the given quantile is included into the
rank.
+ * @return the normalized rank corresponding to the given quantile
+ * @throws IllegalArgumentException if sketch is empty.
+ * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
+ */
+ double getRank(long quantile, QuantileSearchCriteria searchCrit);
- /**
- * This is equivalent to {@link #getRanks(long[], QuantileSearchCriteria)
getRanks(quantiles, INCLUSIVE)}
- * @param quantiles the given array of quantiles
- * @return an array of normalized ranks corresponding to the given array
of quantiles.
- * @throws IllegalArgumentException if sketch is empty.
- */
- default double[] getRanks(long[] quantiles) {
- return getRanks(quantiles, INCLUSIVE);
- }
+ /**
+ * This is equivalent to {@link #getRanks(long[], QuantileSearchCriteria)
getRanks(quantiles, INCLUSIVE)}
+ * @param quantiles the given array of quantiles
+ * @return an array of normalized ranks corresponding to the given array of
quantiles.
+ * @throws IllegalArgumentException if sketch is empty.
+ */
+ default double[] getRanks(long[] quantiles) {
+ return getRanks(quantiles, INCLUSIVE);
+ }
- /**
- * Gets an array of normalized ranks corresponding to the given array of
quantiles and the given
- * search criterion.
- *
- * @param quantiles the given array of quantiles
- * @param searchCrit if INCLUSIVE, the given quantiles include the rank
directly corresponding to each quantile.
- * @return an array of normalized ranks corresponding to the given array
of quantiles.
- * @throws IllegalArgumentException if sketch is empty.
- * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
- */
- double[] getRanks(long[] quantiles, QuantileSearchCriteria searchCrit);
+ /**
+ * Gets an array of normalized ranks corresponding to the given array of
quantiles and the given
+ * search criterion.
+ *
+ * @param quantiles the given array of quantiles
+ * @param searchCrit if INCLUSIVE, the given quantiles include the rank
directly corresponding to each quantile.
+ * @return an array of normalized ranks corresponding to the given array of
quantiles.
+ * @throws IllegalArgumentException if sketch is empty.
+ * @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
+ */
+ double[] getRanks(long[] quantiles, QuantileSearchCriteria searchCrit);
- /**
- * Returns the current number of bytes this Sketch would require if
serialized.
- * @return the number of bytes this sketch would require if serialized.
- */
- int getSerializedSizeBytes();
+ /**
+ * Returns the current number of bytes this Sketch would require if
serialized.
+ * @return the number of bytes this sketch would require if serialized.
+ */
+ int getSerializedSizeBytes();
- /**
- * Gets the sorted view of this sketch
- * @return the sorted view of this sketch
- */
- LongsSortedView getSortedView();
+ /**
+ * Gets the sorted view of this sketch
+ * @return the sorted view of this sketch
+ */
+ LongsSortedView getSortedView();
- /**
- * Gets the iterator for this sketch, which is not sorted.
- * @return the iterator for this sketch
- */
- QuantilesLongsSketchIterator iterator();
+ /**
+ * Gets the iterator for this sketch, which is not sorted.
+ * @return the iterator for this sketch
+ */
+ QuantilesLongsSketchIterator iterator();
- /**
- * Returns a byte array representation of this sketch.
- * @return a byte array representation of this sketch.
- */
- byte[] toByteArray();
+ /**
+ * Returns a byte array representation of this sketch.
+ * @return a byte array representation of this sketch.
+ */
+ byte[] toByteArray();
- /**
- * Updates this sketch with the given item.
- * @param item from a stream of items. NaNs are ignored.
- */
- void update(long item);
+ /**
+ * Updates this sketch with the given item.
+ * @param item from a stream of items. NaNs are ignored.
+ */
+ void update(long item);
}
diff --git
a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesUtil.java
b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesUtil.java
index 5a341c1e..529fd386 100644
--- a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesUtil.java
+++ b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesUtil.java
@@ -69,7 +69,7 @@ public final class QuantilesUtil {
/**
* Checks the sequential validity of the given array of double values.
- * They must be unique, monotonically increasing and not NaN.
+ * They must be unique and monotonically increasing.
* @param values the given array of double values
*/
public static void checkLongsSplitPointsOrder(final long[] values) {
@@ -78,7 +78,7 @@ public final class QuantilesUtil {
for (int j = 0; j < len - 1; j++) {
if (values[j] < values[j + 1]) { continue; }
throw new SketchesArgumentException(
- "Values must be unique, monotonically increasing.");
+ "Values must be unique and monotonically increasing.");
}
}
diff --git
a/src/test/java/org/apache/datasketches/kll/KllDirectCompactLongsSketchTest.java
b/src/test/java/org/apache/datasketches/kll/KllDirectCompactLongsSketchTest.java
index 3ef86dc2..4dc423a1 100644
---
a/src/test/java/org/apache/datasketches/kll/KllDirectCompactLongsSketchTest.java
+++
b/src/test/java/org/apache/datasketches/kll/KllDirectCompactLongsSketchTest.java
@@ -19,6 +19,11 @@
package org.apache.datasketches.kll;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
import org.apache.datasketches.common.SketchesArgumentException;
import
org.apache.datasketches.kll.KllDirectLongsSketch.KllDirectCompactLongsSketch;
import org.apache.datasketches.memory.DefaultMemoryRequestServer;
@@ -26,11 +31,6 @@ import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
public class KllDirectCompactLongsSketchTest {
private static final DefaultMemoryRequestServer memReqSvr = new
DefaultMemoryRequestServer();
@@ -46,8 +46,8 @@ public class KllDirectCompactLongsSketchTest {
assertTrue(sk2.isMemoryUpdatableFormat());
assertTrue(sk2.isReadOnly());
- assertEquals(sk2.getMinItem(), 1.0F);
- assertEquals(sk2.getMaxItem(), 21.0F);
+ assertEquals(sk2.getMinItem(), 1L);
+ assertEquals(sk2.getMaxItem(), 21L);
WritableMemory srcWmem = WritableMemory.writableWrap(byteArr);
KllLongsSketch sk3 = KllLongsSketch.writableWrap(srcWmem, memReqSvr);
@@ -55,8 +55,8 @@ public class KllDirectCompactLongsSketchTest {
println(sk3.toString(true, false));
assertFalse(sk3.isReadOnly());
sk3.update(22);
- assertEquals(sk2.getMinItem(), 1.0F);
- assertEquals(sk2.getMaxItem(), 22.0F);
+ assertEquals(sk2.getMinItem(), 1L);
+ assertEquals(sk2.getMaxItem(), 22L);
}
@Test
@@ -70,16 +70,16 @@ public class KllDirectCompactLongsSketchTest {
//println(sk2.toString(true, false));
assertFalse(sk2.isMemoryUpdatableFormat());
assertTrue(sk2.isReadOnly());
- assertEquals(sk2.getMinItem(), 1.0F);
- assertEquals(sk2.getMaxItem(), 21.0F);
+ assertEquals(sk2.getMinItem(), 1L);
+ assertEquals(sk2.getMaxItem(), 21L);
Memory srcMem2 = Memory.wrap(sk2.toByteArray());
KllLongsSketch sk3 = KllLongsSketch.writableWrap((WritableMemory)srcMem2,
memReqSvr);
assertTrue(sk3 instanceof KllDirectCompactLongsSketch);
assertFalse(sk2.isMemoryUpdatableFormat());
//println(sk3.toString(true, false));
assertTrue(sk3.isReadOnly());
- assertEquals(sk3.getMinItem(), 1.0F);
- assertEquals(sk3.getMaxItem(), 21.0F);
+ assertEquals(sk3.getMinItem(), 1L);
+ assertEquals(sk3.getMaxItem(), 21L);
}
@Test
@@ -92,7 +92,7 @@ public class KllDirectCompactLongsSketchTest {
assertTrue(sk2 instanceof KllDirectCompactLongsSketch);
//println(sk2.toString(true, false));
assertTrue(sk2.isReadOnly());
- assertEquals(sk2.getLongSingleItem(), 1.0F);
+ assertEquals(sk2.getLongSingleItem(), 1L);
sk.update(2);
sk2 = KllLongsSketch.wrap(Memory.wrap(sk.toByteArray()));
@@ -110,12 +110,12 @@ public class KllDirectCompactLongsSketchTest {
KllLongsSketch sk2 = KllLongsSketch.wrap(Memory.wrap(sk.toByteArray()));
long[] itemsArr = sk2.getLongItemsArray();
- for (int i = 0; i < 20; i++) { assertEquals(itemsArr[i], 0F); }
+ for (int i = 0; i < 20; i++) { assertEquals(itemsArr[i], 0); }
sk.update(1);
sk2 = KllLongsSketch.wrap(Memory.wrap(sk.toByteArray()));
itemsArr = sk2.getLongItemsArray();
- for (int i = 0; i < 19; i++) { assertEquals(itemsArr[i], 0F); }
+ for (int i = 0; i < 19; i++) { assertEquals(itemsArr[i], 0); }
assertEquals(itemsArr[19], 1F);
for (int i = 2; i <= 21; i++) { sk.update(i); }
@@ -142,13 +142,13 @@ public class KllDirectCompactLongsSketchTest {
retArr = sk.getLongRetainedItemsArray();
assertEquals(retArr.length, sk.getNumRetained());
assertEquals(retArr.length, 1);
- assertEquals(retArr[0], 1f);
+ assertEquals(retArr[0], 1L);
sk2 = KllLongsSketch.wrap(Memory.wrap(sk.toByteArray()));
retArr = sk2.getLongRetainedItemsArray();
assertEquals(retArr.length, sk.getNumRetained());
assertEquals(retArr.length, 1);
- assertEquals(retArr[0], 1f);
+ assertEquals(retArr[0], 1L);
for (int i = 2; i <= 21; i++) { sk.update(i); }
retArr = sk.getLongRetainedItemsArray();
@@ -169,12 +169,12 @@ public class KllDirectCompactLongsSketchTest {
try { sk2.getMaxItem(); fail(); } catch (SketchesArgumentException e) {}
sk.update(1);
sk2 = KllLongsSketch.wrap(Memory.wrap(sk.toByteArray()));
- assertEquals(sk2.getMaxItem(),1.0F);
- assertEquals(sk2.getMinItem(),1.0F);
+ assertEquals(sk2.getMaxItem(),1L);
+ assertEquals(sk2.getMinItem(),1L);
for (int i = 2; i <= 21; i++) { sk.update(i); }
sk2 = KllLongsSketch.wrap(Memory.wrap(sk.toByteArray()));
- assertEquals(sk2.getMaxItem(),21.0F);
- assertEquals(sk2.getMinItem(),1.0F);
+ assertEquals(sk2.getMaxItem(),21L);
+ assertEquals(sk2.getMinItem(),1L);
}
@Test
@@ -182,8 +182,8 @@ public class KllDirectCompactLongsSketchTest {
KllLongsSketch sk1 = KllLongsSketch.newHeapInstance();
for (int i = 1; i <= 1000; i++) { sk1.update(i); }
KllLongsSketch sk2 = KllLongsSketch.wrap(Memory.wrap(sk1.toByteArray()));
- double med2 = sk2.getQuantile(0.5);
- double med1 = sk1.getQuantile(0.5);
+ long med2 = sk2.getQuantile(0.5);
+ long med1 = sk1.getQuantile(0.5);
assertEquals(med1, med2);
println("Med1: " + med1);
println("Med2: " + med2);
diff --git
a/src/test/java/org/apache/datasketches/kll/KllDirectLongsSketchIteratorTest.java
b/src/test/java/org/apache/datasketches/kll/KllDirectLongsSketchIteratorTest.java
index cddfba16..8be509f1 100644
---
a/src/test/java/org/apache/datasketches/kll/KllDirectLongsSketchIteratorTest.java
+++
b/src/test/java/org/apache/datasketches/kll/KllDirectLongsSketchIteratorTest.java
@@ -30,18 +30,18 @@ public class KllDirectLongsSketchIteratorTest {
@Test
public void emptySketch() {
- final KllLongsSketch sketch = getDFSketch(200, 0);
+ final KllLongsSketch sketch = getDLSketch(200, 0);
QuantilesLongsSketchIterator it = sketch.iterator();
Assert.assertFalse(it.next());
}
@Test
public void oneItemSketch() {
- final KllLongsSketch sketch = getDFSketch(200, 0);
+ final KllLongsSketch sketch = getDLSketch(200, 0);
sketch.update(0);
QuantilesLongsSketchIterator it = sketch.iterator();
Assert.assertTrue(it.next());
- Assert.assertEquals(it.getQuantile(), 0f);
+ Assert.assertEquals(it.getQuantile(), 0);
Assert.assertEquals(it.getWeight(), 1);
Assert.assertFalse(it.next());
}
@@ -49,7 +49,7 @@ public class KllDirectLongsSketchIteratorTest {
@Test
public void bigSketches() {
for (int n = 1000; n < 100000; n += 2000) {
- final KllLongsSketch sketch = getDFSketch(200, 0);
+ final KllLongsSketch sketch = getDLSketch(200, 0);
for (int i = 0; i < n; i++) {
sketch.update(i);
}
@@ -65,15 +65,14 @@ public class KllDirectLongsSketchIteratorTest {
}
}
- private static KllLongsSketch getDFSketch(final int k, final int n) {
+ private static KllLongsSketch getDLSketch(final int k, final int n) {
KllLongsSketch sk = KllLongsSketch.newHeapInstance(k);
for (int i = 1; i <= n; i++) { sk.update(i); }
byte[] byteArr = KllHelper.toByteArray(sk, true);
WritableMemory wmem = WritableMemory.writableWrap(byteArr);
- KllLongsSketch dfsk = KllLongsSketch.writableWrap(wmem, memReqSvr);
- return dfsk;
+ KllLongsSketch dlsk = KllLongsSketch.writableWrap(wmem, memReqSvr);
+ return dlsk;
}
}
-
diff --git
a/src/test/java/org/apache/datasketches/kll/KllDoublesSketchSerDeTest.java
b/src/test/java/org/apache/datasketches/kll/KllDoublesSketchSerDeTest.java
index e07a395d..cca51bb4 100644
--- a/src/test/java/org/apache/datasketches/kll/KllDoublesSketchSerDeTest.java
+++ b/src/test/java/org/apache/datasketches/kll/KllDoublesSketchSerDeTest.java
@@ -74,8 +74,8 @@ public class KllDoublesSketchSerDeTest {
assertEquals(sk2.getNumRetained(), 1);
assertEquals(sk2.getN(), 1);
assertEquals(sk2.getNormalizedRankError(false),
sk1.getNormalizedRankError(false));
- assertEquals(sk2.getMinItem(), 1.0);
- assertEquals(sk2.getMaxItem(), 1.0);
+ assertEquals(sk2.getMinItem(), 1L);
+ assertEquals(sk2.getMaxItem(), 1L);
assertEquals(sk2.getSerializedSizeBytes(), Long.BYTES + Double.BYTES);
//from heap -> byte[] -> off heap
@@ -84,8 +84,8 @@ public class KllDoublesSketchSerDeTest {
assertEquals(sk3.getNumRetained(), 1);
assertEquals(sk3.getN(), 1);
assertEquals(sk3.getNormalizedRankError(false),
sk1.getNormalizedRankError(false));
- assertEquals(sk3.getMinItem(), 1.0);
- assertEquals(sk3.getMaxItem(), 1.0);
+ assertEquals(sk3.getMinItem(), 1L);
+ assertEquals(sk3.getMaxItem(), 1L);
assertEquals(sk3.getSerializedSizeBytes(), sk1.getSerializedSizeBytes());
//from heap -> byte[] -> off heap -> byte[] -> compare byte[]
final byte[] bytes2 = sk3.toByteArray();
@@ -99,8 +99,8 @@ public class KllDoublesSketchSerDeTest {
for (int i = 0; i < n; i++) {
sk1.update(i);
}
- assertEquals(sk1.getMinItem(), 0.0);
- assertEquals(sk1.getMaxItem(), 999.0);
+ assertEquals(sk1.getMinItem(), 0);
+ assertEquals(sk1.getMaxItem(), 999L);
//from heap -> byte[] -> heap
final byte[] bytes = sk1.toByteArray();
diff --git
a/src/test/java/org/apache/datasketches/kll/KllLongsSketchSerDeTest.java
b/src/test/java/org/apache/datasketches/kll/KllLongsSketchSerDeTest.java
index 0c0e8fad..b9b0f800 100644
--- a/src/test/java/org/apache/datasketches/kll/KllLongsSketchSerDeTest.java
+++ b/src/test/java/org/apache/datasketches/kll/KllLongsSketchSerDeTest.java
@@ -19,21 +19,21 @@
package org.apache.datasketches.kll;
-import org.apache.datasketches.common.SketchesArgumentException;
-import org.apache.datasketches.memory.Memory;
-import org.testng.annotations.Test;
-
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
+import org.apache.datasketches.common.SketchesArgumentException;
+import org.apache.datasketches.memory.Memory;
+import org.testng.annotations.Test;
+
public class KllLongsSketchSerDeTest {
@Test
public void serializeDeserializeEmpty() {
final int N = 20;
-
+
final KllLongsSketch sk1 = KllLongsSketch.newHeapInstance(N);
//Empty: from heap -> byte[] -> heap
final byte[] bytes = sk1.toByteArray();
@@ -46,7 +46,7 @@ public class KllLongsSketchSerDeTest {
try { sk2.getMinItem(); fail(); } catch (SketchesArgumentException e) {}
try { sk2.getMaxItem(); fail(); } catch (SketchesArgumentException e) {}
assertEquals(sk2.getSerializedSizeBytes(), sk1.getSerializedSizeBytes());
-
+
//Empty: from heap -> byte[] -> off heap
final KllLongsSketch sk3 = KllLongsSketch.wrap(Memory.wrap(bytes));
assertTrue(sk3.isEmpty());
@@ -74,18 +74,18 @@ public class KllLongsSketchSerDeTest {
assertEquals(sk2.getNumRetained(), 1);
assertEquals(sk2.getN(), 1);
assertEquals(sk2.getNormalizedRankError(false),
sk1.getNormalizedRankError(false));
- assertEquals(sk2.getMinItem(), 1.0F);
- assertEquals(sk2.getMaxItem(), 1.0F);
+ assertEquals(sk2.getMinItem(), 1L);
+ assertEquals(sk2.getMaxItem(), 1L);
assertEquals(sk2.getSerializedSizeBytes(), Long.BYTES + Long.BYTES);
-
+
//from heap -> byte[] -> off heap
final KllLongsSketch sk3 = KllLongsSketch.wrap(Memory.wrap(bytes));
assertFalse(sk3.isEmpty());
assertEquals(sk3.getNumRetained(), 1);
assertEquals(sk3.getN(), 1);
assertEquals(sk3.getNormalizedRankError(false),
sk1.getNormalizedRankError(false));
- assertEquals(sk3.getMinItem(), 1.0f);
- assertEquals(sk3.getMaxItem(), 1.0f);
+ assertEquals(sk3.getMinItem(), 1L);
+ assertEquals(sk3.getMaxItem(), 1L);
assertEquals(sk3.getSerializedSizeBytes(), sk1.getSerializedSizeBytes());
//from heap -> byte[] -> off heap -> byte[] -> compare byte[]
final byte[] bytes2 = sk3.toByteArray();
@@ -99,9 +99,9 @@ public class KllLongsSketchSerDeTest {
for (int i = 0; i < n; i++) {
sk1.update(i);
}
- assertEquals(sk1.getMinItem(), 0.0f);
- assertEquals(sk1.getMaxItem(), 999.0f);
-
+ assertEquals(sk1.getMinItem(), 0);
+ assertEquals(sk1.getMaxItem(), 999L);
+
//from heap -> byte[] -> heap
final byte[] bytes = sk1.toByteArray();
final KllLongsSketch sk2 = KllLongsSketch.heapify(Memory.wrap(bytes));
@@ -113,7 +113,7 @@ public class KllLongsSketchSerDeTest {
assertEquals(sk2.getMinItem(), sk1.getMinItem());
assertEquals(sk2.getMaxItem(), sk1.getMaxItem());
assertEquals(sk2.getSerializedSizeBytes(), sk1.getSerializedSizeBytes());
-
+
//from heap -> byte[] -> off heap
final KllLongsSketch sk3 = KllLongsSketch.wrap(Memory.wrap(bytes));
assertFalse(sk3.isEmpty());
diff --git a/src/test/java/org/apache/datasketches/kll/KllLongsSketchTest.java
b/src/test/java/org/apache/datasketches/kll/KllLongsSketchTest.java
index f50f8846..1f9dba7e 100644
--- a/src/test/java/org/apache/datasketches/kll/KllLongsSketchTest.java
+++ b/src/test/java/org/apache/datasketches/kll/KllLongsSketchTest.java
@@ -19,16 +19,8 @@
package org.apache.datasketches.kll;
-import org.apache.datasketches.common.SketchesArgumentException;
-import org.apache.datasketches.memory.DefaultMemoryRequestServer;
-import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.WritableMemory;
-import org.apache.datasketches.quantilescommon.LongsSortedView;
-import org.apache.datasketches.quantilescommon.LongsSortedViewIterator;
-import org.testng.annotations.Test;
-
import static java.lang.Math.min;
-import static org.apache.datasketches.kll.KllSketch.SketchType.DOUBLES_SKETCH;
+import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
import static
org.apache.datasketches.quantilescommon.QuantileSearchCriteria.EXCLUSIVE;
import static
org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
import static org.testng.Assert.assertEquals;
@@ -37,6 +29,14 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
+import org.apache.datasketches.common.SketchesArgumentException;
+import org.apache.datasketches.memory.DefaultMemoryRequestServer;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.WritableMemory;
+import org.apache.datasketches.quantilescommon.LongsSortedView;
+import org.apache.datasketches.quantilescommon.LongsSortedViewIterator;
+import org.testng.annotations.Test;
+
public class KllLongsSketchTest {
private static final String LS = System.getProperty("line.separator");
private static final double PMF_EPS_FOR_K_8 =
KllSketch.getNormalizedRankError(8, true);
@@ -89,8 +89,8 @@ public class KllLongsSketchTest {
assertEquals(sketch.getRank(0L, INCLUSIVE), 0.0);
assertEquals(sketch.getRank(1L, INCLUSIVE), 1.0);
assertEquals(sketch.getRank(2L, INCLUSIVE), 1.0);
- assertEquals(sketch.getMinItem(), 1.0);
- assertEquals(sketch.getMaxItem(), 1.0);
+ assertEquals(sketch.getMinItem(), 1L);
+ assertEquals(sketch.getMaxItem(), 1L);
assertEquals(sketch.getQuantile(0.5, EXCLUSIVE), 1L);
assertEquals(sketch.getQuantile(0.5, INCLUSIVE), 1L);
}
@@ -164,8 +164,8 @@ public class KllLongsSketchTest {
assertEquals(pmf[0], 0.5, PMF_EPS_FOR_K_256);
assertEquals(pmf[1], 0.5, PMF_EPS_FOR_K_256);
- assertEquals(sketch.getMinItem(), 0f); // min value is exact
- assertEquals(sketch.getMaxItem(), n - 1f); // max value is exact
+ assertEquals(sketch.getMinItem(), 0); // min value is exact
+ assertEquals(sketch.getMaxItem(), n - 1); // max value is exact
// check at every 0.1 percentage point
final double[] fractions = new double[1001];
@@ -235,19 +235,19 @@ public class KllLongsSketchTest {
sketch2.update(2 * n - i - 1);
}
- assertEquals(sketch1.getMinItem(), 0.0);
- assertEquals(sketch1.getMaxItem(), (n - 1) * 1.0);
+ assertEquals(sketch1.getMinItem(), 0);
+ assertEquals(sketch1.getMaxItem(), (n - 1));
- assertEquals(sketch2.getMinItem(), n * 1.0);
- assertEquals(sketch2.getMaxItem(), (2 * n - 1) * 1.0);
+ assertEquals(sketch2.getMinItem(), n);
+ assertEquals(sketch2.getMaxItem(), (2 * n - 1));
sketch1.merge(sketch2);
assertFalse(sketch1.isEmpty());
assertEquals(sketch1.getN(), 2L * n);
- assertEquals(sketch1.getMinItem(), 0.0);
- assertEquals(sketch1.getMaxItem(), (2 * n - 1) * 1.0);
- assertEquals(sketch1.getQuantile(0.5), n * 1.0, 2 * n * PMF_EPS_FOR_K_256);
+ assertEquals(sketch1.getMinItem(), 0);
+ assertEquals(sketch1.getMaxItem(), (2 * n - 1));
+ assertEquals(sketch1.getQuantile(0.5), n, 2 * n * PMF_EPS_FOR_K_256);
}
@Test
@@ -260,11 +260,11 @@ public class KllLongsSketchTest {
sketch2.update(2 * n - i - 1);
}
- assertEquals(sketch1.getMinItem(), 0.0f);
- assertEquals(sketch1.getMaxItem(), n - 1f);
+ assertEquals(sketch1.getMinItem(), 0);
+ assertEquals(sketch1.getMaxItem(), n - 1L);
assertEquals(sketch2.getMinItem(), n);
- assertEquals(sketch2.getMaxItem(), 2f * n - 1.0);
+ assertEquals(sketch2.getMaxItem(), 2L * n - 1L);
assertTrue(sketch1.getNormalizedRankError(false) <
sketch2.getNormalizedRankError(false));
assertTrue(sketch1.getNormalizedRankError(true) <
sketch2.getNormalizedRankError(true));
@@ -276,9 +276,9 @@ public class KllLongsSketchTest {
assertFalse(sketch1.isEmpty());
assertEquals(sketch1.getN(), 2 * n);
- assertEquals(sketch1.getMinItem(), 0.0);
- assertEquals(sketch1.getMaxItem(), 2.0 * n - 1.0);
- assertEquals(sketch1.getQuantile(0.5), n, 2 * n * PMF_EPS_FOR_K_128);
+ assertEquals(sketch1.getMinItem(), 0);
+ assertEquals(sketch1.getMaxItem(), 2L * n - 1L);
+ assertEquals(sketch1.getQuantile(0.5), n, 2L * n * PMF_EPS_FOR_K_128);
}
@Test
@@ -297,17 +297,17 @@ public class KllLongsSketchTest {
assertFalse(sketch1.isEmpty());
assertEquals(sketch1.getN(), n);
- assertEquals(sketch1.getMinItem(), 0.0);
- assertEquals(sketch1.getMaxItem(), n - 1.0);
- assertEquals(sketch1.getQuantile(0.5), n / 2.0, n * PMF_EPS_FOR_K_256);
+ assertEquals(sketch1.getMinItem(), 0);
+ assertEquals(sketch1.getMaxItem(), n - 1);
+ assertEquals(sketch1.getQuantile(0.5), n / 2, n * PMF_EPS_FOR_K_256);
//merge the other way
sketch2.merge(sketch1);
assertFalse(sketch1.isEmpty());
assertEquals(sketch1.getN(), n);
- assertEquals(sketch1.getMinItem(), 0f);
- assertEquals(sketch1.getMaxItem(), n - 1.0);
- assertEquals(sketch1.getQuantile(0.5), n / 2.0, n * PMF_EPS_FOR_K_256);
+ assertEquals(sketch1.getMinItem(), 0);
+ assertEquals(sketch1.getMaxItem(), n - 1);
+ assertEquals(sketch1.getQuantile(0.5), n / 2, n * PMF_EPS_FOR_K_256);
}
@Test
@@ -333,7 +333,7 @@ public class KllLongsSketchTest {
sketch1.update(1);
sketch2.update(2);
sketch2.merge(sketch1);
- assertEquals(sketch2.getMinItem(), 1.0);
+ assertEquals(sketch2.getMinItem(), 1);
}
@Test
@@ -344,8 +344,8 @@ public class KllLongsSketchTest {
}
final KllLongsSketch sketch2 = KllLongsSketch.newHeapInstance(10);
sketch2.merge(sketch1);
- assertEquals(sketch2.getMinItem(), 1.0);
- assertEquals(sketch2.getMaxItem(), 1_000_000.0);
+ assertEquals(sketch2.getMinItem(), 1);
+ assertEquals(sketch2.getMaxItem(), 1_000_000);
}
@Test(expectedExceptions = SketchesArgumentException.class)
@@ -365,7 +365,7 @@ public class KllLongsSketchTest {
sketch.update(i);
}
assertEquals(sketch.getK(), KllSketch.DEFAULT_M);
- assertEquals(sketch.getQuantile(0.5), 500.0, 1000 * PMF_EPS_FOR_K_8);
+ assertEquals(sketch.getQuantile(0.5), 500, 1000 * PMF_EPS_FOR_K_8);
}
@Test
@@ -418,8 +418,8 @@ public class KllLongsSketchTest {
catch (NullPointerException e) { }
try { KllFloatsSketch.newDirectInstance(wmem, null); fail(); }
catch (NullPointerException e) { }
- int updateSize = KllSketch.getMaxSerializedSizeBytes(200, 0,
DOUBLES_SKETCH, true);
- int compactSize = KllSketch.getMaxSerializedSizeBytes(200, 0,
DOUBLES_SKETCH, false);
+ int updateSize = KllSketch.getMaxSerializedSizeBytes(200, 0, LONGS_SKETCH,
true);
+ int compactSize = KllSketch.getMaxSerializedSizeBytes(200, 0,
LONGS_SKETCH, false);
assertTrue(compactSize < updateSize);
}
@@ -463,7 +463,7 @@ public class KllLongsSketchTest {
long[] sp = new long[] { 10, 20, 30, 40 };
println("SplitPoints:");
for (int i = 0; i < sp.length; i++) {
- printf("%10.2f", sp[i]);
+ printf("%10d", sp[i]);
}
println("");
println("INCLUSIVE:");
@@ -622,8 +622,8 @@ public class KllLongsSketchTest {
println(sk.toString(withLevels, withLevelsAndItems));
println("");
assertEquals(sk.getN(), 108);
- assertEquals(sk.getMaxItem(), 108.0);
- assertEquals(sk.getMinItem(), 1.0);
+ assertEquals(sk.getMaxItem(), 108L);
+ assertEquals(sk.getMinItem(), 1L);
}
@Test
@@ -648,7 +648,7 @@ public class KllLongsSketchTest {
assertEquals(totN, M * N);
assertEquals(sketch.getMinItem(), 1L);
assertEquals(sketch.getMaxItem(), totN);
- assertEquals(sketch.getQuantile(0.5), totN / 2.0, totN *
PMF_EPS_FOR_K_256 * 2.0); //wider tolerance
+ assertEquals(sketch.getQuantile(0.5), totN / 2, totN * PMF_EPS_FOR_K_256
* 2.0); //wider tolerance
}
final long runTime = System.nanoTime() - startTime;
println("Vectorized Updates");
@@ -686,7 +686,7 @@ public class KllLongsSketchTest {
assertEquals(totN, M * N);
assertEquals(sketch.getMinItem(), 1L);
assertEquals(sketch.getMaxItem(), totN);
- assertEquals(sketch.getQuantile(0.5), totN / 2.0, totN *
PMF_EPS_FOR_K_256 * 2.0); //wider tolerance
+ assertEquals(sketch.getQuantile(0.5), totN / 2, totN * PMF_EPS_FOR_K_256
* 2.0); //wider tolerance
}
final long runTime = System.nanoTime() - startTime;
println("Vectorized Updates");
diff --git
a/src/test/java/org/apache/datasketches/kll/KllMiscDirectLongsTest.java
b/src/test/java/org/apache/datasketches/kll/KllMiscDirectLongsTest.java
index a1242934..9a299837 100644
--- a/src/test/java/org/apache/datasketches/kll/KllMiscDirectLongsTest.java
+++ b/src/test/java/org/apache/datasketches/kll/KllMiscDirectLongsTest.java
@@ -19,6 +19,12 @@
package org.apache.datasketches.kll;
+import static org.apache.datasketches.kll.KllSketch.SketchType.LONGS_SKETCH;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.DefaultMemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;
@@ -26,12 +32,6 @@ import
org.apache.datasketches.quantilescommon.LongsSortedView;
import org.apache.datasketches.quantilescommon.LongsSortedViewIterator;
import org.testng.annotations.Test;
-import static org.apache.datasketches.kll.KllSketch.SketchType.FLOATS_SKETCH;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
public class KllMiscDirectLongsTest {
static final String LS = System.getProperty("line.separator");
private static final DefaultMemoryRequestServer memReqSvr = new
DefaultMemoryRequestServer();
@@ -101,7 +101,7 @@ public class KllMiscDirectLongsTest {
while (itr.next()) {
long v = itr.getQuantile();
long wt = itr.getWeight();
- printf("%12.1f%12d\n", v, wt);
+ printf("%12d%12d\n", v, wt);
}
}
@@ -116,7 +116,7 @@ public class KllMiscDirectLongsTest {
int k = 20; //don't change this
KllLongsSketch sk;
- //println("#### CASE: FLOAT FULL HEAP");
+ //println("#### CASE: LONG FULL HEAP");
sk = getDirectLongsSketch(k, 0);
for (int i = 1; i <= k + 1; i++) { sk.update(i); }
//println(sk.toString(true, true));
@@ -128,12 +128,12 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 33);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 3);
- assertEquals(sk.getMaxItem(), 21.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 21L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 2);
assertFalse(sk.isLevelZeroSorted());
- //println("#### CASE: FLOAT HEAP EMPTY");
+ //println("#### CASE: LONG HEAP EMPTY");
sk = getDirectLongsSketch(k, 0);
//println(sk.toString(true, true));
assertEquals(sk.getK(), k);
@@ -149,7 +149,7 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
- //println("#### CASE: FLOAT HEAP SINGLE");
+ //println("#### CASE: LONG HEAP SINGLE");
sk = getDirectLongsSketch(k, 0);
sk.update(1);
//println(sk.toString(true, true));
@@ -161,8 +161,8 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 20);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 2);
- assertEquals(sk.getMaxItem(), 1.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 1L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
}
@@ -175,7 +175,7 @@ public class KllMiscDirectLongsTest {
byte[] compBytes;
WritableMemory wmem;
- //println("#### CASE: FLOAT FULL HEAPIFIED FROM COMPACT");
+ //println("#### CASE: LONG FULL HEAPIFIED FROM COMPACT");
sk2 = getDirectLongsSketch(k, 0);
for (int i = 1; i <= k + 1; i++) { sk2.update(i); }
//println(sk.toString(true, true));
@@ -191,12 +191,12 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 33);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 3);
- assertEquals(sk.getMaxItem(), 21.0F);
- assertEquals(sk.getMinItem(), 1.0f);
+ assertEquals(sk.getMaxItem(), 21L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 2);
assertFalse(sk.isLevelZeroSorted());
- //println("#### CASE: FLOAT EMPTY HEAPIFIED FROM COMPACT");
+ //println("#### CASE: LONG EMPTY HEAPIFIED FROM COMPACT");
sk2 = getDirectLongsSketch(k, 0);
//println(sk.toString(true, true));
compBytes = sk2.toByteArray();
@@ -216,7 +216,7 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
- //println("#### CASE: FLOAT SINGLE HEAPIFIED FROM COMPACT");
+ //println("#### CASE: LONG SINGLE HEAPIFIED FROM COMPACT");
sk2 = getDirectLongsSketch(k, 0);
sk2.update(1);
//println(sk2.toString(true, true));
@@ -232,8 +232,8 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 20);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 2);
- assertEquals(sk.getMaxItem(), 1.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 1L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
}
@@ -246,7 +246,7 @@ public class KllMiscDirectLongsTest {
byte[] compBytes;
WritableMemory wmem;
- //println("#### CASE: FLOAT FULL HEAPIFIED FROM UPDATABLE");
+ //println("#### CASE: LONG FULL HEAPIFIED FROM UPDATABLE");
sk2 = getDirectLongsSketch(k, 0);
for (int i = 1; i <= k + 1; i++) { sk2.update(i); }
//println(sk2.toString(true, true));
@@ -262,12 +262,12 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 33);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 3);
- assertEquals(sk.getMaxItem(), 21.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 21L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 2);
assertFalse(sk.isLevelZeroSorted());
- // println("#### CASE: FLOAT EMPTY HEAPIFIED FROM UPDATABLE");
+ // println("#### CASE: LONG EMPTY HEAPIFIED FROM UPDATABLE");
sk2 = getDirectLongsSketch(k, 0);
//println(sk.toString(true, true));
compBytes = KllHelper.toByteArray(sk2, true);
@@ -287,7 +287,7 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
- //println("#### CASE: FLOAT SINGLE HEAPIFIED FROM UPDATABLE");
+ //println("#### CASE: LONG SINGLE HEAPIFIED FROM UPDATABLE");
sk2 = getDirectLongsSketch(k, 0);
sk2.update(1);
//println(sk.toString(true, true));
@@ -303,8 +303,8 @@ public class KllMiscDirectLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 20);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 2);
- assertEquals(sk.getMaxItem(), 1.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 1L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
}
@@ -319,18 +319,18 @@ public class KllMiscDirectLongsTest {
WritableMemory wmem;
String s;
- println("#### CASE: FLOAT FULL UPDATABLE");
+ println("#### CASE: LONG FULL UPDATABLE");
sk = getDirectLongsSketch(k, 0);
for (int i = 1; i <= k + 1; i++) { sk.update(i); }
upBytes = KllHelper.toByteArray(sk, true);
wmem = WritableMemory.writableWrap(upBytes);
- s = KllPreambleUtil.toString(wmem, FLOATS_SKETCH, true);
+ s = KllPreambleUtil.toString(wmem, LONGS_SKETCH, true);
println("step 1: sketch to byte[]/memory & analyze memory");
println(s);
sk2 = KllLongsSketch.writableWrap(wmem, memReqSvr);
upBytes2 = KllHelper.toByteArray(sk2, true);
wmem = WritableMemory.writableWrap(upBytes2);
- s = KllPreambleUtil.toString(wmem, FLOATS_SKETCH, true);
+ s = KllPreambleUtil.toString(wmem, LONGS_SKETCH, true);
println("step 2: memory to heap sketch, to byte[]/memory & analyze memory.
Should match above");
println(s);
assertEquals(upBytes, upBytes2);
@@ -339,13 +339,13 @@ public class KllMiscDirectLongsTest {
sk = getDirectLongsSketch(k, 0);
upBytes = KllHelper.toByteArray(sk, true);
wmem = WritableMemory.writableWrap(upBytes);
- s = KllPreambleUtil.toString(wmem, FLOATS_SKETCH, true);
+ s = KllPreambleUtil.toString(wmem, LONGS_SKETCH, true);
println("step 1: sketch to byte[]/memory & analyze memory");
println(s);
sk2 = KllLongsSketch.writableWrap(wmem, memReqSvr);
upBytes2 = KllHelper.toByteArray(sk2, true);
wmem = WritableMemory.writableWrap(upBytes2);
- s = KllPreambleUtil.toString(wmem, FLOATS_SKETCH, true);
+ s = KllPreambleUtil.toString(wmem, LONGS_SKETCH, true);
println("step 2: memory to heap sketch, to byte[]/memory & analyze memory.
Should match above");
println(s);
assertEquals(upBytes, upBytes2);
@@ -355,13 +355,13 @@ public class KllMiscDirectLongsTest {
sk.update(1);
upBytes = KllHelper.toByteArray(sk, true);
wmem = WritableMemory.writableWrap(upBytes);
- s = KllPreambleUtil.toString(wmem, FLOATS_SKETCH, true);
+ s = KllPreambleUtil.toString(wmem, LONGS_SKETCH, true);
println("step 1: sketch to byte[]/memory & analyze memory");
println(s);
sk2 = KllLongsSketch.writableWrap(wmem, memReqSvr);
upBytes2 = KllHelper.toByteArray(sk2, true);
wmem = WritableMemory.writableWrap(upBytes2);
- s = KllPreambleUtil.toString(wmem, FLOATS_SKETCH, true);
+ s = KllPreambleUtil.toString(wmem, LONGS_SKETCH, true);
println("step 2: memory to heap sketch, to byte[]/memory & analyze memory.
Should match above");
println(s);
assertEquals(upBytes, upBytes2);
@@ -407,8 +407,8 @@ public class KllMiscDirectLongsTest {
WritableMemory dstMem = WritableMemory.allocate(3000);
KllLongsSketch sk = KllLongsSketch.newDirectInstance(k, dstMem, memReqSvr);
for (int i = 1; i <= 10_000; i++) {sk.update(i); }
- assertEquals(sk.getMinItem(), 1.0F);
- assertEquals(sk.getMaxItem(), 10000.0F);
+ assertEquals(sk.getMinItem(), 1L);
+ assertEquals(sk.getMaxItem(), 10000L);
//println(sk.toString(true, true));
}
@@ -419,8 +419,8 @@ public class KllMiscDirectLongsTest {
WritableMemory dstMem = WritableMemory.allocate(1000);
KllLongsSketch sk = KllDirectLongsSketch.newDirectUpdatableInstance(k, m,
dstMem, memReqSvr);
for (int i = 1; i <= 200; i++) {sk.update(i); }
- assertEquals(sk.getMinItem(), 1.0);
- assertEquals(sk.getMaxItem(), 200.0);
+ assertEquals(sk.getMinItem(), 1L);
+ assertEquals(sk.getMaxItem(), 200L);
}
private static KllLongsSketch getDirectLongsSketch(final int k, final int n)
{
diff --git a/src/test/java/org/apache/datasketches/kll/KllMiscLongsTest.java
b/src/test/java/org/apache/datasketches/kll/KllMiscLongsTest.java
index cf9193ac..294d2abe 100644
--- a/src/test/java/org/apache/datasketches/kll/KllMiscLongsTest.java
+++ b/src/test/java/org/apache/datasketches/kll/KllMiscLongsTest.java
@@ -230,11 +230,11 @@ public class KllMiscLongsTest {
while (itr.next()) {
long v = itr.getQuantile();
long wt = itr.getWeight();
- printf("%6d %12.1f %12d" + LS, i, v, wt);
+ printf("%6d %12d %12d" + LS, i, v, wt);
i++;
}
- assertEquals(sv.getMinItem(), 1.0F);
- assertEquals(sv.getMaxItem(), n * 1.0F);
+ assertEquals(sv.getMinItem(), 1L);
+ assertEquals(sv.getMaxItem(), n);
}
@Test //set static enablePrinting = true for visual checking
@@ -273,12 +273,12 @@ public class KllMiscLongsTest {
printf("%12s %12s %12s" + LS, "Value", "Weight", "NaturalRank");
long cumWt = 0;
while (itr.next()) {
- double v = itr.getQuantile();
+ long v = itr.getQuantile();
long wt = itr.getWeight();
long natRank = itr.getNaturalRank(INCLUSIVE);
cumWt += wt;
assertEquals(cumWt, natRank);
- printf("%12.1f %12d %12d" + LS, v, wt, natRank);
+ printf("%12d %12d %12d" + LS, v, wt, natRank);
}
assertEquals(cumWt, sk.getN());
}
@@ -296,7 +296,7 @@ public class KllMiscLongsTest {
private static void outputItems(long[] itemsArr) {
String[] hdr2 = {"Index", "Value"};
String hdr2fmt = "%6s %15s" + LS;
- String d2fmt = "%6d %15f" + LS;
+ String d2fmt = "%6d %15d" + LS;
println("ItemsArr");
printf(hdr2fmt, (Object[]) hdr2);
for (int i = 0; i < itemsArr.length; i++) {
@@ -354,20 +354,20 @@ public class KllMiscLongsTest {
public void checkIntCapAux() {
String[] hdr = {"level", "depth", "wt", "cap", "(end)", "MaxN"};
String hdrFmt = "%6s %6s %28s %10s %10s %34s" + LS;
- String dataFmt = "%6d %6d %,28d %,10d %,10d %,34.0f" + LS;
+ String dataFmt = "%6d %6d %,28d %,10d %,10d %,34d" + LS;
int k = 1000;
int m = 8;
int numLevels = 20;
println("k=" + k + ", m=" + m + ", numLevels=" + numLevels);
printf(hdrFmt, (Object[]) hdr);
- double maxN = 0;
- double[] correct =
{0,1,1,2,2,3,5,8,12,17,26,39,59,88,132,198,296,444,667,1000};
+ long maxN = 0;
+ long[] correct =
{0,1,1,2,2,3,5,8,12,17,26,39,59,88,132,198,296,444,667,1000};
for (int i = 0; i < numLevels; i++) {
int depth = numLevels - i - 1;
long cap = KllHelper.intCapAux(k, depth);
long end = Math.max(m, cap);
long wt = 1L << i;
- maxN += (double)wt * (double)end;
+ maxN += wt * end;
printf(dataFmt, i, depth, wt, cap, end, maxN);
assertEquals(cap, correct[i]);
}
@@ -411,7 +411,7 @@ public class KllMiscLongsTest {
int k = 20; //don't change this
KllLongsSketch sk;
- println("#### CASE: FLOAT FULL HEAP");
+ println("#### CASE: LONG FULL HEAP");
sk = KllLongsSketch.newHeapInstance(k);
for (int i = 1; i <= k + 1; i++) { sk.update(i); }
println(sk.toString(true, true));
@@ -423,12 +423,12 @@ public class KllMiscLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 33);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 3);
- assertEquals(sk.getMaxItem(), 21.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 21L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 2);
assertFalse(sk.isLevelZeroSorted());
- println("#### CASE: FLOAT HEAP EMPTY");
+ println("#### CASE: LONG HEAP EMPTY");
sk = KllLongsSketch.newHeapInstance(k);
println(sk.toString(true, true));
assertEquals(sk.getK(), k);
@@ -444,7 +444,7 @@ public class KllMiscLongsTest {
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
- println("#### CASE: FLOAT HEAP SINGLE");
+ println("#### CASE: LONG HEAP SINGLE");
sk = KllLongsSketch.newHeapInstance(k);
sk.update(1);
println(sk.toString(true, true));
@@ -456,8 +456,8 @@ public class KllMiscLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 20);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 2);
- assertEquals(sk.getMaxItem(), 1.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 1L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
}
@@ -527,8 +527,8 @@ public class KllMiscLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 20);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 2);
- assertEquals(sk.getMaxItem(), 1.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 1L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
}
@@ -597,8 +597,8 @@ public class KllMiscLongsTest {
assertEquals(sk.getMinK(), k);
assertEquals(sk.getLongItemsArray().length, 20);
assertEquals(sk.getLevelsArray(sk.sketchStructure).length, 2);
- assertEquals(sk.getMaxItem(), 1.0F);
- assertEquals(sk.getMinItem(), 1.0F);
+ assertEquals(sk.getMaxItem(), 1L);
+ assertEquals(sk.getMinItem(), 1L);
assertEquals(sk.getNumLevels(), 1);
assertFalse(sk.isLevelZeroSorted());
}
@@ -740,8 +740,8 @@ public class KllMiscLongsTest {
sk2.update(i + 100);
}
sk1.merge(sk2);
- assertEquals(sk1.getMinItem(), 1.0);
- assertEquals(sk1.getMaxItem(), 143.0);
+ assertEquals(sk1.getMinItem(), 1L);
+ assertEquals(sk1.getMaxItem(), 143L);
}
@Test
@@ -755,12 +755,12 @@ public class KllMiscLongsTest {
WritableMemory srcMem =
WritableMemory.writableWrap(KllHelper.toByteArray(skHeap, true));
KllLongsSketch skDirect = KllLongsSketch.writableWrap(srcMem, memReqSvr);
assertTrue(skDirect instanceof KllDirectLongsSketch);
- assertEquals(skDirect.getLongSingleItem(), 1.0F);
+ assertEquals(skDirect.getLongSingleItem(), 1L);
Memory srcMem2 = Memory.wrap(skHeap.toByteArray());
KllLongsSketch skCompact = KllLongsSketch.wrap(srcMem2);
assertTrue(skCompact instanceof KllDirectCompactLongsSketch);
- assertEquals(skCompact.getLongSingleItem(), 1.0F);
+ assertEquals(skCompact.getLongSingleItem(), 1L);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]