diff --git a/pom.xml b/pom.xml index e130f2694..1cce4056c 100644 --- a/pom.xml +++ b/pom.xml @@ -117,7 +117,7 @@ under the License. 4.9.10 - 0.16.1 + 0.17 4.3.0 @@ -332,19 +332,20 @@ under the License. ${project.basedir}/rat true - true - - - **/*.yaml - **/*.yml - **/.* - **/test/resources/**/*.txt - **/git.properties - **/*.sk - LICENSE - NOTICE - **/*.code-workspace - + + + StandardCollection + **/*.yaml + **/*.yml + **/.* + **/test/resources/**/*.txt + **/git.properties + **/doc/** + **/*.sk + LICENSE + NOTICE + **/*.code-workspace + diff --git a/src/main/java/org/apache/datasketches/common/ArrayOfBooleansSerDe.java b/src/main/java/org/apache/datasketches/common/ArrayOfBooleansSerDe.java index 71196f322..ac7283652 100644 --- a/src/main/java/org/apache/datasketches/common/ArrayOfBooleansSerDe.java +++ b/src/main/java/org/apache/datasketches/common/ArrayOfBooleansSerDe.java @@ -30,6 +30,12 @@ * @author Jon Malkin */ public class ArrayOfBooleansSerDe extends ArrayOfItemsSerDe { + + /** + * No argument constructor. + */ + public ArrayOfBooleansSerDe() { } + /** * Computes number of bytes needed for packed bit encoding of the array of booleans. Rounds * partial bytes up to return a whole number of bytes. diff --git a/src/main/java/org/apache/datasketches/common/ArrayOfDoublesSerDe.java b/src/main/java/org/apache/datasketches/common/ArrayOfDoublesSerDe.java index ca170df60..87f8412a9 100644 --- a/src/main/java/org/apache/datasketches/common/ArrayOfDoublesSerDe.java +++ b/src/main/java/org/apache/datasketches/common/ArrayOfDoublesSerDe.java @@ -32,6 +32,11 @@ */ public class ArrayOfDoublesSerDe extends ArrayOfItemsSerDe { + /** + * No argument constructor. + */ + public ArrayOfDoublesSerDe() { } + @Override public byte[] serializeToByteArray(final Double item) { Objects.requireNonNull(item, "Item must not be null"); diff --git a/src/main/java/org/apache/datasketches/common/ArrayOfItemsSerDe.java b/src/main/java/org/apache/datasketches/common/ArrayOfItemsSerDe.java index 5786a3389..81f2d157c 100644 --- a/src/main/java/org/apache/datasketches/common/ArrayOfItemsSerDe.java +++ b/src/main/java/org/apache/datasketches/common/ArrayOfItemsSerDe.java @@ -30,6 +30,11 @@ */ public abstract class ArrayOfItemsSerDe { + /** + * No argument constructor. + */ + public ArrayOfItemsSerDe() { } + /** * Serialize a single unserialized item to a byte array. * diff --git a/src/main/java/org/apache/datasketches/common/ArrayOfLongsSerDe.java b/src/main/java/org/apache/datasketches/common/ArrayOfLongsSerDe.java index b7b85a170..118901b89 100644 --- a/src/main/java/org/apache/datasketches/common/ArrayOfLongsSerDe.java +++ b/src/main/java/org/apache/datasketches/common/ArrayOfLongsSerDe.java @@ -32,6 +32,11 @@ */ public class ArrayOfLongsSerDe extends ArrayOfItemsSerDe { + /** + * No argument constructor. + */ + public ArrayOfLongsSerDe() { } + @Override public byte[] serializeToByteArray(final Long item) { Objects.requireNonNull(item, "Item must not be null"); diff --git a/src/main/java/org/apache/datasketches/common/ArrayOfNumbersSerDe.java b/src/main/java/org/apache/datasketches/common/ArrayOfNumbersSerDe.java index 0d8f27753..797d8d3b0 100644 --- a/src/main/java/org/apache/datasketches/common/ArrayOfNumbersSerDe.java +++ b/src/main/java/org/apache/datasketches/common/ArrayOfNumbersSerDe.java @@ -49,7 +49,6 @@ * @author Jon Malkin */ public class ArrayOfNumbersSerDe extends ArrayOfItemsSerDe { - // values selected to enable backwards compatibility private static final byte LONG_INDICATOR = 12; private static final byte INTEGER_INDICATOR = 9; @@ -58,6 +57,11 @@ public class ArrayOfNumbersSerDe extends ArrayOfItemsSerDe { private static final byte DOUBLE_INDICATOR = 4; private static final byte FLOAT_INDICATOR = 6; + /** + * No argument constructor. + */ + public ArrayOfNumbersSerDe() { } + @Override public byte[] serializeToByteArray(final Number item) { Objects.requireNonNull(item, "Item must not be null"); diff --git a/src/main/java/org/apache/datasketches/common/ArrayOfStringsSerDe.java b/src/main/java/org/apache/datasketches/common/ArrayOfStringsSerDe.java index 7d41987ec..72e2ebea4 100644 --- a/src/main/java/org/apache/datasketches/common/ArrayOfStringsSerDe.java +++ b/src/main/java/org/apache/datasketches/common/ArrayOfStringsSerDe.java @@ -41,6 +41,11 @@ */ public class ArrayOfStringsSerDe extends ArrayOfItemsSerDe { + /** + * No argument constructor. + */ + public ArrayOfStringsSerDe() { } + @Override public byte[] serializeToByteArray(final String item) { Objects.requireNonNull(item, "Item must not be null"); diff --git a/src/main/java/org/apache/datasketches/common/ArrayOfUtf16StringsSerDe.java b/src/main/java/org/apache/datasketches/common/ArrayOfUtf16StringsSerDe.java index 42cd66f4c..cde46fc95 100644 --- a/src/main/java/org/apache/datasketches/common/ArrayOfUtf16StringsSerDe.java +++ b/src/main/java/org/apache/datasketches/common/ArrayOfUtf16StringsSerDe.java @@ -39,6 +39,11 @@ */ public class ArrayOfUtf16StringsSerDe extends ArrayOfItemsSerDe { + /** + * No argument constructor. + */ + public ArrayOfUtf16StringsSerDe() { } + @Override public byte[] serializeToByteArray(final String item) { Objects.requireNonNull(item, "Item must not be null"); diff --git a/src/main/java/org/apache/datasketches/common/ByteArrayUtil.java b/src/main/java/org/apache/datasketches/common/ByteArrayUtil.java index 3be1f0551..abf16eede 100644 --- a/src/main/java/org/apache/datasketches/common/ByteArrayUtil.java +++ b/src/main/java/org/apache/datasketches/common/ByteArrayUtil.java @@ -25,6 +25,11 @@ */ public final class ByteArrayUtil { + /** + * No argument constructor. + */ + public ByteArrayUtil() { } + /** * Copies bytes from source to target with offsets on both the source and target. * @param source the given source diff --git a/src/main/java/org/apache/datasketches/common/MemorySegmentRequest.java b/src/main/java/org/apache/datasketches/common/MemorySegmentRequest.java index 2fe018335..8a10f277a 100644 --- a/src/main/java/org/apache/datasketches/common/MemorySegmentRequest.java +++ b/src/main/java/org/apache/datasketches/common/MemorySegmentRequest.java @@ -53,10 +53,14 @@ default void requestClose(final MemorySegment prevSeg) { } /** - * This class implements the defaults + * A convenience class that implements a default implementation. */ public static class Default implements MemorySegmentRequest { - //A convenience class that creates the target for the static member DEFAULT. + + /** + * No argument constructor that creates the target for the static member DEFAULT. + */ + public Default() { } } /** diff --git a/src/main/java/org/apache/datasketches/common/MemorySegmentRequestExample.java b/src/main/java/org/apache/datasketches/common/MemorySegmentRequestExample.java index 650ce4223..fbf2521b8 100644 --- a/src/main/java/org/apache/datasketches/common/MemorySegmentRequestExample.java +++ b/src/main/java/org/apache/datasketches/common/MemorySegmentRequestExample.java @@ -20,11 +20,10 @@ package org.apache.datasketches.common; import java.lang.foreign.Arena; - import java.lang.foreign.MemorySegment; import java.util.Enumeration; -import java.util.concurrent.ConcurrentHashMap; import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; /** * This is an example of a possible implementation of the MemorySegmentRequest interface @@ -35,6 +34,11 @@ public final class MemorySegmentRequestExample implements MemorySegmentRequest { private final ConcurrentHashMap map = new ConcurrentHashMap<>(); + /** + * No argument constructor. + */ + public MemorySegmentRequestExample() { } + /** * Request a new off-heap MemorySegment with the given newByteSeze. * An internal confined Arena is created to exclusively manage the new segment and it is associated diff --git a/src/main/java/org/apache/datasketches/common/positional/PositionInvariantsException.java b/src/main/java/org/apache/datasketches/common/positional/PositionInvariantsException.java index 720cf91a0..ef327a564 100644 --- a/src/main/java/org/apache/datasketches/common/positional/PositionInvariantsException.java +++ b/src/main/java/org/apache/datasketches/common/positional/PositionInvariantsException.java @@ -21,6 +21,8 @@ /** * Position operation violation. + * + * @author Lee Rhodes */ public class PositionInvariantsException extends RuntimeException { private static final long serialVersionUID = 1L; diff --git a/src/main/java/org/apache/datasketches/common/positional/PositionalImpl.java b/src/main/java/org/apache/datasketches/common/positional/PositionalImpl.java index 930d951b2..01e89eb23 100644 --- a/src/main/java/org/apache/datasketches/common/positional/PositionalImpl.java +++ b/src/main/java/org/apache/datasketches/common/positional/PositionalImpl.java @@ -112,7 +112,7 @@ public final PositionalImpl setStartPositionEnd(final long start, final long pos * @param start the lowest start position * @param pos the current position * @param end the highest position - * @param cap the capacity of the backing buffer. + * @param cap the capacity of the backing resource. */ private static final void checkInvariants(final long start, final long pos, final long end, final long cap) { diff --git a/src/main/java/org/apache/datasketches/common/positional/PositionalSegment.java b/src/main/java/org/apache/datasketches/common/positional/PositionalSegment.java index 10fd7dd9b..192b56271 100644 --- a/src/main/java/org/apache/datasketches/common/positional/PositionalSegment.java +++ b/src/main/java/org/apache/datasketches/common/positional/PositionalSegment.java @@ -22,7 +22,7 @@ import java.lang.foreign.MemorySegment; /** - * Defines the read-only API for relative positional access to a resource. + * Defines the API for relative positional access to a MemorySegment. * * @author Lee Rhodes */ @@ -259,7 +259,7 @@ void getShortArray( int dstOffsetShorts, int lengthShorts); - //PRIMITIVE putX() and putXArray() + //PRIMITIVE setX() and setXArray() /** * Sets the boolean value at the current position. diff --git a/src/main/java/org/apache/datasketches/common/positional/PositionalSegmentImpl.java b/src/main/java/org/apache/datasketches/common/positional/PositionalSegmentImpl.java index a09ed4d4e..380f0bb20 100644 --- a/src/main/java/org/apache/datasketches/common/positional/PositionalSegmentImpl.java +++ b/src/main/java/org/apache/datasketches/common/positional/PositionalSegmentImpl.java @@ -31,6 +31,8 @@ /** * Implementation of PositionalSegment + * + * @author Lee Rhodes */ final class PositionalSegmentImpl extends PositionalImpl implements PositionalSegment { private static final byte SHORT_SHIFT = 1; @@ -200,7 +202,7 @@ public void getShortArray(final short[] dstArray, final int dstOffsetShorts, fin incrementPosition(lengthShorts << SHORT_SHIFT); } - //PRIMITIVE putX() and putXArray() implementations + //PRIMITIVE setX() and setXArray() implementations @Override public void setBoolean(final boolean value) { diff --git a/src/main/java/org/apache/datasketches/common/positional/package-info.java b/src/main/java/org/apache/datasketches/common/positional/package-info.java index 852956ae6..9049e3573 100644 --- a/src/main/java/org/apache/datasketches/common/positional/package-info.java +++ b/src/main/java/org/apache/datasketches/common/positional/package-info.java @@ -17,4 +17,11 @@ * under the License. */ +/** + * This package provides the classes that define and implement a relative positional API. + * + * @see org.apache.datasketches.common.positional.Positional + * + * @author Lee Rhodes + */ package org.apache.datasketches.common.positional; diff --git a/src/main/java/org/apache/datasketches/count/package-info.java b/src/main/java/org/apache/datasketches/count/package-info.java index bb39c938f..c363f1d4a 100644 --- a/src/main/java/org/apache/datasketches/count/package-info.java +++ b/src/main/java/org/apache/datasketches/count/package-info.java @@ -17,4 +17,24 @@ * under the License. */ +/** + * This package in intended for implementations of the the Count Sketch and the Count-min Sketch both of which can be used to estimate + * frequency-moments of a stream of distinct elements. They are different from the unique counting sketches (HLL, Theta, CPC, etc.) + * and different from the Frequent-Items Sketch. + * + *

A Count-Min sketch is a probabilistic data structure that estimates the frequency of items in a large data stream using a + * fixed amount of memory. It uses a 2D array of counters and multiple hash functions to map each item to a position in every row. + * To estimate an item's frequency, it takes the minimum count from all the positions it hashes to, which provides an overestimate + * that is guaranteed to be greater than or equal to the true count.

+ * + *

A Count sketch is a type of dimensionality reduction that is particularly efficient in statistics, machine learning and + * algorithms. It was invented by Moses Charikar, Kevin Chen and Martin Farach-Colton in an effort to speed up the AMS Sketch by + * Alon, Matias and Szegedy for approximating the frequency moments of streams[4] (these calculations require counting of the + * number of occurrences for the distinct elements of the stream).

+ * + * @see https://en.wikipedia.org/wiki/Count_sketch + * @see https://en.wikipedia.org/wiki/Count%E2%80%93min_sketch + * + */ + package org.apache.datasketches.count; diff --git a/src/main/java/org/apache/datasketches/cpc/TestUtil.java b/src/main/java/org/apache/datasketches/cpc/TestUtil.java index e9dad61ab..f555dae67 100644 --- a/src/main/java/org/apache/datasketches/cpc/TestUtil.java +++ b/src/main/java/org/apache/datasketches/cpc/TestUtil.java @@ -30,6 +30,11 @@ */ public class TestUtil { + /** + * No argument constructor. + */ + public TestUtil() { } + static final double pwrLaw10NextDouble(final int ppb, final double curPoint) { final double cur = (curPoint < 1.0) ? 1.0 : curPoint; double gi = round(Math.log10(cur) * ppb); //current generating index diff --git a/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java b/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java index 8e043e124..0c19c64b1 100644 --- a/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java +++ b/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java @@ -34,6 +34,11 @@ */ public final class BloomFilterBuilder { + /** + * No argument constructor. + */ + public BloomFilterBuilder() { } + /** * Returns the optimal number of hash functions to given target numbers of distinct items * and the BloomFilter size in bits. This function will provide a result even if the input diff --git a/src/main/java/org/apache/datasketches/frequencies/FrequentItemsSketch.java b/src/main/java/org/apache/datasketches/frequencies/FrequentItemsSketch.java index dfa72f4e3..857d8e1f6 100644 --- a/src/main/java/org/apache/datasketches/frequencies/FrequentItemsSketch.java +++ b/src/main/java/org/apache/datasketches/frequencies/FrequentItemsSketch.java @@ -56,7 +56,10 @@ import org.apache.datasketches.common.SketchesStateException; /** - * This sketch is useful for tracking approximate frequencies of items of type <T> + * This sketch is based on the paper https://arxiv.org/abs/1705.07001 + * ("A High-Performance Algorithm for Identifying Frequent Items in Data Streams" + * by Daniel Anderson, Pryce Bevan, Kevin Lang, Edo Liberty, Lee Rhodes, and Justin Thaler) + * and is useful for tracking approximate frequencies of items of type <T> * with optional associated counts (<T> item, long count) that are members of a * multiset of such items. The true frequency of an item is defined to be the sum of associated * counts. diff --git a/src/main/java/org/apache/datasketches/frequencies/FrequentLongsSketch.java b/src/main/java/org/apache/datasketches/frequencies/FrequentLongsSketch.java index 04b2c1d5e..f20e97352 100644 --- a/src/main/java/org/apache/datasketches/frequencies/FrequentLongsSketch.java +++ b/src/main/java/org/apache/datasketches/frequencies/FrequentLongsSketch.java @@ -54,7 +54,10 @@ import org.apache.datasketches.common.SuppressFBWarnings; /** - * This sketch is useful for tracking approximate frequencies of long items with optional + * This sketch is based on the paper https://arxiv.org/abs/1705.07001 + * ("A High-Performance Algorithm for Identifying Frequent Items in Data Streams" + * by Daniel Anderson, Pryce Bevan, Kevin Lang, Edo Liberty, Lee Rhodes, and Justin Thaler) + * and is useful for tracking approximate frequencies of long items with optional * associated counts (long item, long count) that are members of a multiset of * such items. The true frequency of an item is defined to be the sum of associated counts. * diff --git a/src/main/java/org/apache/datasketches/frequencies/package-info.java b/src/main/java/org/apache/datasketches/frequencies/package-info.java index 0071240da..d7ab9b7ac 100644 --- a/src/main/java/org/apache/datasketches/frequencies/package-info.java +++ b/src/main/java/org/apache/datasketches/frequencies/package-info.java @@ -17,4 +17,7 @@ * under the License. */ +/** + * This package contains the implementations of the paper https://arxiv.org/abs/1705.07001. + */ package org.apache.datasketches.frequencies; diff --git a/src/main/java/org/apache/datasketches/hash/MurmurHash3FFM21.java b/src/main/java/org/apache/datasketches/hash/MurmurHash3FFM.java similarity index 98% rename from src/main/java/org/apache/datasketches/hash/MurmurHash3FFM21.java rename to src/main/java/org/apache/datasketches/hash/MurmurHash3FFM.java index 1d6823839..722aba8bb 100644 --- a/src/main/java/org/apache/datasketches/hash/MurmurHash3FFM21.java +++ b/src/main/java/org/apache/datasketches/hash/MurmurHash3FFM.java @@ -44,16 +44,16 @@ *

This implementation produces exactly the same hash result as the * MurmurHash3 function in datasketches-java given compatible inputs.

* - *

This FFM21 version of the implementation leverages the java.lang.foreign package (FFM) of JDK-21 in place of + *

This FFM version of the implementation leverages the java.lang.foreign package (FFM) of JDK-25 in place of * the Unsafe class. * * @author Lee Rhodes */ -public final class MurmurHash3FFM21 { +public final class MurmurHash3FFM { private static final long C1 = 0x87c37b91114253d5L; private static final long C2 = 0x4cf5ad432745937fL; - private MurmurHash3FFM21() { } + private MurmurHash3FFM() { } /** * Returns a 128-bit hash of the input. @@ -199,7 +199,7 @@ public static long[] hash(final MemorySegment seg, final long offsetBytes, final final long k1 = seg.get(JAVA_LONG_UNALIGNED, cumOff); //0, 16, 32, ... final long k2 = seg.get(JAVA_LONG_UNALIGNED, cumOff + 8); //8, 24, 40, ... - synchronized (MurmurHash3FFM21.class) { + synchronized (MurmurHash3FFM.class) { cumOff += 16L; rem -= 16L; } diff --git a/src/main/java/org/apache/datasketches/kll/KllDoublesSketch.java b/src/main/java/org/apache/datasketches/kll/KllDoublesSketch.java index 541d551c1..2981d3628 100644 --- a/src/main/java/org/apache/datasketches/kll/KllDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/kll/KllDoublesSketch.java @@ -35,7 +35,7 @@ import org.apache.datasketches.quantilescommon.DoublesSketchSortedView; import org.apache.datasketches.quantilescommon.QuantileSearchCriteria; import org.apache.datasketches.quantilescommon.QuantilesDoublesAPI; -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; /** * This variation of the KllSketch implements primitive doubles. @@ -266,7 +266,7 @@ public double[] getRanks(final double[] quantiles, final QuantileSearchCriteria } @Override - public QuantilesDoublesSketchIterator iterator() { + public QuantilesDoublesSketchIteratorAPI iterator() { return new KllDoublesSketchIterator( getDoubleItemsArray(), getLevelsArray(SketchStructure.UPDATABLE), getNumLevels()); } diff --git a/src/main/java/org/apache/datasketches/kll/KllDoublesSketchIterator.java b/src/main/java/org/apache/datasketches/kll/KllDoublesSketchIterator.java index bc18c5347..9c7e4bd13 100644 --- a/src/main/java/org/apache/datasketches/kll/KllDoublesSketchIterator.java +++ b/src/main/java/org/apache/datasketches/kll/KllDoublesSketchIterator.java @@ -19,12 +19,12 @@ package org.apache.datasketches.kll; -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; /** * Iterator over KllDoublesSketch. The order is not defined. */ -public final class KllDoublesSketchIterator extends KllSketchIterator implements QuantilesDoublesSketchIterator { +public final class KllDoublesSketchIterator extends KllSketchIterator implements QuantilesDoublesSketchIteratorAPI { private final double[] quantiles; KllDoublesSketchIterator(final double[] quantiles, final int[] levelsArr, final int numLevels) { diff --git a/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java b/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java index 6e3b6c374..89f277fb8 100644 --- a/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java +++ b/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java @@ -37,7 +37,7 @@ import org.apache.datasketches.quantilescommon.ItemsSketchSortedView; import org.apache.datasketches.quantilescommon.QuantileSearchCriteria; import org.apache.datasketches.quantilescommon.QuantilesGenericAPI; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; /** * This variation of the KllSketch implements generic data types. The user must provide @@ -256,7 +256,7 @@ public final ItemsSketchSortedView getSortedView() { } @Override - public QuantilesGenericSketchIterator iterator() { + public QuantilesGenericSketchIteratorAPI iterator() { return new KllItemsSketchIterator<>( getTotalItemsArray(), getLevelsArray(SketchStructure.UPDATABLE), getNumLevels()); } diff --git a/src/main/java/org/apache/datasketches/kll/KllItemsSketchIterator.java b/src/main/java/org/apache/datasketches/kll/KllItemsSketchIterator.java index 02bda7a20..0e39c2c69 100644 --- a/src/main/java/org/apache/datasketches/kll/KllItemsSketchIterator.java +++ b/src/main/java/org/apache/datasketches/kll/KllItemsSketchIterator.java @@ -19,13 +19,13 @@ package org.apache.datasketches.kll; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; /** * Iterator over KllItemsSketch. The order is not defined. * @param the item class type */ -public final class KllItemsSketchIterator extends KllSketchIterator implements QuantilesGenericSketchIterator { +public final class KllItemsSketchIterator extends KllSketchIterator implements QuantilesGenericSketchIteratorAPI { private final Object[] quantiles; KllItemsSketchIterator(final Object[] quantiles, final int[] levelsArr, final int numLevels) { diff --git a/src/main/java/org/apache/datasketches/kll/KllSketch.java b/src/main/java/org/apache/datasketches/kll/KllSketch.java index d25176871..2a3f992dd 100644 --- a/src/main/java/org/apache/datasketches/kll/KllSketch.java +++ b/src/main/java/org/apache/datasketches/kll/KllSketch.java @@ -71,7 +71,7 @@ /** * This class is the root of the KLL sketch class hierarchy. It includes the public API that is independent - * of either sketch type (e.g., float, double or generic item) and independent of whether the sketch is targeted + * of either sketch type (e.g., float, double, long or generic item) and independent of whether the sketch is targeted * for use on the Java heap or off-heap. * *

KLL is an implementation of a very compact quantiles sketch with lazy compaction scheme diff --git a/src/main/java/org/apache/datasketches/kll/KllSketchIterator.java b/src/main/java/org/apache/datasketches/kll/KllSketchIterator.java index feaf33f53..3e16fbc11 100644 --- a/src/main/java/org/apache/datasketches/kll/KllSketchIterator.java +++ b/src/main/java/org/apache/datasketches/kll/KllSketchIterator.java @@ -19,7 +19,7 @@ package org.apache.datasketches.kll; -import org.apache.datasketches.quantilescommon.QuantilesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesSketchIteratorAPI; /** * The base implementation for the KLL sketch iterator hierarchy used for viewing the @@ -35,7 +35,7 @@ * * @author Lee Rhodes */ -public class KllSketchIterator implements QuantilesSketchIterator { +public class KllSketchIterator implements QuantilesSketchIteratorAPI { protected final int[] levelsArr; protected final int numLevels; protected int level; diff --git a/src/main/java/org/apache/datasketches/partitions/package-info.java b/src/main/java/org/apache/datasketches/partitions/package-info.java index cee11ec1d..58bd126b3 100644 --- a/src/main/java/org/apache/datasketches/partitions/package-info.java +++ b/src/main/java/org/apache/datasketches/partitions/package-info.java @@ -18,6 +18,7 @@ */ /** - * + * This package is for classes that simplify the task of partitioning large data into many approximately equal-sized + * partitions. */ package org.apache.datasketches.partitions; diff --git a/src/main/java/org/apache/datasketches/quantiles/ClassicUtil.java b/src/main/java/org/apache/datasketches/quantiles/ClassicUtil.java index 4e49a7dbb..d86a0f487 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ClassicUtil.java +++ b/src/main/java/org/apache/datasketches/quantiles/ClassicUtil.java @@ -57,7 +57,7 @@ private ClassicUtil() {} /** * Used by Classic Quantiles. - * Gets the normalized rank error given k and pmf for the Quantiles DoubleSketch and ItemsSketch. + * Gets the normalized rank error given k and pmf for the QuantilesDoubleSketch and QuantilesItemsSketch. * @param k the configuration parameter * @param pmf if true, returns the "double-sided" normalized rank error for the getPMF() function. * Otherwise, it is the "single-sided" normalized rank error for all the other queries. @@ -75,7 +75,7 @@ public static double getNormalizedRankError(final int k, final boolean pmf) { /** * Used by Classic Quantiles. * Gets the approximate k to use given epsilon, the normalized rank error - * for the Quantiles DoubleSketch and ItemsSketch. + * for the QuantilesDoubleSketch and QuantilesItemsSketch. * @param epsilon the normalized rank error between zero and one. * @param pmf if true, this function returns k assuming the input epsilon * is the desired "double-sided" epsilon for the getPMF() function. Otherwise, this function @@ -109,7 +109,7 @@ public static int getKFromEpsilon(final double epsilon, final boolean pmf) { static int computeGrowingBaseBufferCap(final int k, final int curCombinedBufCap) { if (curCombinedBufCap < (2 * k)) { return 2 * Math.max(Math.min(k, curCombinedBufCap), MIN_K); - } + } return 2 * k; } diff --git a/src/main/java/org/apache/datasketches/quantiles/CompactDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/CompactQuantilesDoublesSketch.java similarity index 91% rename from src/main/java/org/apache/datasketches/quantiles/CompactDoublesSketch.java rename to src/main/java/org/apache/datasketches/quantiles/CompactQuantilesDoublesSketch.java index 18e05d315..490ac35eb 100644 --- a/src/main/java/org/apache/datasketches/quantiles/CompactDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/CompactQuantilesDoublesSketch.java @@ -25,8 +25,8 @@ * Compact sketches are inherently read only. * @author Jon Malkin */ -public abstract class CompactDoublesSketch extends DoublesSketch { - CompactDoublesSketch(final int k) { +public abstract class CompactQuantilesDoublesSketch extends QuantilesDoublesSketch { + CompactQuantilesDoublesSketch(final int k) { super(k); } diff --git a/src/main/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketch.java index af0579eef..baf03736a 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketch.java @@ -59,13 +59,13 @@ import org.apache.datasketches.quantilescommon.QuantilesAPI; /** - * Implements the DoublesSketch off-heap. + * Implements the QuantilesDoublesSketch off-heap. * * @author Kevin Lang * @author Lee Rhodes * @author Jon Malkin */ -final class DirectCompactDoublesSketch extends CompactDoublesSketch { +final class DirectCompactDoublesSketch extends CompactQuantilesDoublesSketch { private static final int MIN_DIRECT_DOUBLES_SER_VER = 3; private final MemorySegment seg_; @@ -76,13 +76,13 @@ private DirectCompactDoublesSketch(final int k, final MemorySegment seg) { } /** - * Converts the given UpdateDoublesSketch to this compact form. + * Converts the given UpdatableQuantilesDoublesSketch to this compact form. * * @param sketch the sketch to convert * @param dstSeg the MemorySegment to use for the destination - * @return a DirectCompactDoublesSketch created from an UpdateDoublesSketch + * @return a DirectCompactDoublesSketch created from an UpdatableQuantilesDoublesSketch */ - static DirectCompactDoublesSketch createFromUpdateSketch(final UpdateDoublesSketch sketch, + static DirectCompactDoublesSketch createFromUpdateSketch(final UpdatableQuantilesDoublesSketch sketch, final MemorySegment dstSeg) { final long segCap = dstSeg.byteSize(); final int k = sketch.getK(); @@ -133,9 +133,9 @@ static DirectCompactDoublesSketch createFromUpdateSketch(final UpdateDoublesSket } /** - * Wrap this sketch around the given compact MemorySegment image of a DoublesSketch. + * Wrap this sketch around the given compact MemorySegment image of a QuantilesDoublesSketch. * - * @param srcSeg the given compact MemorySegment image of a DoublesSketch, + * @param srcSeg the given compact MemorySegment image of a QuantilesDoublesSketch, * @return a sketch that wraps the given srcSeg. */ static DirectCompactDoublesSketch wrapInstance(final MemorySegment srcSeg) { diff --git a/src/main/java/org/apache/datasketches/quantiles/DirectDoublesSketchAccessor.java b/src/main/java/org/apache/datasketches/quantiles/DirectDoublesSketchAccessor.java index dd66e6466..4452645b2 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DirectDoublesSketchAccessor.java +++ b/src/main/java/org/apache/datasketches/quantiles/DirectDoublesSketchAccessor.java @@ -29,7 +29,7 @@ */ final class DirectDoublesSketchAccessor extends DoublesSketchAccessor { - DirectDoublesSketchAccessor(final DoublesSketch ds, + DirectDoublesSketchAccessor(final QuantilesDoublesSketch ds, final boolean forceSize, final int level) { super(ds, forceSize, level); diff --git a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java index 168b80b16..a3b717beb 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java @@ -62,12 +62,12 @@ import org.apache.datasketches.quantilescommon.QuantilesAPI; /** - * Implements the DoublesSketch in a MemorySegment. + * Implements the QuantilesDoublesSketch in a MemorySegment. * * @author Kevin Lang * @author Lee Rhodes */ -final class DirectUpdateDoublesSketch extends UpdateDoublesSketch { +final class DirectUpdateDoublesSketch extends UpdatableQuantilesDoublesSketch { private static final int MIN_DIRECT_DOUBLES_SER_VER = 3; private MemorySegmentRequest mSegReq_ = null; private MemorySegment seg_; @@ -80,7 +80,7 @@ private DirectUpdateDoublesSketch(final int k, final MemorySegment seg, final Me } /** - * Creates a new instance of a DoublesSketch in a MemorySegment. + * Creates a new instance of a QuantilesDoublesSketch in a MemorySegment. * * @param k Parameter that controls space usage of sketch and accuracy of estimates. * Must be greater than 1 and less than 65536 and a power of 2. @@ -114,9 +114,9 @@ static DirectUpdateDoublesSketch newInstance(final int k, final MemorySegment ds } /** - * Wrap this sketch around the given updatable MemorySegment image of a DoublesSketch. + * Wrap this sketch around the given updatable MemorySegment image of a QuantilesDoublesSketch. * - * @param srcSeg the given MemorySegment image of an UpdateDoublesSketch and must not be null. + * @param srcSeg the given MemorySegment image of an UpdatableQuantilesDoublesSketch and must not be null. * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand. * Otherwise, it can be null and the default MemorySegmentRequest will be used. * @return a sketch that wraps the given srcSeg @@ -294,7 +294,7 @@ MemorySegment getMemorySegment() { } @Override - UpdateDoublesSketch getSketchAndReset() { + UpdatableQuantilesDoublesSketch getSketchAndReset() { final HeapUpdateDoublesSketch skCopy = HeapUpdateDoublesSketch.heapifyInstance(seg_); reset(); return skCopy; diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesByteArrayImpl.java b/src/main/java/org/apache/datasketches/quantiles/DoublesByteArrayImpl.java index 8d5f817de..0deea1d9b 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesByteArrayImpl.java +++ b/src/main/java/org/apache/datasketches/quantiles/DoublesByteArrayImpl.java @@ -51,7 +51,7 @@ final class DoublesByteArrayImpl { private DoublesByteArrayImpl() {} - static byte[] toByteArray(final DoublesSketch sketch, final boolean ordered, final boolean compact) { + static byte[] toByteArray(final QuantilesDoublesSketch sketch, final boolean ordered, final boolean compact) { final boolean empty = sketch.isEmpty(); //create the flags byte @@ -72,13 +72,13 @@ static byte[] toByteArray(final DoublesSketch sketch, final boolean ordered, fin /** * Returns a byte array, including preamble, min, max and data extracted from the sketch. - * @param sketch the given DoublesSketch + * @param sketch the given QuantilesDoublesSketch * @param flags the Flags field * @param ordered true if the desired form of the resulting array has the base buffer sorted. * @param compact true if the desired form of the resulting array is in compact form. * @return a byte array, including preamble, min, max and data extracted from the Combined Buffer. */ - private static byte[] convertToByteArray(final DoublesSketch sketch, final int flags, + private static byte[] convertToByteArray(final QuantilesDoublesSketch sketch, final int flags, final boolean ordered, final boolean compact) { final int preLongs = sketch.isEmpty() ? 1 : 2; diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesMergeImpl.java b/src/main/java/org/apache/datasketches/quantiles/DoublesMergeImpl.java index ab1747472..c8ae7de0a 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesMergeImpl.java +++ b/src/main/java/org/apache/datasketches/quantiles/DoublesMergeImpl.java @@ -61,7 +61,7 @@ private DoublesMergeImpl() {} * @param src The source sketch * @param tgt The target sketch */ - static void mergeInto(final DoublesSketch src, final UpdateDoublesSketch tgt) { + static void mergeInto(final QuantilesDoublesSketch src, final UpdatableQuantilesDoublesSketch tgt) { final int srcK = src.getK(); final int tgtK = tgt.getK(); final long srcN = src.getN(); @@ -141,8 +141,8 @@ static void mergeInto(final DoublesSketch src, final UpdateDoublesSketch tgt) { * @param src The source sketch * @param tgt The target sketch */ - //also used by DoublesSketch, DoublesUnionImpl and HeapDoublesSketchTest - static void downSamplingMergeInto(final DoublesSketch src, final UpdateDoublesSketch tgt) { + //also used by QuantilesDoublesSketch, QuantilesDoublesUnionImpl and HeapDoublesSketchTest + static void downSamplingMergeInto(final QuantilesDoublesSketch src, final UpdatableQuantilesDoublesSketch tgt) { final int sourceK = src.getK(); final int targetK = tgt.getK(); final long tgtN = tgt.getN(); @@ -227,7 +227,7 @@ private static void justZipWithStride( final DoublesBufferAccessor bufC, // output final int kC, // number of items that should be in the output final int stride) { - final int randomOffset = DoublesSketch.rand.nextInt(stride); + final int randomOffset = QuantilesDoublesSketch.rand.nextInt(stride); for (int a = randomOffset, c = 0; c < kC; a += stride, c++ ) { bufC.set(c, bufA.get(a)); } diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesSketchAccessor.java b/src/main/java/org/apache/datasketches/quantiles/DoublesSketchAccessor.java index 41355f63d..4c4bdd5cd 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesSketchAccessor.java +++ b/src/main/java/org/apache/datasketches/quantiles/DoublesSketchAccessor.java @@ -32,7 +32,7 @@ abstract class DoublesSketchAccessor extends DoublesBufferAccessor { static final int BB_LVL_IDX = -1; - final DoublesSketch ds_; + final QuantilesDoublesSketch ds_; final boolean forceSize_; long n_; @@ -41,10 +41,10 @@ abstract class DoublesSketchAccessor extends DoublesBufferAccessor { int offset_; //bytes for Direct, doubles for heap DoublesSketchAccessor( - final DoublesSketch ds, - final boolean forceSize, - final int level) { - checkLvl(level); + final QuantilesDoublesSketch ds, + final boolean forceSize, + final int level) { + checkLvl(level); ds_ = ds; forceSize_ = forceSize; setLevel(level); @@ -57,14 +57,14 @@ private static final void checkLvl(final int level) { } /** - * Wrap the given DoublesSketch - * @param ds the given DoublesSketch + * Wrap the given QuantilesDoublesSketch + * @param ds the given QuantilesDoublesSketch * @param forceSize Generally, this must be true if modeling an updatable sketch, i.e., not compact. * See {@link #setLevel(int) setLevel(int)} below. * * @return this */ - static DoublesSketchAccessor wrap(final DoublesSketch ds, final boolean forceSize) { + static DoublesSketchAccessor wrap(final QuantilesDoublesSketch ds, final boolean forceSize) { if (ds.hasMemorySegment()) { return new DirectDoublesSketchAccessor(ds, forceSize, BB_LVL_IDX); } @@ -76,7 +76,7 @@ static DoublesSketchAccessor wrap(final DoublesSketch ds, final boolean forceSiz /* * This initializes the following internal member variables: *

    - *
  • n_ The local copy of DoublesSketch.getN().
  • + *
  • n_ The local copy of QuantilesDoublesSketch.getN().
  • *
  • currLvl_ The current level being processed.
  • *
  • numItems_ The number of items in this level.
  • *
  • offset_ If accessing a MemorySegment sketch, this is bytes offset from the start of the segment. diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesUpdateImpl.java b/src/main/java/org/apache/datasketches/quantiles/DoublesUpdateImpl.java index 174654dae..f76ddebad 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesUpdateImpl.java +++ b/src/main/java/org/apache/datasketches/quantiles/DoublesUpdateImpl.java @@ -130,7 +130,7 @@ static long inPlacePropagateCarry( private static void zipSize2KBuffer( final DoublesBufferAccessor bufIn, final DoublesBufferAccessor bufOut) { - final int randomOffset = DoublesSketch.rand.nextBoolean() ? 1 : 0; + final int randomOffset = QuantilesDoublesSketch.rand.nextBoolean() ? 1 : 0; final int limOut = bufOut.numItems(); for (int idxIn = randomOffset, idxOut = 0; idxOut < limOut; idxIn += 2, idxOut++) { bufOut.set(idxOut, bufIn.get(idxIn)); diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesUtil.java b/src/main/java/org/apache/datasketches/quantiles/DoublesUtil.java index abbb86207..da6b89579 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesUtil.java +++ b/src/main/java/org/apache/datasketches/quantiles/DoublesUtil.java @@ -49,7 +49,7 @@ private DoublesUtil() {} * @param sketch the given sketch * @return a copy of the given sketch */ - static HeapUpdateDoublesSketch copyToHeap(final DoublesSketch sketch) { + static HeapUpdateDoublesSketch copyToHeap(final QuantilesDoublesSketch sketch) { final HeapUpdateDoublesSketch qsCopy; qsCopy = HeapUpdateDoublesSketch.newInstance(sketch.getK()); qsCopy.putN(sketch.getN()); @@ -97,7 +97,7 @@ static void checkDoublesSerVer(final int serVer, final int minSupportedSerVer) { } } - static String toString(final boolean withLevels, final boolean withLevelsAndItems, final DoublesSketch sk) { + static String toString(final boolean withLevels, final boolean withLevelsAndItems, final QuantilesDoublesSketch sk) { final StringBuilder sb = new StringBuilder(); sb.append(getSummary(sk)); if (withLevels) { @@ -109,7 +109,7 @@ static String toString(final boolean withLevels, final boolean withLevelsAndItem return sb.toString(); } - private static String getSummary(final DoublesSketch sk) { + private static String getSummary(final QuantilesDoublesSketch sk) { final StringBuilder sb = new StringBuilder(); final String thisSimpleName = sk.getClass().getSimpleName(); final int k = sk.getK(); @@ -157,7 +157,7 @@ private static String getSummary(final DoublesSketch sk) { return sb.toString(); } - private static String outputLevels(final DoublesSketch sk) { + private static String outputLevels(final QuantilesDoublesSketch sk) { final String name = sk.getClass().getSimpleName(); final int k = sk.getK(); final long n = sk.getN(); @@ -180,7 +180,7 @@ private static String outputLevels(final DoublesSketch sk) { return sb.toString(); } - private static String outputDataDetail(final DoublesSketch sk) { + private static String outputDataDetail(final QuantilesDoublesSketch sk) { final String name = sk.getClass().getSimpleName(); final int k = sk.getK(); final long n = sk.getN(); diff --git a/src/main/java/org/apache/datasketches/quantiles/HeapCompactDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/HeapCompactDoublesSketch.java index 1ab9d2e32..f4b45fc54 100644 --- a/src/main/java/org/apache/datasketches/quantiles/HeapCompactDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/HeapCompactDoublesSketch.java @@ -42,12 +42,12 @@ import org.apache.datasketches.quantilescommon.QuantilesAPI; /** - * Implements the DoublesSketch on the Java heap. + * Implements the QuantilesDoublesSketch on the Java heap. * * @author Lee Rhodes * @author Jon Malkin */ -final class HeapCompactDoublesSketch extends CompactDoublesSketch { +final class HeapCompactDoublesSketch extends CompactQuantilesDoublesSketch { static final int MIN_HEAP_DOUBLES_SER_VER = 1; /** @@ -96,12 +96,12 @@ private HeapCompactDoublesSketch(final int k) { } /** - * Converts the given UpdateDoublesSketch to this compact form. + * Converts the given UpdatableQuantilesDoublesSketch to this compact form. * * @param sketch the sketch to convert - * @return a HeapCompactDoublesSketch created from an UpdateDoublesSketch + * @return a HeapCompactDoublesSketch created from an UpdatableQuantilesDoublesSketch */ - static HeapCompactDoublesSketch createFromUpdateSketch(final UpdateDoublesSketch sketch) { + static HeapCompactDoublesSketch createFromUpdateSketch(final UpdatableQuantilesDoublesSketch sketch) { final int k = sketch.getK(); final long n = sketch.getN(); @@ -149,10 +149,10 @@ static HeapCompactDoublesSketch createFromUpdateSketch(final UpdateDoublesSketch } /** - * Heapifies the given srcSeg, which must be a MemorySegment image of a DoublesSketch and may have data. + * Heapifies the given srcSeg, which must be a MemorySegment image of a QuantilesDoublesSketch and may have data. * * @param srcSeg a MemorySegment image of a sketch, which may be in compact or not compact form. - * @return a DoublesSketch on the Java heap. + * @return a QuantilesDoublesSketch on the Java heap. */ static HeapCompactDoublesSketch heapifyInstance(final MemorySegment srcSeg) { final long segCapBytes = srcSeg.byteSize(); diff --git a/src/main/java/org/apache/datasketches/quantiles/HeapDoublesSketchAccessor.java b/src/main/java/org/apache/datasketches/quantiles/HeapDoublesSketchAccessor.java index fac541e55..66585d070 100644 --- a/src/main/java/org/apache/datasketches/quantiles/HeapDoublesSketchAccessor.java +++ b/src/main/java/org/apache/datasketches/quantiles/HeapDoublesSketchAccessor.java @@ -26,7 +26,7 @@ */ final class HeapDoublesSketchAccessor extends DoublesSketchAccessor { - HeapDoublesSketchAccessor(final DoublesSketch ds, + HeapDoublesSketchAccessor(final QuantilesDoublesSketch ds, final boolean forceSize, final int level) { super(ds, forceSize, level); diff --git a/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java index aa65d8796..144e94fb7 100644 --- a/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java @@ -49,12 +49,12 @@ import org.apache.datasketches.quantilescommon.QuantilesAPI; /** - * Implements the DoublesSketch on the Java heap. + * Implements the QuantilesDoublesSketch on the Java heap. * * @author Lee Rhodes * @author Jon Malkin */ -final class HeapUpdateDoublesSketch extends UpdateDoublesSketch { +final class HeapUpdateDoublesSketch extends UpdatableQuantilesDoublesSketch { static final int MIN_HEAP_DOUBLES_SER_VER = 1; /** @@ -104,7 +104,7 @@ private HeapUpdateDoublesSketch(final int k) { } /** - * Obtains a new on-heap instance of a DoublesSketch. + * Obtains a new on-heap instance of a QuantilesDoublesSketch. * * @param k Parameter that controls space usage of sketch and accuracy of estimates. * Must be greater than 1 and less than 65536 and a power of 2. @@ -123,10 +123,10 @@ static HeapUpdateDoublesSketch newInstance(final int k) { } /** - * Heapifies the given srcSeg, which must be a MemorySegment image of a DoublesSketch and may have data. + * Heapifies the given srcSeg, which must be a MemorySegment image of a QuantilesDoublesSketch and may have data. * * @param srcSeg a MemorySegment image of a sketch, which may be in compact or updatable form. - * @return a DoublesSketch on the Java heap. + * @return a QuantilesDoublesSketch on the Java heap. */ static HeapUpdateDoublesSketch heapifyInstance(final MemorySegment srcSeg) { final long segCapBytes = srcSeg.byteSize(); diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsByteArrayImpl.java b/src/main/java/org/apache/datasketches/quantiles/ItemsByteArrayImpl.java index 69aaf33ce..9c78268d4 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsByteArrayImpl.java +++ b/src/main/java/org/apache/datasketches/quantiles/ItemsByteArrayImpl.java @@ -47,7 +47,7 @@ final class ItemsByteArrayImpl { private ItemsByteArrayImpl() {} - static byte[] toByteArray(final ItemsSketch sketch, final boolean ordered, final ArrayOfItemsSerDe serDe) { + static byte[] toByteArray(final QuantilesItemsSketch sketch, final boolean ordered, final ArrayOfItemsSerDe serDe) { final boolean empty = sketch.isEmpty(); final int flags = (empty ? EMPTY_FLAG_MASK : 0) @@ -84,12 +84,12 @@ static byte[] toByteArray(final ItemsSketch sketch, final boolean ordered * Returns an array of items in compact form, including min and max extracted from the * Combined Buffer. * @param the data type - * @param sketch a type of ItemsSketch + * @param sketch a type of QuantilesItemsSketch * @param ordered true if the desired form of the resulting array has the base buffer sorted. * @return an array of items, including min and max extracted from the Combined Buffer. */ @SuppressWarnings("unchecked") - private static T[] combinedBufferToItemsArray(final ItemsSketch sketch, + private static T[] combinedBufferToItemsArray(final QuantilesItemsSketch sketch, final boolean ordered) { final int extra = 2; // extra space for min and max items final int outArrCap = sketch.getNumRetained(); diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsMergeImpl.java b/src/main/java/org/apache/datasketches/quantiles/ItemsMergeImpl.java index 2c1566988..5105abe8a 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsMergeImpl.java +++ b/src/main/java/org/apache/datasketches/quantiles/ItemsMergeImpl.java @@ -63,7 +63,7 @@ private ItemsMergeImpl() {} * @param tgt The target sketch */ @SuppressWarnings("unchecked") - static void mergeInto(final ItemsSketch src, final ItemsSketch tgt) { + static void mergeInto(final QuantilesItemsSketch src, final QuantilesItemsSketch tgt) { final int srcK = src.getK(); final int tgtK = tgt.getK(); final long srcN = src.getN(); @@ -133,8 +133,8 @@ else if (tgtMin == null) { //if srcMin were null we would leave tgt alone * @param src The source sketch * @param tgt The target sketch */ - @SuppressWarnings("unchecked") //also used by ItemsSketch and ItemsUnion - static void downSamplingMergeInto(final ItemsSketch src, final ItemsSketch tgt) { + @SuppressWarnings("unchecked") //also used by QuantilesItemsSketch and QuantilesItemsUnion + static void downSamplingMergeInto(final QuantilesItemsSketch src, final QuantilesItemsSketch tgt) { final int sourceK = src.getK(); final int targetK = tgt.getK(); @@ -208,7 +208,7 @@ private static void justZipWithStride( final T[] bufC, final int startC, // output final int kC, // number of items that should be in the output final int stride) { - final int randomOffset = ItemsSketch.rand.nextInt(stride); + final int randomOffset = QuantilesItemsSketch.rand.nextInt(stride); final int limC = startC + kC; for (int a = startSrc + randomOffset, c = startC; c < limC; a += stride, c++ ) { bufC[c] = bufSrc[a]; diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsUpdateImpl.java b/src/main/java/org/apache/datasketches/quantiles/ItemsUpdateImpl.java index 1d41a07c7..9a978b1c9 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsUpdateImpl.java +++ b/src/main/java/org/apache/datasketches/quantiles/ItemsUpdateImpl.java @@ -28,7 +28,7 @@ private ItemsUpdateImpl() {} //important: newN might not equal n_ // This only increases the size and does not touch or move any data. - static void maybeGrowLevels(final ItemsSketch sketch, final long newN) { + static void maybeGrowLevels(final QuantilesItemsSketch sketch, final long newN) { // important: newN might not equal n_ final int k = sketch.getK(); final int numLevelsNeeded = ClassicUtil.computeNumLevelsNeeded(k, newN); @@ -54,7 +54,7 @@ static void inPlacePropagateCarry( final T[] sizeKBuf, final int sizeKStart, final T[] size2KBuf, final int size2KStart, final boolean doUpdateVersion, - final ItemsSketch sketch) { // else doMergeIntoVersion + final QuantilesItemsSketch sketch) { // else doMergeIntoVersion final Object[] levelsArr = sketch.getCombinedBuffer(); final long bitPattern = sketch.getBitPattern(); final int k = sketch.getK(); @@ -93,12 +93,12 @@ static void inPlacePropagateCarry( sketch.bitPattern_ = bitPattern + (1L << startingLevel); } - //note: this version refers to the ItemsSketch.rand + //note: this version refers to the QuantilesItemsSketch.rand private static void zipSize2KBuffer( final Object[] bufA, final int startA, // input final Object[] bufC, final int startC, // output final int k) { - final int randomOffset = ItemsSketch.rand.nextBoolean() ? 1 : 0; + final int randomOffset = QuantilesItemsSketch.rand.nextBoolean() ? 1 : 0; final int limC = startC + k; for (int a = startA + randomOffset, c = startC; c < limC; a += 2, c++) { bufC[c] = bufA[a]; diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsUtil.java b/src/main/java/org/apache/datasketches/quantiles/ItemsUtil.java index 81a0654f5..7ae7cec2f 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsUtil.java +++ b/src/main/java/org/apache/datasketches/quantiles/ItemsUtil.java @@ -58,7 +58,7 @@ static void checkItemsSerVer(final int serVer) { * @param sketch the given quantiles sketch */ @SuppressWarnings("unchecked") - static void processFullBaseBuffer(final ItemsSketch sketch) { + static void processFullBaseBuffer(final QuantilesItemsSketch sketch) { final int bbCount = sketch.getBaseBufferCount(); final long n = sketch.getN(); assert bbCount == (2 * sketch.getK()); // internal consistency check @@ -81,7 +81,7 @@ static void processFullBaseBuffer(final ItemsSketch sketch) { } static String toString(final boolean withLevels, final boolean withLevelsAndItems, - final ItemsSketch sk) { + final QuantilesItemsSketch sk) { final StringBuilder sb = new StringBuilder(); final String thisSimpleName = sk.getClass().getSimpleName(); final int bbCount = sk.getBaseBufferCount(); @@ -128,7 +128,7 @@ static String toString(final boolean withLevels, final boolean withLevelsAnd return sb.toString(); } - private static String outputLevels(final ItemsSketch sk) { + private static String outputLevels(final QuantilesItemsSketch sk) { final String name = sk.getClass().getSimpleName(); final int k = sk.getK(); final long n = sk.getN(); @@ -151,7 +151,7 @@ private static String outputLevels(final ItemsSketch sk) { return sb.toString(); } - private static String outputDataDetail(final ItemsSketch sk) { + private static String outputDataDetail(final QuantilesItemsSketch sk) { final String name = sk.getClass().getSimpleName(); final int k = sk.getK(); final long n = sk.getN(); diff --git a/src/main/java/org/apache/datasketches/quantiles/PreambleUtil.java b/src/main/java/org/apache/datasketches/quantiles/PreambleUtil.java index fdaa5bc19..1ba160c41 100644 --- a/src/main/java/org/apache/datasketches/quantiles/PreambleUtil.java +++ b/src/main/java/org/apache/datasketches/quantiles/PreambleUtil.java @@ -44,12 +44,12 @@ * The multi-byte primitives are stored in native byte order. * The single byte fields are treated as unsigned.

    * - *

    An empty ItemsSketch, on-heap DoublesSketch or compact off-heap DoublesSketch only require 8 - * bytes. An off-heap UpdateDoublesSketch and all non-empty sketches require at least 16 bytes of + *

    An empty QuantilesItemsSketch, on-heap QuantilesDoublesSketch or compact off-heap QuantilesDoublesSketch only require 8 + * bytes. An off-heap UpdatableQuantilesDoublesSketch and all non-empty sketches require at least 16 bytes of * preamble.

    * *
    {@code
    - * Long || Start Byte Adr: Common for both DoublesSketch and ItemsSketch
    + * Long || Start Byte Adr: Common for both QuantilesDoublesSketch and QuantilesItemsSketch
      * Adr:
      *      ||    7   |    6   |    5   |    4   |    3   |    2   |    1   |     0          |
      *  0   ||------unused-----|--------K--------|  Flags | FamID  | SerVer | Preamble_Longs |
    @@ -57,8 +57,8 @@
      *      ||   15   |   14   |   13   |   12   |   11   |   10   |    9   |     8          |
      *  1   ||-----------------------------------N_LONG--------------------------------------|
      *
    - *  Applies only to DoublesSketch:
    - *  (ItemsSketch has elements in the same order, but size depends on sizeOf(T)
    + *  Applies only to QuantilesDoublesSketch:
    + *  (QuantilesItemsSketch has elements in the same order, but size depends on sizeOf(T)
      *
      *      ||   23   |   22   |   21   |   20   |   19   |   18   |   17   |    16          |
      *  2   ||---------------------------START OF DATA, MIN_DOUBLE---------------------------|
    @@ -86,9 +86,9 @@ private PreambleUtil() {}
       static final int N_LONG                     = 8;  //to 15
     
       //After Preamble:
    -  static final int MIN_DOUBLE                 = 16; //to 23 (Only for DoublesSketch)
    -  static final int MAX_DOUBLE                 = 24; //to 31 (Only for DoublesSketch)
    -  static final int COMBINED_BUFFER            = 32; //to 39 (Only for DoublesSketch)
    +  static final int MIN_DOUBLE                 = 16; //to 23 (Only for QuantilesDoublesSketch)
    +  static final int MAX_DOUBLE                 = 24; //to 31 (Only for QuantilesDoublesSketch)
    +  static final int COMBINED_BUFFER            = 32; //to 39 (Only for QuantilesDoublesSketch)
     
       // flag bit masks
       static final int RESERVED_FLAG_MASK         = 1;
    @@ -110,7 +110,7 @@ private PreambleUtil() {}
        * Used primarily in testing.
        *
        * @param byteArr the given byte array.
    -   * @param isDoublesSketch flag to indicate that the byte array represents DoublesSketch
    +   * @param isDoublesSketch flag to indicate that the byte array represents QuantilesDoublesSketch
        * to output min and max quantiles in the summary
        * @return the summary string.
        */
    @@ -121,11 +121,11 @@ static String toString(final byte[] byteArr, final boolean isDoublesSketch) {
     
       /**
        * Returns a human readable string summary of the Preamble of the given MemorySegment. If this MemorySegment
    -   * image is from a DoublesSketch, the MinQuantile and MaxQuantile will also be output.
    +   * image is from a QuantilesDoublesSketch, the MinQuantile and MaxQuantile will also be output.
        * Used primarily in testing.
        *
        * @param seg the given MemorySegment
    -   * @param isDoublesSketch flag to indicate that the byte array represents DoublesSketch
    +   * @param isDoublesSketch flag to indicate that the byte array represents QuantilesDoublesSketch
        * to output min and max quantiles in the summary
        * @return the summary string.
        */
    diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketch.java
    similarity index 93%
    rename from src/main/java/org/apache/datasketches/quantiles/DoublesSketch.java
    rename to src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketch.java
    index e14d5301e..85bf957d7 100644
    --- a/src/main/java/org/apache/datasketches/quantiles/DoublesSketch.java
    +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketch.java
    @@ -19,10 +19,10 @@
     
     package org.apache.datasketches.quantiles;
     
    -import static java.lang.foreign.ValueLayout.JAVA_BYTE;
     import static java.lang.Math.max;
     import static java.lang.Math.min;
     import static java.lang.System.arraycopy;
    +import static java.lang.foreign.ValueLayout.JAVA_BYTE;
     import static org.apache.datasketches.common.Util.ceilingPowerOf2;
     import static org.apache.datasketches.quantiles.ClassicUtil.MAX_PRELONGS;
     import static org.apache.datasketches.quantiles.ClassicUtil.MIN_K;
    @@ -44,7 +44,7 @@
     import org.apache.datasketches.quantilescommon.QuantileSearchCriteria;
     import org.apache.datasketches.quantilescommon.QuantilesAPI;
     import org.apache.datasketches.quantilescommon.QuantilesDoublesAPI;
    -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator;
    +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI;
     
     /**
      * This is an implementation of the Low Discrepancy Mergeable Quantiles Sketch, using doubles,
    @@ -59,7 +59,7 @@
      * a confidence of about 99%.

    * *
    -Table Guide for DoublesSketch Size in Bytes and Approximate Error:
    +Table Guide for QuantilesDoublesSketch Size in Bytes and Approximate Error:
               K => |      16      32      64     128     256     512   1,024
         ~ Error => | 12.145%  6.359%  3.317%  1.725%  0.894%  0.463%  0.239%
                  N | Size in Bytes ->
    @@ -101,7 +101,7 @@
      *
      * @see QuantilesAPI
      */
    -public abstract class DoublesSketch implements QuantilesDoublesAPI, MemorySegmentStatus {
    +public abstract class QuantilesDoublesSketch implements QuantilesDoublesAPI, MemorySegmentStatus {
     
       /**
        * Setting the seed makes the results of the sketch deterministic if the input quantiles are
    @@ -120,21 +120,21 @@ public abstract class DoublesSketch implements QuantilesDoublesAPI, MemorySegmen
        */
       DoublesSketchSortedView doublesSV = null;
     
    -  DoublesSketch(final int k) {
    +  QuantilesDoublesSketch(final int k) {
         checkK(k);
         k_ = k;
       }
     
       synchronized static void setRandom(final long seed) {
    -    DoublesSketch.rand = new Random(seed);
    +    QuantilesDoublesSketch.rand = new Random(seed);
       }
     
       /**
        * Returns a new builder
        * @return a new builder
        */
    -  public static final DoublesSketchBuilder builder() {
    -    return new DoublesSketchBuilder();
    +  public static final QuantilesDoublesSketchBuilder builder() {
    +    return new QuantilesDoublesSketchBuilder();
       }
     
       /**
    @@ -143,7 +143,7 @@ public static final DoublesSketchBuilder builder() {
        * @param srcSeg a MemorySegment image of a Sketch.
        * @return a heap-based Sketch based on the given MemorySegment
        */
    -  public static DoublesSketch heapify(final MemorySegment srcSeg) {
    +  public static QuantilesDoublesSketch heapify(final MemorySegment srcSeg) {
         if (checkIsMemorySegmentCompact(srcSeg)) {
           return HeapCompactDoublesSketch.heapifyInstance(srcSeg);
         }
    @@ -151,12 +151,12 @@ public static DoublesSketch heapify(final MemorySegment srcSeg) {
       }
     
       /**
    -   * Wrap this sketch around the given MemorySegment image of a compact, read-only DoublesSketch.
    +   * Wrap this sketch around the given MemorySegment image of a compact, read-only QuantilesDoublesSketch.
        *
    -   * @param srcSeg the given MemorySegment image of a compact, read-only DoublesSketch.
    +   * @param srcSeg the given MemorySegment image of a compact, read-only QuantilesDoublesSketch.
        * @return a compact, read-only sketch that wraps the given MemorySegment.
        */
    -  public static DoublesSketch wrap(final MemorySegment srcSeg) {
    +  public static QuantilesDoublesSketch wrap(final MemorySegment srcSeg) {
         if (!checkIsMemorySegmentCompact(srcSeg)) {
           throw new SketchesArgumentException(
               "MemorySegment sketch image must be in compact form. "
    @@ -166,9 +166,9 @@ public static DoublesSketch wrap(final MemorySegment srcSeg) {
       }
     
       /**
    -   * Wrap this sketch around the given MemorySegment image of an updatable DoublesSketch.
    +   * Wrap this sketch around the given MemorySegment image of an updatable QuantilesDoublesSketch.
        *
    -   * 

    The given MemorySegment must be writable and it must contain a UpdateDoublesSketch. + *

    The given MemorySegment must be writable and it must contain a UpdatableQuantilesDoublesSketch. * The sketch will be updated and managed totally within the MemorySegment. If the given source * MemorySegment is created off-heap, then all the management of the sketch's internal data will be off-heap as well.

    * @@ -176,10 +176,10 @@ public static DoublesSketch wrap(final MemorySegment srcSeg) { * will request more capacity using the {@link MemorySegmentRequest MemorySegmentRequest} interface. The default of this interface will * return a new MemorySegment on the heap.

    * - * @param srcSeg the given MemorySegment image of an UpdateDoublesSketch. + * @param srcSeg the given MemorySegment image of an UpdatableQuantilesDoublesSketch. * @return an updatable sketch that wraps the given MemorySegment. */ - public static DoublesSketch writableWrap(final MemorySegment srcSeg) { + public static QuantilesDoublesSketch writableWrap(final MemorySegment srcSeg) { if (checkIsMemorySegmentCompact(srcSeg)) { throw new SketchesArgumentException( "MemorySegment sketch image must be in updatable form. " @@ -189,9 +189,9 @@ public static DoublesSketch writableWrap(final MemorySegment srcSeg) { } /** - * Wrap this sketch around the given MemorySegment image of an updatable DoublesSketch. + * Wrap this sketch around the given MemorySegment image of an updatable QuantilesDoublesSketch. * - *

    The given MemorySegment must be writable and it must contain a UpdateDoublesSketch. + *

    The given MemorySegment must be writable and it must contain a UpdatableQuantilesDoublesSketch. * The sketch will be updated and managed totally within the MemorySegment. If the given source * MemorySegment is created off-heap, then all the management of the sketch's internal data will be off-heap as well.

    * @@ -200,12 +200,12 @@ public static DoublesSketch writableWrap(final MemorySegment srcSeg) { * return a new MemorySegment on the heap. It is up to the user to optionally extend this interface if more flexible * handling of requests for more capacity is required.

    * - * @param srcSeg the given MemorySegment image of a DoublesSketch. + * @param srcSeg the given MemorySegment image of a QuantilesDoublesSketch. * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand. * Otherwise, it can be null and the default MemorySegmentRequest will be used. * @return a sketch that wraps the given MemorySegment. */ - public static DoublesSketch writableWrap(final MemorySegment srcSeg, final MemorySegmentRequest mSegReq) { + public static QuantilesDoublesSketch writableWrap(final MemorySegment srcSeg, final MemorySegmentRequest mSegReq) { if (checkIsMemorySegmentCompact(srcSeg)) { throw new SketchesArgumentException("MemorySegment sketch image must be in updatable form."); } @@ -413,20 +413,20 @@ public String toString(final boolean withLevels, final boolean withLevelsAndItem } /** - * Returns a human readable string of the preamble of a byte array image of a DoublesSketch. + * Returns a human readable string of the preamble of a byte array image of a QuantilesDoublesSketch. * Used for debugging. * @param byteArr the given byte array - * @return a human readable string of the preamble of a byte array image of a DoublesSketch. + * @return a human readable string of the preamble of a byte array image of a QuantilesDoublesSketch. */ public static String toString(final byte[] byteArr) { return PreambleUtil.toString(byteArr, true); } /** - * Returns a human readable string of the preamble of a MemorySegment image of a DoublesSketch. + * Returns a human readable string of the preamble of a MemorySegment image of a QuantilesDoublesSketch. * Used for debugging. * @param seg the given MemorySegment - * @return a human readable string of the preamble of a MemorySegment image of a DoublesSketch. + * @return a human readable string of the preamble of a MemorySegment image of a QuantilesDoublesSketch. */ public static String toString(final MemorySegment seg) { return PreambleUtil.toString(seg, true); @@ -445,7 +445,7 @@ public static String toString(final MemorySegment seg) { * Otherwise, it can be null and the default MemorySegmentRequest will be used. * @return the new sketch. */ - public DoublesSketch downSample(final DoublesSketch srcSketch, final int smallerK, final MemorySegment dstSeg, + public QuantilesDoublesSketch downSample(final QuantilesDoublesSketch srcSketch, final int smallerK, final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { return downSampleInternal(srcSketch, smallerK, dstSeg, mSegReq); } @@ -464,7 +464,7 @@ public int getCurrentCompactSerializedSizeBytes() { } /** - * Returns the number of bytes a DoublesSketch would require to store in compact form + * Returns the number of bytes a QuantilesDoublesSketch would require to store in compact form * given k and n. The compact form is not updatable. * @param k the size configuration parameter for the sketch * @param n the number of quantiles input into the sketch @@ -544,8 +544,8 @@ public void putIntoMemorySegment(final MemorySegment dstSeg, final boolean compa } @Override - public QuantilesDoublesSketchIterator iterator() { - return new DoublesSketchIterator(this, getBitPattern()); + public QuantilesDoublesSketchIteratorAPI iterator() { + return new QuantilesDoublesSketchIterator(this, getBitPattern()); } @Override @@ -556,12 +556,12 @@ public QuantilesDoublesSketchIterator iterator() { /* * DoublesMergeImpl.downSamplingMergeInto requires the target sketch to implement update(), so * we ensure that the target is an UpdateSketch. The public API, on the other hand, just - * specifies a DoublesSketch. This lets us be more specific about the type without changing the + * specifies a QuantilesDoublesSketch. This lets us be more specific about the type without changing the * public API. */ - UpdateDoublesSketch downSampleInternal(final DoublesSketch srcSketch, final int smallerK, final MemorySegment dstSeg, + UpdatableQuantilesDoublesSketch downSampleInternal(final QuantilesDoublesSketch srcSketch, final int smallerK, final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { - final UpdateDoublesSketch newSketch = dstSeg == null + final UpdatableQuantilesDoublesSketch newSketch = dstSeg == null ? HeapUpdateDoublesSketch.newInstance(smallerK) : DirectUpdateDoublesSketch.newInstance(smallerK, dstSeg, mSegReq); if (srcSketch.isEmpty()) { return newSketch; } @@ -626,7 +626,7 @@ private DoublesSketchSortedView getSV() { final long[] svCumWeights = new long[numQuantiles]; final DoublesSketchAccessor sketchAccessor = DoublesSketchAccessor.wrap(this, false); - // Populate from DoublesSketch: + // Populate from QuantilesDoublesSketch: // copy over the "levels" and then the base buffer, all with appropriate weights populateFromDoublesSketch(getK(), totalN, getBitPattern(), sketchAccessor, svQuantiles, svCumWeights); diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesSketchBuilder.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketchBuilder.java similarity index 75% rename from src/main/java/org/apache/datasketches/quantiles/DoublesSketchBuilder.java rename to src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketchBuilder.java index ffb51a612..6155b5803 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesSketchBuilder.java +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketchBuilder.java @@ -27,21 +27,21 @@ import org.apache.datasketches.common.MemorySegmentRequest; /** - * For building a new quantiles DoublesSketch. + * For building a new quantiles QuantilesDoublesSketch. * * @author Lee Rhodes */ -public class DoublesSketchBuilder { +public class QuantilesDoublesSketchBuilder { private int bK = PreambleUtil.DEFAULT_K; /** - * Constructor for a new DoublesSketchBuilder. The default configuration is + * Constructor for a new QuantilesDoublesSketchBuilder. The default configuration is *
      *
    • k: 128. This produces a normalized rank error of about 1.7%
    • *
    • MemorySegment: null
    • *
    */ - public DoublesSketchBuilder() {} + public QuantilesDoublesSketchBuilder() {} /** * Sets the parameter k that determines the accuracy and size of the sketch. @@ -51,7 +51,7 @@ public DoublesSketchBuilder() {} * larger k to smaller k. * @return this builder */ - public DoublesSketchBuilder setK(final int k) { + public QuantilesDoublesSketchBuilder setK(final int k) { ClassicUtil.checkK(k); bK = k; return this; @@ -66,32 +66,32 @@ public int getK() { } /** - * Returns an UpdateDoublesSketch with the current configuration of this Builder. - * @return a UpdateDoublesSketch + * Returns an UpdatableQuantilesDoublesSketch with the current configuration of this Builder. + * @return a UpdatableQuantilesDoublesSketch */ - public UpdateDoublesSketch build() { + public UpdatableQuantilesDoublesSketch build() { return HeapUpdateDoublesSketch.newInstance(bK); } /** - * Returns a UpdateDoublesSketch with the current configuration of this builder + * Returns a UpdatableQuantilesDoublesSketch with the current configuration of this builder * and the specified backing destination MemorySegment store that can grow. * @param dstSeg destination MemorySegment for use by the sketch - * @return an UpdateDoublesSketch + * @return an UpdatableQuantilesDoublesSketch */ - public UpdateDoublesSketch build(final MemorySegment dstSeg) { + public UpdatableQuantilesDoublesSketch build(final MemorySegment dstSeg) { return this.build(dstSeg, null); } /** - * Returns a UpdateDoublesSketch with the current configuration of this builder + * Returns a UpdatableQuantilesDoublesSketch with the current configuration of this builder * and the specified backing destination MemorySegment store that can grow. * @param dstSeg destination MemorySegment for use by the sketch * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand. * Otherwise, it can be null and the default MemorySegmentRequest will be used. - * @return an UpdateDoublesSketch + * @return an UpdatableQuantilesDoublesSketch */ - public UpdateDoublesSketch build(final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { + public UpdatableQuantilesDoublesSketch build(final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { return DirectUpdateDoublesSketch.newInstance(bK, dstSeg, mSegReq); } diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesSketchIterator.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketchIterator.java similarity index 88% rename from src/main/java/org/apache/datasketches/quantiles/DoublesSketchIterator.java rename to src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketchIterator.java index 1d08c6377..5b1d9bfbb 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesSketchIterator.java +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesSketchIterator.java @@ -22,19 +22,19 @@ import java.util.Objects; import org.apache.datasketches.common.SketchesStateException; -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; /** - * Iterator over DoublesSketch. The order is not defined. + * Iterator over QuantilesDoublesSketch. The order is not defined. */ -public final class DoublesSketchIterator implements QuantilesDoublesSketchIterator { +public final class QuantilesDoublesSketchIterator implements QuantilesDoublesSketchIteratorAPI { private final DoublesSketchAccessor sketchAccessor; private long bitPattern; private int level; private long weight; private int index; - DoublesSketchIterator(final DoublesSketch sketch, final long bitPattern) { + QuantilesDoublesSketchIterator(final QuantilesDoublesSketch sketch, final long bitPattern) { Objects.requireNonNull(sketch, "sketch must not be null"); sketchAccessor = DoublesSketchAccessor.wrap(sketch, false); this.bitPattern = bitPattern; diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesUnion.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnion.java similarity index 71% rename from src/main/java/org/apache/datasketches/quantiles/DoublesUnion.java rename to src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnion.java index 0bc8dbcf4..707513c65 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesUnion.java +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnion.java @@ -25,60 +25,66 @@ import org.apache.datasketches.common.MemorySegmentStatus; /** - * The API for Union operations for quantiles DoublesSketches + * The API for Union operations for QuantilesDoublesSketches * * @author Lee Rhodes */ -public abstract class DoublesUnion implements MemorySegmentStatus { +public abstract class QuantilesDoublesUnion implements MemorySegmentStatus { + + /** + * No argument constructor. + */ + public QuantilesDoublesUnion() { } /** * Returns a new UnionBuilder * @return a new UnionBuilder */ - public static DoublesUnionBuilder builder() { - return new DoublesUnionBuilder(); + public static QuantilesDoublesUnionBuilder builder() { + return new QuantilesDoublesUnionBuilder(); } /** * Returns a Heap Union object that has been initialized with the data from the given sketch. - * @param sketch A DoublesSketch to be used as a source of data only and will not be modified. - * @return a DoublesUnion object + * @param sketch A QuantilesDoublesSketch to be used as a source of data only and will not be modified. + * @return a QuantilesDoublesUnion object */ - public static DoublesUnion heapify(final DoublesSketch sketch) { - return DoublesUnionImpl.heapifyInstance(sketch); + public static QuantilesDoublesUnion heapify(final QuantilesDoublesSketch sketch) { + return QuantilesDoublesUnionImpl.heapifyInstance(sketch); } /** * Returns a Heap Union object that has been initialized with the data from the given MemorySegment that contains an * image of a sketch. * - * @param srcSeg A MemorySegment image of a DoublesSketch to be used as a source of data and will not be modified. + * @param srcSeg A MemorySegment image of a QuantilesDoublesSketch to be used as a source of data and will not be modified. * @return a Union object */ - public static DoublesUnion heapify(final MemorySegment srcSeg) { - return DoublesUnionImpl.heapifyInstance(srcSeg); + public static QuantilesDoublesUnion heapify(final MemorySegment srcSeg) { + return QuantilesDoublesUnionImpl.heapifyInstance(srcSeg); } /** - * Returns an updatable Union object that wraps the given MemorySegment that contains an image of a DoublesSketch. + * Returns an updatable Union object that wraps the given MemorySegment that contains an image of a QuantilesDoublesSketch. * - * @param srcSeg A MemorySegment image of an updatable DoublesSketch to be used as the data structure for the union and will be modified. + * @param srcSeg A MemorySegment image of an updatable QuantilesDoublesSketch to be used as the data structure for the union + * and will be modified. * @return a Union object */ - public static DoublesUnion wrap(final MemorySegment srcSeg) { - return DoublesUnionImpl.wrapInstance(srcSeg, null); + public static QuantilesDoublesUnion wrap(final MemorySegment srcSeg) { + return QuantilesDoublesUnionImpl.wrapInstance(srcSeg, null); } /** - * Returns an updatable Union object that wraps the given MemorySegment that contains an image of a DoublesSketch. + * Returns an updatable Union object that wraps the given MemorySegment that contains an image of a QuantilesDoublesSketch. * * @param srcSeg A MemorySegment sketch to be used as the data structure for the union and will be modified. * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand. * Otherwise, it can be null and the default MemorySegmentRequest will be used. * @return a Union object */ - public static DoublesUnion wrap(final MemorySegment srcSeg, final MemorySegmentRequest mSegReq) { - return DoublesUnionImpl.wrapInstance(srcSeg, mSegReq); + public static QuantilesDoublesUnion wrap(final MemorySegment srcSeg, final MemorySegmentRequest mSegReq) { + return QuantilesDoublesUnionImpl.wrapInstance(srcSeg, mSegReq); } @Override @@ -121,11 +127,11 @@ public static DoublesUnion wrap(final MemorySegment srcSeg, final MemorySegmentR * * @param sketchIn the sketch to be merged into this one. */ - public abstract void union(DoublesSketch sketchIn); + public abstract void union(QuantilesDoublesSketch sketchIn); /** * Iterative union operation, which means this method can be repeatedly called. - * Merges the given MemorySegment image of a DoublesSketch into this union object. + * Merges the given MemorySegment image of a QuantilesDoublesSketch into this union object. * The given MemorySegment object is not modified and a link to it is not retained. * It is required that the ratio of the two K's be a power of 2. * This is easily satisfied if each of the K's are already a power of 2. @@ -146,16 +152,16 @@ public static DoublesUnion wrap(final MemorySegment srcSeg, final MemorySegmentR public abstract void update(double dataItem); /** - * Gets the result of this Union as an UpdateDoublesSketch, which enables further update + * Gets the result of this Union as an UpdatableQuantilesDoublesSketch, which enables further update * operations on the resulting sketch. The Union state has not been changed, which allows * further union operations. * * @return the result of this Union operation */ - public abstract UpdateDoublesSketch getResult(); + public abstract UpdatableQuantilesDoublesSketch getResult(); /** - * Places the result of this Union into the provided MemorySegment as an UpdateDoublesSketch, + * Places the result of this Union into the provided MemorySegment as an UpdatableQuantilesDoublesSketch, * which enables further update operations on the resulting sketch. The Union state has not * been changed, which allows further union operations. * @@ -164,15 +170,15 @@ public static DoublesUnion wrap(final MemorySegment srcSeg, final MemorySegmentR * Otherwise, it can be null and the default MemorySegmentRequest will be used. * @return the result of this Union operation */ - public abstract UpdateDoublesSketch getResult(MemorySegment dstSeg, MemorySegmentRequest mSegReq); + public abstract UpdatableQuantilesDoublesSketch getResult(MemorySegment dstSeg, MemorySegmentRequest mSegReq); /** - * Gets the result of this Union as an UpdateDoublesSketch, which enables further update + * Gets the result of this Union as an UpdatableQuantilesDoublesSketch, which enables further update * operations on the resulting sketch. The Union is reset to the virgin state. * * @return the result of this Union operation and reset. */ - public abstract UpdateDoublesSketch getResultAndReset(); + public abstract UpdatableQuantilesDoublesSketch getResultAndReset(); /** * Resets this Union to a virgin state. @@ -180,7 +186,7 @@ public static DoublesUnion wrap(final MemorySegment srcSeg, final MemorySegmentR public abstract void reset(); /** - * Serialize this union to a byte array. Result is an UpdateDoublesSketch, serialized in an + * Serialize this union to a byte array. Result is an UpdatableQuantilesDoublesSketch, serialized in an * unordered, non-compact form. The resulting byte[] can be heapified or wrapped as either a * sketch or a union. * diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesUnionBuilder.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnionBuilder.java similarity index 80% rename from src/main/java/org/apache/datasketches/quantiles/DoublesUnionBuilder.java rename to src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnionBuilder.java index e788c1a7a..555b2660a 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesUnionBuilder.java +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnionBuilder.java @@ -24,20 +24,20 @@ import org.apache.datasketches.common.MemorySegmentRequest; /** - * For building a new DoublesSketch Union operation. + * For building a new QuantilesDoublesSketch Union operation. * * @author Lee Rhodes */ -public class DoublesUnionBuilder { +public class QuantilesDoublesUnionBuilder { private int bMaxK = PreambleUtil.DEFAULT_K; /** - * Constructor for a new DoublesUnionBuilder. The default configuration is + * Constructor for a new QuantilesDoublesUnionBuilder. The default configuration is *
      *
    • k: 128. This produces a normalized rank error of about 1.7%
    • *
    */ - public DoublesUnionBuilder() {} + public QuantilesDoublesUnionBuilder() {} /** * Sets the parameter masK that determines the maximum size of the sketch that @@ -48,7 +48,7 @@ public DoublesUnionBuilder() {} * different k. * @return this builder */ - public DoublesUnionBuilder setMaxK(final int maxK) { + public QuantilesDoublesUnionBuilder setMaxK(final int maxK) { ClassicUtil.checkK(maxK); bMaxK = maxK; return this; @@ -66,8 +66,8 @@ public int getMaxK() { * Returns a new empty Union object with the current configuration of this Builder. * @return a Union object */ - public DoublesUnion build() { - return DoublesUnionImpl.heapInstance(bMaxK); + public QuantilesDoublesUnion build() { + return QuantilesDoublesUnionImpl.heapInstance(bMaxK); } /** @@ -78,8 +78,8 @@ public DoublesUnion build() { * Otherwise, it can be null and the default MemorySegmentRequest will be used. * @return a Union object */ - public DoublesUnion build(final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { - return DoublesUnionImpl.directInstance(bMaxK, dstSeg, mSegReq); + public QuantilesDoublesUnion build(final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { + return QuantilesDoublesUnionImpl.directInstance(bMaxK, dstSeg, mSegReq); } } diff --git a/src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnionImpl.java similarity index 75% rename from src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java rename to src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnionImpl.java index 0c7a4468f..8cd4552a3 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesDoublesUnionImpl.java @@ -36,28 +36,28 @@ * @author Lee Rhodes * @author Kevin Lang */ -final class DoublesUnionImpl extends DoublesUnion { +final class QuantilesDoublesUnionImpl extends QuantilesDoublesUnion { int maxK_; - UpdateDoublesSketch gadget_ = null; + UpdatableQuantilesDoublesSketch gadget_ = null; - private DoublesUnionImpl(final int maxK) { + private QuantilesDoublesUnionImpl(final int maxK) { maxK_ = maxK; } /** - * Returns a empty DoublesUnion object on the heap. + * Returns a empty QuantilesDoublesUnion object on the heap. * @param maxK determines the accuracy and size of the union and is a maximum. * The effective k can be smaller due to unions with smaller k sketches. * It is recommended that maxK be a power of 2 to enable unioning of sketches with * different k. - * @return a new DoublesUnionImpl on the Java heap + * @return a new QuantilesDoublesUnionImpl on the Java heap */ - static DoublesUnionImpl heapInstance(final int maxK) { - return new DoublesUnionImpl(maxK); + static QuantilesDoublesUnionImpl heapInstance(final int maxK) { + return new QuantilesDoublesUnionImpl(maxK); } /** - * Returns a empty DoublesUnion object that uses the given MemorySegment for its internal sketch gadget + * Returns a empty QuantilesDoublesUnion object that uses the given MemorySegment for its internal sketch gadget * and will be initialized to the empty state. * * @param maxK determines the accuracy and size of the union and is a maximum. @@ -67,70 +67,71 @@ static DoublesUnionImpl heapInstance(final int maxK) { * @param dstSeg the MemorySegment to be used by the internal sketch and must not be null. * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand. * Otherwise, it can be null and the default MemorySegmentRequest will be used. - * @return a DoublesUnion object + * @return a QuantilesDoublesUnion object */ - static DoublesUnionImpl directInstance(final int maxK, final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { + static QuantilesDoublesUnionImpl directInstance(final int maxK, final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { Objects.requireNonNull(dstSeg); final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.newInstance(maxK, dstSeg, mSegReq); - final DoublesUnionImpl union = new DoublesUnionImpl(maxK); + final QuantilesDoublesUnionImpl union = new QuantilesDoublesUnionImpl(maxK); union.maxK_ = maxK; union.gadget_ = sketch; return union; } /** - * Returns a Heap DoublesUnion object that has been initialized with the data from the given + * Returns a Heap QuantilesDoublesUnion object that has been initialized with the data from the given * sketch. * - * @param sketch A DoublesSketch to be used as a source of data only and will not be modified. - * @return a DoublesUnion object + * @param sketch A QuantilesDoublesSketch to be used as a source of data only and will not be modified. + * @return a QuantilesDoublesUnion object */ - static DoublesUnionImpl heapifyInstance(final DoublesSketch sketch) { + static QuantilesDoublesUnionImpl heapifyInstance(final QuantilesDoublesSketch sketch) { Objects.requireNonNull(sketch); final int k = sketch.getK(); - final DoublesUnionImpl union = new DoublesUnionImpl(k); + final QuantilesDoublesUnionImpl union = new QuantilesDoublesUnionImpl(k); union.maxK_ = k; union.gadget_ = copyToHeap(sketch); return union; } /** - * Returns a Heap DoublesUnion object that has been initialized with the data from the given - * MemorySegment image of a DoublesSketch. The srcSeg object will not be modified and a reference to + * Returns a Heap QuantilesDoublesUnion object that has been initialized with the data from the given + * MemorySegment image of a QuantilesDoublesSketch. The srcSeg object will not be modified and a reference to * it is not retained. The maxK of the resulting union will be that obtained from * the sketch MemorySegment image. * - * @param srcSeg an optionally read-only MemorySegment image of a DoublesSketch - * @return a DoublesUnion object + * @param srcSeg an optionally read-only MemorySegment image of a QuantilesDoublesSketch + * @return a QuantilesDoublesUnion object */ - static DoublesUnionImpl heapifyInstance(final MemorySegment srcSeg) { + static QuantilesDoublesUnionImpl heapifyInstance(final MemorySegment srcSeg) { Objects.requireNonNull(srcSeg); final HeapUpdateDoublesSketch sketch = HeapUpdateDoublesSketch.heapifyInstance(srcSeg); - final DoublesUnionImpl union = new DoublesUnionImpl(sketch.getK()); + final QuantilesDoublesUnionImpl union = new QuantilesDoublesUnionImpl(sketch.getK()); union.gadget_ = sketch; return union; } /** - * Returns an Union object that wraps the data of the given MemorySegment image of a UpdateDoublesSketch. + * Returns an Union object that wraps the data of the given MemorySegment image of a UpdatableQuantilesDoublesSketch. * The data of the Union will remain in the MemorySegment. * - * @param srcSeg A MemorySegment image of an updatable DoublesSketch to be used as the data structure for the union and will be modified. + * @param srcSeg A MemorySegment image of an updatable QuantilesDoublesSketch to be used as the data structure for the union + * and will be modified. * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand. * Otherwise, it can be null and the default MemorySegmentRequest will be used. * @return a Union object */ - static DoublesUnionImpl wrapInstance(final MemorySegment srcSeg, final MemorySegmentRequest mSegReq) { + static QuantilesDoublesUnionImpl wrapInstance(final MemorySegment srcSeg, final MemorySegmentRequest mSegReq) { Objects.requireNonNull(srcSeg); if (srcSeg.isReadOnly()) { throw new SketchesReadOnlyException("Cannot create a Union with a Read Only MemorySegment."); } final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.wrapInstance(srcSeg, mSegReq); - final DoublesUnionImpl union = new DoublesUnionImpl(sketch.getK()); + final QuantilesDoublesUnionImpl union = new QuantilesDoublesUnionImpl(sketch.getK()); union.gadget_ = sketch; return union; } @Override - public void union(final DoublesSketch sketchIn) { + public void union(final QuantilesDoublesSketch sketchIn) { Objects.requireNonNull(sketchIn); gadget_ = updateLogic(maxK_, gadget_, sketchIn); gadget_.doublesSV = null; @@ -140,9 +141,9 @@ public void union(final DoublesSketch sketchIn) { public void union(final MemorySegment seg) { Objects.requireNonNull(seg); if (checkIsMemorySegmentCompact(seg)) { - gadget_ = updateLogic(maxK_, gadget_, DoublesSketch.wrap(seg)); + gadget_ = updateLogic(maxK_, gadget_, QuantilesDoublesSketch.wrap(seg)); } else { - gadget_ = updateLogic(maxK_, gadget_, DoublesSketch.writableWrap(seg, null)); + gadget_ = updateLogic(maxK_, gadget_, QuantilesDoublesSketch.writableWrap(seg, null)); } gadget_.doublesSV = null; @@ -160,13 +161,13 @@ public void update(final double dataItem) { @Override public byte[] toByteArray() { if (gadget_ == null) { - return DoublesSketch.builder().setK(maxK_).build().toByteArray(); + return QuantilesDoublesSketch.builder().setK(maxK_).build().toByteArray(); } return gadget_.toByteArray(); } @Override - public UpdateDoublesSketch getResult() { + public UpdatableQuantilesDoublesSketch getResult() { if (gadget_ == null) { return HeapUpdateDoublesSketch.newInstance(maxK_); } @@ -174,10 +175,10 @@ public UpdateDoublesSketch getResult() { } @Override - public UpdateDoublesSketch getResult(final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { + public UpdatableQuantilesDoublesSketch getResult(final MemorySegment dstSeg, final MemorySegmentRequest mSegReq) { final long segCapBytes = dstSeg.byteSize(); if (gadget_ == null) { - if (segCapBytes < DoublesSketch.getUpdatableStorageBytes(0, 0)) { + if (segCapBytes < QuantilesDoublesSketch.getUpdatableStorageBytes(0, 0)) { throw new SketchesArgumentException("Insufficient capacity for result: " + segCapBytes); } return DirectUpdateDoublesSketch.newInstance(maxK_, dstSeg, mSegReq); @@ -188,9 +189,9 @@ public UpdateDoublesSketch getResult(final MemorySegment dstSeg, final MemorySeg } @Override - public UpdateDoublesSketch getResultAndReset() { + public UpdatableQuantilesDoublesSketch getResultAndReset() { if (gadget_ == null) { return null; } //Intentionally return null here for speed. - final UpdateDoublesSketch ds = gadget_.getSketchAndReset(); + final UpdatableQuantilesDoublesSketch ds = gadget_.getSketchAndReset(); gadget_ = null; return ds; } @@ -252,7 +253,7 @@ public String toString(final boolean sketchSummary, final boolean dataDetail) { } //@formatter:off - static UpdateDoublesSketch updateLogic(final int myMaxK, final UpdateDoublesSketch myQS, final DoublesSketch other) { + static UpdatableQuantilesDoublesSketch updateLogic(final int myMaxK, final UpdatableQuantilesDoublesSketch myQS, final QuantilesDoublesSketch other) { int sw1 = ((myQS == null) ? 0 : myQS.isEmpty() ? 4 : 8); sw1 |= ((other == null) ? 0 : other.isEmpty() ? 1 : 2); int outCase = 0; //0=null, 1=NOOP, 2=copy, 3=merge @@ -269,7 +270,7 @@ static UpdateDoublesSketch updateLogic(final int myMaxK, final UpdateDoublesSket case 10: outCase = 3; break; //myQS = valid, other = valid; merge default: break; //This cannot happen } - UpdateDoublesSketch ret = null; + UpdatableQuantilesDoublesSketch ret = null; switch (outCase) { case 0: break; //return null @@ -313,12 +314,12 @@ static UpdateDoublesSketch updateLogic(final int myMaxK, final UpdateDoublesSket ret = DoublesUtil.copyToHeap(other); } } else { //Not Empty: myQS has data, downsample to tmp - final UpdateDoublesSketch tmp = DoublesSketch.builder().setK(other.getK()).build(); + final UpdatableQuantilesDoublesSketch tmp = QuantilesDoublesSketch.builder().setK(other.getK()).build(); DoublesMergeImpl.downSamplingMergeInto(myQS, tmp); //myData -> tmp ret = (myQS.hasMemorySegment()) - ? DoublesSketch.builder().setK(other.getK()).build(myQS.getMemorySegment()) - : DoublesSketch.builder().setK(other.getK()).build(); + ? QuantilesDoublesSketch.builder().setK(other.getK()).build(myQS.getMemorySegment()) + : QuantilesDoublesSketch.builder().setK(other.getK()).build(); DoublesMergeImpl.mergeInto(tmp, ret); DoublesMergeImpl.mergeInto(other, ret); diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesItemsSketch.java similarity index 92% rename from src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java rename to src/main/java/org/apache/datasketches/quantiles/QuantilesItemsSketch.java index 9dc161ce7..17c94940d 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesItemsSketch.java @@ -19,6 +19,8 @@ package org.apache.datasketches.quantiles; +import static java.lang.Math.max; +import static java.lang.Math.min; import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static org.apache.datasketches.quantiles.ClassicUtil.MIN_K; import static org.apache.datasketches.quantiles.ClassicUtil.checkFamilyID; @@ -35,8 +37,6 @@ import static org.apache.datasketches.quantiles.PreambleUtil.extractN; import static org.apache.datasketches.quantiles.PreambleUtil.extractPreLongs; import static org.apache.datasketches.quantiles.PreambleUtil.extractSerVer; -import static java.lang.Math.max; -import static java.lang.Math.min; import java.lang.foreign.MemorySegment; import java.lang.reflect.Array; @@ -53,7 +53,7 @@ import org.apache.datasketches.quantilescommon.QuantileSearchCriteria; import org.apache.datasketches.quantilescommon.QuantilesAPI; import org.apache.datasketches.quantilescommon.QuantilesGenericAPI; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; /** * This is an implementation of the Low Discrepancy Mergeable Quantiles Sketch, using generic items, @@ -67,14 +67,14 @@ * from the hypothetically sorted array of input quantiles at normalized ranks of 0.483 and 0.517, with * a confidence of about 99%.

    * - *

    The size of an ItemsSketch is very dependent on the size of the generic Items input into the sketch, - * so there is no comparable size table as there is for the DoublesSketch.

    + *

    The size of an QuantilesItemsSketch is very dependent on the size of the generic Items input into the sketch, + * so there is no comparable size table as there is for the QuantilesDoublesSketch.

    * * @see QuantilesAPI * * @param The sketch item data type. */ -public final class ItemsSketch implements QuantilesGenericAPI { +public final class QuantilesItemsSketch implements QuantilesGenericAPI { final Class clazz; private final Comparator comparator_; final int k_; @@ -126,7 +126,7 @@ public final class ItemsSketch implements QuantilesGenericAPI { //**Constructors** - private ItemsSketch( + private QuantilesItemsSketch( final int k, final Class clazz, final Comparator comparator) { @@ -139,20 +139,20 @@ private ItemsSketch( } /** - * Obtains a new instance of an ItemsSketch using the DEFAULT_K. + * Obtains a new instance of an QuantilesItemsSketch using the DEFAULT_K. * @param The sketch item data type. * @param clazz the given class of T. * @param comparator to compare items. * @return an ItemSketch<T>. */ - public static ItemsSketch getInstance( + public static QuantilesItemsSketch getInstance( final Class clazz, final Comparator comparator) { return getInstance(clazz, PreambleUtil.DEFAULT_K, comparator); } /** - * Obtains a new instance of an ItemsSketch using the given k. + * Obtains a new instance of an QuantilesItemsSketch using the given k. * @param The sketch item data type. * @param clazz the given class of T. * @param k Parameter that controls space usage of sketch and accuracy of estimates. @@ -160,11 +160,11 @@ public static ItemsSketch getInstance( * @param comparator to compare items. * @return an ItemSketch<T>. */ - public static ItemsSketch getInstance( + public static QuantilesItemsSketch getInstance( final Class clazz, final int k, final Comparator comparator) { - final ItemsSketch qs = new ItemsSketch<>(k, clazz, comparator); + final QuantilesItemsSketch qs = new QuantilesItemsSketch<>(k, clazz, comparator); final int bufAlloc = 2 * Math.min(MIN_K, k); //the min is important qs.n_ = 0; qs.combinedBufferItemCapacity_ = bufAlloc; @@ -177,15 +177,15 @@ public static ItemsSketch getInstance( } /** - * Heapifies the given srcSeg, which must be a MemorySegment image of a ItemsSketch. + * Heapifies the given srcSeg, which must be a MemorySegment image of a QuantilesItemsSketch. * @param The sketch item data type. * @param clazz the given class of T. * @param srcSeg a MemorySegment image of a sketch generated from this class. * @param comparator to compare items. * @param serDe an instance of ArrayOfItemsSerDe. - * @return a ItemsSketch<T> on the Java heap. + * @return a QuantilesItemsSketch<T> on the Java heap. */ - public static ItemsSketch heapify( + public static QuantilesItemsSketch heapify( final Class clazz, final MemorySegment srcSeg, final Comparator comparator, @@ -208,7 +208,7 @@ public static ItemsSketch heapify( final boolean empty = checkPreLongsFlagsCap(preambleLongs, flags, segCapBytes); checkFamilyID(familyID); - final ItemsSketch sk = getInstance(clazz, k, comparator); //checks k + final QuantilesItemsSketch sk = getInstance(clazz, k, comparator); //checks k if (empty) { return sk; } //Not empty, must have valid preamble + min, max @@ -239,8 +239,8 @@ public static ItemsSketch heapify( * @param sketch the given sketch. * @return a copy of the given sketch. */ - static ItemsSketch copy(final ItemsSketch sketch) { - final ItemsSketch qsCopy = ItemsSketch.getInstance(sketch.clazz, sketch.k_, sketch.comparator_); + static QuantilesItemsSketch copy(final QuantilesItemsSketch sketch) { + final QuantilesItemsSketch qsCopy = QuantilesItemsSketch.getInstance(sketch.clazz, sketch.k_, sketch.comparator_); qsCopy.n_ = sketch.n_; qsCopy.minItem_ = sketch.isEmpty() ? null : sketch.getMinItem(); qsCopy.maxItem_ = sketch.isEmpty() ? null : sketch.getMaxItem(); @@ -362,8 +362,8 @@ public double[] getRanks(final T[] quantiles, final QuantileSearchCriteria searc } @Override - public QuantilesGenericSketchIterator iterator() { - return new ItemsSketchIterator<>(this, bitPattern_); + public QuantilesGenericSketchIteratorAPI iterator() { + return new QuantilesItemsSketchIterator<>(this, bitPattern_); } @Override @@ -474,20 +474,20 @@ public String toString(final boolean withLevels, final boolean withLevelsAndItem } /** - * Returns a human readable string of the preamble of a byte array image of an ItemsSketch. + * Returns a human readable string of the preamble of a byte array image of an QuantilesItemsSketch. * Used for debugging. * @param byteArr the given byte array - * @return a human readable string of the preamble of a byte array image of an ItemsSketch. + * @return a human readable string of the preamble of a byte array image of an QuantilesItemsSketch. */ public static String toString(final byte[] byteArr) { return PreambleUtil.toString(byteArr, false); } /** - * Returns a human readable string of the preamble of a MemorySegment image of an ItemsSketch. + * Returns a human readable string of the preamble of a MemorySegment image of an QuantilesItemsSketch. * Used for debugging. * @param seg the given MemorySegment - * @return a human readable string of the preamble of a MemorySegment image of an ItemsSketch. + * @return a human readable string of the preamble of a MemorySegment image of an QuantilesItemsSketch. */ public static String toString(final MemorySegment seg) { return PreambleUtil.toString(seg, false); @@ -501,8 +501,8 @@ public static String toString(final MemorySegment seg) { * It is required that this.getK() = newK * 2^(nonnegative integer). * @return the new sketch. */ - public ItemsSketch downSample(final int newK) { - final ItemsSketch newSketch = ItemsSketch.getInstance(clazz, newK, comparator_); + public QuantilesItemsSketch downSample(final int newK) { + final QuantilesItemsSketch newSketch = QuantilesItemsSketch.getInstance(clazz, newK, comparator_); ItemsMergeImpl.downSamplingMergeInto(this, newSketch); return newSketch; } @@ -538,7 +538,7 @@ public void update(final T item) { if ((minItem_ == null) || (comparator_.compare(item, minItem_) < 0)) { minItem_ = item; } if ((baseBufferCount_ + 1) > combinedBufferItemCapacity_) { - ItemsSketch.growBaseBuffer(this); + QuantilesItemsSketch.growBaseBuffer(this); } combinedBuffer_[baseBufferCount_++] = item; n_++; @@ -586,8 +586,8 @@ Object[] getCombinedBuffer() { * Returns a copy of this sketch and then resets. * @return a copy of this sketch and then resets. */ - ItemsSketch getSketchAndReset() { - final ItemsSketch skCopy = copy(this); + QuantilesItemsSketch getSketchAndReset() { + final QuantilesItemsSketch skCopy = copy(this); reset(); return skCopy; } @@ -620,7 +620,7 @@ private void itemsArrayToCombinedBuffer(final T[] itemsArray) { } } - private static void growBaseBuffer(final ItemsSketch sketch) { + private static void growBaseBuffer(final QuantilesItemsSketch sketch) { final Object[] baseBuffer = sketch.getCombinedBuffer(); final int oldSize = sketch.getCombinedBufferAllocatedCount(); final int k = sketch.getK(); @@ -642,7 +642,7 @@ private ItemsSketchSortedView refreshSortedView() { } @SuppressWarnings({"unchecked"}) - private static ItemsSketchSortedView getSV(final ItemsSketch sk) { + private static ItemsSketchSortedView getSV(final QuantilesItemsSketch sk) { final long totalN = sk.getN(); if (sk.isEmpty() || (totalN == 0)) { throw new SketchesArgumentException(EMPTY_MSG); } final int k = sk.getK(); @@ -654,7 +654,7 @@ private static ItemsSketchSortedView getSV(final ItemsSketch sk) { final T[] combinedBuffer = (T[]) sk.getCombinedBuffer(); final int baseBufferCount = sk.getBaseBufferCount(); - // Populate from ItemsSketch: + // Populate from QuantilesItemsSketch: // copy over the "levels" and then the base buffer, all with appropriate weights populateFromItemsSketch(k, totalN, sk.getBitPattern(), combinedBuffer, baseBufferCount, numQuantiles, svQuantiles, svCumWeights, sk.getComparator()); diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsSketchIterator.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesItemsSketchIterator.java similarity index 89% rename from src/main/java/org/apache/datasketches/quantiles/ItemsSketchIterator.java rename to src/main/java/org/apache/datasketches/quantiles/QuantilesItemsSketchIterator.java index 87b542612..58bbc8c4e 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsSketchIterator.java +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesItemsSketchIterator.java @@ -22,13 +22,13 @@ import java.util.Objects; import org.apache.datasketches.common.SketchesStateException; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; /** - * Iterator over ItemsSketch. The order is not defined. + * Iterator over QuantilesItemsSketch. The order is not defined. * @param type of item */ -public final class ItemsSketchIterator implements QuantilesGenericSketchIterator { +public final class QuantilesItemsSketchIterator implements QuantilesGenericSketchIteratorAPI { private Object[] combinedBuffer; private long bitPattern; private int level; @@ -38,7 +38,7 @@ public final class ItemsSketchIterator implements QuantilesGenericSketchItera private int num; private int k; - ItemsSketchIterator(final ItemsSketch sketch, final long bitPattern) { + QuantilesItemsSketchIterator(final QuantilesItemsSketch sketch, final long bitPattern) { Objects.requireNonNull(sketch, "sketch must not be null"); combinedBuffer = sketch.combinedBuffer_; num = sketch.getBaseBufferCount(); diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsUnion.java b/src/main/java/org/apache/datasketches/quantiles/QuantilesItemsUnion.java similarity index 74% rename from src/main/java/org/apache/datasketches/quantiles/ItemsUnion.java rename to src/main/java/org/apache/datasketches/quantiles/QuantilesItemsUnion.java index 97cb9c8c7..9e1ce9bc8 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsUnion.java +++ b/src/main/java/org/apache/datasketches/quantiles/QuantilesItemsUnion.java @@ -28,24 +28,24 @@ import org.apache.datasketches.common.ArrayOfItemsSerDe; /** - * The API for Union operations for generic ItemsSketches + * The API for Union operations for generic QuantilesItemsSketches * * @param The sketch item data type. * * @author Lee Rhodes * @author Alexander Saydakov */ -public final class ItemsUnion { +public final class QuantilesItemsUnion { final int maxK_; final Comparator comparator_; - ItemsSketch gadget_; + QuantilesItemsSketch gadget_; Class clazz_; - private ItemsUnion( + private QuantilesItemsUnion( final int maxK, final Comparator comparator, - final ItemsSketch gadget) { + final QuantilesItemsSketch gadget) { Objects.requireNonNull(gadget, "Gadget sketch must not be null."); Objects.requireNonNull(comparator, "Comparator must not be null."); maxK_ = maxK; @@ -56,63 +56,63 @@ private ItemsUnion( } /** - * Create an instance of ItemsUnion with the default k. + * Create an instance of QuantilesItemsUnion with the default k. * @param The sketch item data type. * @param clazz The sketch class type. * @param comparator to compare items. - * @return a new instance of ItemsUnion + * @return a new instance of QuantilesItemsUnion */ - public static ItemsUnion getInstance( + public static QuantilesItemsUnion getInstance( final Class clazz, final Comparator comparator) { - final ItemsSketch emptySk = ItemsSketch.getInstance(clazz, comparator); - return new ItemsUnion<>(PreambleUtil.DEFAULT_K, comparator, emptySk); + final QuantilesItemsSketch emptySk = QuantilesItemsSketch.getInstance(clazz, comparator); + return new QuantilesItemsUnion<>(PreambleUtil.DEFAULT_K, comparator, emptySk); } /** - * Create an instance of ItemsUnion + * Create an instance of QuantilesItemsUnion * @param The sketch item data type. * @param clazz The sketch class type. * @param maxK determines the accuracy and size of the union and is a maximum. * The effective k can be smaller due to unions with smaller k sketches. * maxK must be a power of 2 to enable unioning of sketches with a different k. * @param comparator to compare items. - * @return an new instance of ItemsUnion + * @return an new instance of QuantilesItemsUnion */ - public static ItemsUnion getInstance( + public static QuantilesItemsUnion getInstance( final Class clazz, final int maxK, final Comparator comparator) { - final ItemsSketch emptySk = ItemsSketch.getInstance(clazz, maxK, comparator); - return new ItemsUnion<>(maxK, comparator, emptySk); + final QuantilesItemsSketch emptySk = QuantilesItemsSketch.getInstance(clazz, maxK, comparator); + return new QuantilesItemsUnion<>(maxK, comparator, emptySk); } /** - * Initialize a new ItemsUnion with a heapified instance of an ItemsSketch from a MemorySegment. + * Initialize a new QuantilesItemsUnion with a heapified instance of an QuantilesItemsSketch from a MemorySegment. * @param The sketch data type. * @param clazz The sketch class type. - * @param srcSeg the given srcSeg, an image of an ItemsSketch. A reference to srcSeg will not be maintained internally. + * @param srcSeg the given srcSeg, an image of an QuantilesItemsSketch. A reference to srcSeg will not be maintained internally. * @param comparator to compare items. * @param serDe an instance of ArrayOfItemsSerDe. - * @return an ItemsUnion initialized with a heapified ItemsSketch from a MemorySegment. + * @return an QuantilesItemsUnion initialized with a heapified QuantilesItemsSketch from a MemorySegment. */ - public static ItemsUnion initializeWithMemorySegment( + public static QuantilesItemsUnion initializeWithMemorySegment( final Class clazz, final MemorySegment srcSeg, final Comparator comparator, final ArrayOfItemsSerDe serDe) { - final ItemsSketch gadget = ItemsSketch.heapify(clazz, srcSeg, comparator, serDe); - return new ItemsUnion<>(gadget.getK(), gadget.getComparator(), gadget); + final QuantilesItemsSketch gadget = QuantilesItemsSketch.heapify(clazz, srcSeg, comparator, serDe); + return new QuantilesItemsUnion<>(gadget.getK(), gadget.getComparator(), gadget); } /** - * Initialize a new ItemsUnion with an instance of ItemsSketch + * Initialize a new QuantilesItemsUnion with an instance of QuantilesItemsSketch * @param The sketch data type - * @param sketch an instance of ItemsSketch to initialize this union - * @return an initialized instance of ItemsUnion + * @param sketch an instance of QuantilesItemsSketch to initialize this union + * @return an initialized instance of QuantilesItemsUnion */ - public static ItemsUnion initialize(final ItemsSketch sketch) { - return new ItemsUnion<>(sketch.getK(), sketch.getComparator(), ItemsSketch.copy(sketch)); + public static QuantilesItemsUnion initialize(final QuantilesItemsSketch sketch) { + return new QuantilesItemsUnion<>(sketch.getK(), sketch.getComparator(), QuantilesItemsSketch.copy(sketch)); } /** @@ -128,13 +128,13 @@ public static ItemsUnion initialize(final ItemsSketch sketch) { * * @param sketchIn the sketch to be merged into this one. */ - public void union(final ItemsSketch sketchIn) { + public void union(final QuantilesItemsSketch sketchIn) { gadget_ = updateLogic(maxK_, comparator_, gadget_, sketchIn); } /** * Iterative union operation, which means this method can be repeatedly called. - * Merges the given MemorySegment image of a ItemsSketch into this union object. + * Merges the given MemorySegment image of a QuantilesItemsSketch into this union object. * The given MemorySegment object is not modified and a link to it is not retained. * It is required that the ratio of the two K's be a power of 2. * This is easily satisfied if each of the K's are already a power of 2. @@ -148,7 +148,7 @@ public void union(final ItemsSketch sketchIn) { public void union( final MemorySegment srcSeg, final ArrayOfItemsSerDe serDe) { - final ItemsSketch that = ItemsSketch.heapify(clazz_, srcSeg, comparator_, serDe); + final QuantilesItemsSketch that = QuantilesItemsSketch.heapify(clazz_, srcSeg, comparator_, serDe); gadget_ = updateLogic(maxK_, comparator_, gadget_, that); } @@ -160,7 +160,7 @@ public void union( public void update(final T dataItem) { if (dataItem == null) { return; } if (gadget_ == null) { - gadget_ = ItemsSketch.getInstance(clazz_, maxK_, comparator_); + gadget_ = QuantilesItemsSketch.getInstance(clazz_, maxK_, comparator_); } gadget_.update(dataItem); } @@ -170,11 +170,11 @@ public void update(final T dataItem) { * This enables further union update operations on this state. * @return the result of this Union operation */ - public ItemsSketch getResult() { + public QuantilesItemsSketch getResult() { if (gadget_ == null) { - return ItemsSketch.getInstance(clazz_, maxK_, comparator_); + return QuantilesItemsSketch.getInstance(clazz_, maxK_, comparator_); } - return ItemsSketch.copy(gadget_); //can't have any externally owned handles. + return QuantilesItemsSketch.copy(gadget_); //can't have any externally owned handles. } /** @@ -182,7 +182,7 @@ public ItemsSketch getResult() { * * @return the result of this Union operation and reset. */ - public ItemsSketch getResultAndReset() { + public QuantilesItemsSketch getResultAndReset() { if (gadget_ == null) { return null; } //Intentionally return null here for speed. return gadget_.getSketchAndReset(); } @@ -241,7 +241,7 @@ public String toString(final boolean sketchSummary, final boolean dataDetail) { sb.append(LS).append("### Quantiles ").append(thisSimpleName).append(LS); sb.append(" maxK : ").append(kStr); if (gadget_ == null) { - sb.append(ItemsSketch.getInstance(clazz_, maxK_, comparator_).toString()); + sb.append(QuantilesItemsSketch.getInstance(clazz_, maxK_, comparator_).toString()); return sb.toString(); } sb.append(gadget_.toString(sketchSummary, dataDetail)); @@ -249,7 +249,7 @@ public String toString(final boolean sketchSummary, final boolean dataDetail) { } /** - * Serialize this union to a byte array. Result is an ItemsSketch, serialized in an + * Serialize this union to a byte array. Result is an QuantilesItemsSketch, serialized in an * unordered, non-compact form. The resulting byte[] can be passed to getInstance for either a * sketch or union. * @@ -258,7 +258,7 @@ public String toString(final boolean sketchSummary, final boolean dataDetail) { */ public byte[] toByteArray(final ArrayOfItemsSerDe serDe) { if (gadget_ == null) { - final ItemsSketch sketch = ItemsSketch.getInstance(clazz_, maxK_, comparator_); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(clazz_, maxK_, comparator_); return sketch.toByteArray(serDe); } return gadget_.toByteArray(serDe); @@ -266,8 +266,8 @@ public byte[] toByteArray(final ArrayOfItemsSerDe serDe) { //@formatter:off @SuppressWarnings("unchecked") - static ItemsSketch updateLogic(final int myMaxK, final Comparator comparator, - final ItemsSketch myQS, final ItemsSketch other) { + static QuantilesItemsSketch updateLogic(final int myMaxK, final Comparator comparator, + final QuantilesItemsSketch myQS, final QuantilesItemsSketch other) { int sw1 = ((myQS == null) ? 0 : myQS.isEmpty() ? 4 : 8); sw1 |= ((other == null) ? 0 : other.isEmpty() ? 1 : 2); int outCase = 0; //0=null, 1=NOOP, 2=copy, 3=merge @@ -284,7 +284,7 @@ static ItemsSketch updateLogic(final int myMaxK, final Comparator ret = null; + QuantilesItemsSketch ret = null; switch (outCase) { case 0: break; @@ -292,7 +292,7 @@ static ItemsSketch updateLogic(final int myMaxK, final Comparator ItemsSketch updateLogic(final int myMaxK, final Comparator ItemsSketch updateLogic(final int myMaxK, final Comparator other.getK(), must reverse roles //must copy other as it will become mine and can't have any externally owned handles. - ret = ItemsSketch.copy(other); + ret = QuantilesItemsSketch.copy(other); ItemsMergeImpl.mergeInto(myQS, ret); } break; } case 4: { assert other != null; - ret = ItemsSketch.getInstance(other.getClassOfT(), Math.min(myMaxK, other.getK()), comparator); + ret = QuantilesItemsSketch.getInstance(other.getClassOfT(), Math.min(myMaxK, other.getK()), comparator); break; } default: break; //This cannot happen diff --git a/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/UpdatableQuantilesDoublesSketch.java similarity index 87% rename from src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java rename to src/main/java/org/apache/datasketches/quantiles/UpdatableQuantilesDoublesSketch.java index d511d8fa7..803484aac 100644 --- a/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/UpdatableQuantilesDoublesSketch.java @@ -24,19 +24,19 @@ import org.apache.datasketches.common.MemorySegmentRequest; /** - * Extends DoubleSketch + * Extends QuantilesDoubleSketch * @author Jon Malkin */ -public abstract class UpdateDoublesSketch extends DoublesSketch { +public abstract class UpdatableQuantilesDoublesSketch extends QuantilesDoublesSketch { - UpdateDoublesSketch(final int k) { + UpdatableQuantilesDoublesSketch(final int k) { super(k); } /** * Wrap a sketch around the given source MemorySegment containing sketch data that originated from this sketch. * - *

    The given MemorySegment must be writable and it must contain a UpdateDoublesSketch. + *

    The given MemorySegment must be writable and it must contain a UpdatableQuantilesDoublesSketch. * The sketch will be updated and managed totally within the MemorySegment. If the given source * MemorySegment is created off-heap, then all the management of the sketch's internal data will be off-heap as well.

    * @@ -47,7 +47,7 @@ public abstract class UpdateDoublesSketch extends DoublesSketch { * @param srcSeg a MemorySegment that contains sketch data. * @return an instance of this sketch that wraps the given MemorySegment. */ - public static UpdateDoublesSketch wrap(final MemorySegment srcSeg) { + public static UpdatableQuantilesDoublesSketch wrap(final MemorySegment srcSeg) { return DirectUpdateDoublesSketch.wrapInstance(srcSeg, null); } @@ -55,7 +55,7 @@ public static UpdateDoublesSketch wrap(final MemorySegment srcSeg) { * Wrap a sketch around the given source MemorySegment containing sketch data that originated from this sketch and including an * optional, user defined {@link MemorySegmentRequest MemorySegmentRequest}. * - *

    The given MemorySegment must be writable and it must contain a UpdateDoublesSketch. + *

    The given MemorySegment must be writable and it must contain a UpdatableQuantilesDoublesSketch. * The sketch will be updated and managed totally within the MemorySegment. If the given source * MemorySegment is created off-heap, then all the management of the sketch's internal data will be off-heap as well.

    * @@ -69,7 +69,7 @@ public static UpdateDoublesSketch wrap(final MemorySegment srcSeg) { * Otherwise, it can be null and the default MemorySegmentRequest will be used. * @return an instance of this sketch that wraps the given MemorySegment. */ - public static UpdateDoublesSketch wrap(final MemorySegment srcSeg, final MemorySegmentRequest mSegReq) { + public static UpdatableQuantilesDoublesSketch wrap(final MemorySegment srcSeg, final MemorySegmentRequest mSegReq) { return DirectUpdateDoublesSketch.wrapInstance(srcSeg, mSegReq); } @@ -79,15 +79,15 @@ public static UpdateDoublesSketch wrap(final MemorySegment srcSeg, final MemoryS * @param srcSeg compact MemorySegment image of a sketch serialized by this sketch. * @return a heap-based sketch based on the given MemorySegment. */ - public static UpdateDoublesSketch heapify(final MemorySegment srcSeg) { + public static UpdatableQuantilesDoublesSketch heapify(final MemorySegment srcSeg) { return HeapUpdateDoublesSketch.heapifyInstance(srcSeg); } /** - * Returns a CompactDoublesSketch of this class - * @return a CompactDoublesSketch of this class + * Returns a CompactQuantilesDoublesSketch of this class + * @return a CompactQuantilesDoublesSketch of this class */ - public CompactDoublesSketch compact() { + public CompactQuantilesDoublesSketch compact() { return compact(null); } @@ -97,7 +97,7 @@ public CompactDoublesSketch compact() { * @param dstSeg An optional target MemorySegment to hold the sketch. * @return A compact version of this sketch */ - public CompactDoublesSketch compact(final MemorySegment dstSeg) { + public CompactQuantilesDoublesSketch compact(final MemorySegment dstSeg) { if (dstSeg == null) { return HeapCompactDoublesSketch.createFromUpdateSketch(this); } @@ -108,7 +108,7 @@ public CompactDoublesSketch compact(final MemorySegment dstSeg) { * Returns an on-heap copy of this sketch and then resets this sketch with the same value of k. * @return an on-heap copy of this sketch and then resets this sketch with the same value of k. */ - abstract UpdateDoublesSketch getSketchAndReset(); + abstract UpdatableQuantilesDoublesSketch getSketchAndReset(); /** * Grows the combined buffer to the given spaceNeeded diff --git a/src/main/java/org/apache/datasketches/quantiles/package-info.java b/src/main/java/org/apache/datasketches/quantiles/package-info.java index 8767757b7..7ff0dcdb3 100644 --- a/src/main/java/org/apache/datasketches/quantiles/package-info.java +++ b/src/main/java/org/apache/datasketches/quantiles/package-info.java @@ -21,7 +21,7 @@ * The quantiles package contains stochastic streaming algorithms that enable single-pass * analysis of the distribution of a stream of quantiles. * - * @see org.apache.datasketches.quantiles.DoublesSketch - * @see org.apache.datasketches.quantiles.ItemsSketch + * @see org.apache.datasketches.quantiles.QuantilesDoublesSketch + * @see org.apache.datasketches.quantiles.QuantilesItemsSketch */ package org.apache.datasketches.quantiles; diff --git a/src/main/java/org/apache/datasketches/quantilescommon/BinarySearch.java b/src/main/java/org/apache/datasketches/quantilescommon/BinarySearch.java index 1d1059193..9a5bd7592 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/BinarySearch.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/BinarySearch.java @@ -26,6 +26,11 @@ */ public final class BinarySearch { + /** + * No argument constructor. + */ + public BinarySearch() { } + /** * Binary Search for the index of the exact float value in the given search range. * If -1 is returned there are no values in the search range that equals the given value. diff --git a/src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java b/src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java index b5a8b8a45..2ad3ecdd0 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java @@ -19,15 +19,15 @@ package org.apache.datasketches.quantilescommon; -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.DoublesPair; /** - * The SortedView of the Quantiles Classic DoublesSketch and the KllDoublesSketch. + * The SortedView of the Quantiles Classic QuantilesDoublesSketch and the KllDoublesSketch. * @author Alexander Saydakov * @author Lee Rhodes */ diff --git a/src/main/java/org/apache/datasketches/quantilescommon/GenericInequalitySearch.java b/src/main/java/org/apache/datasketches/quantilescommon/GenericInequalitySearch.java index 7b9d6d665..460ef6b7b 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/GenericInequalitySearch.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/GenericInequalitySearch.java @@ -47,6 +47,11 @@ */ public final class GenericInequalitySearch { + /** + * No argument constructor. + */ + public GenericInequalitySearch() { } + /** * The enumerator of inequalities */ diff --git a/src/main/java/org/apache/datasketches/quantilescommon/IncludeMinMax.java b/src/main/java/org/apache/datasketches/quantilescommon/IncludeMinMax.java index 1edfc2054..84061f840 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/IncludeMinMax.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/IncludeMinMax.java @@ -27,6 +27,11 @@ */ public class IncludeMinMax { + /** + * No argument constructor. + */ + public IncludeMinMax() { } + /** A simple structure to hold a pair of arrays */ public static class DoublesPair { /** the array of quantiles */ diff --git a/src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java b/src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java index 515783825..ebbed228d 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java @@ -21,7 +21,6 @@ import static java.lang.Math.min; import static org.apache.datasketches.quantilescommon.GenericInequalitySearch.find; -import static org.apache.datasketches.quantilescommon.IncludeMinMax.ItemsPair; import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE; import static org.apache.datasketches.quantilescommon.QuantilesAPI.EMPTY_MSG; import static org.apache.datasketches.quantilescommon.QuantilesUtil.evenlySpacedDoubles; @@ -32,9 +31,10 @@ import org.apache.datasketches.common.SketchesArgumentException; import org.apache.datasketches.quantilescommon.GenericInequalitySearch.Inequality; +import org.apache.datasketches.quantilescommon.IncludeMinMax.ItemsPair; /** - * The SortedView for the KllItemsSketch and the classic ItemsSketch. + * The SortedView for the KllItemsSketch and the classic QuantilesItemsSketch. * @param The sketch data type * @author Alexander Saydakov * @author Lee Rhodes diff --git a/src/main/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnov.java b/src/main/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnov.java index 751a74ff1..5ed11347b 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnov.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnov.java @@ -33,6 +33,11 @@ */ public final class KolmogorovSmirnov { + /** + * No argument constructor. + */ + public KolmogorovSmirnov() { } + /** * Computes the raw delta between two QuantilesDoublesAPI sketches for the kolmogorovSmirnovTest(...) method. * @param sketch1 first Input QuantilesDoublesAPI diff --git a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesAPI.java b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesAPI.java index 09cfd6071..63ec15284 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesAPI.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesAPI.java @@ -283,7 +283,7 @@ default double[] getRanks(final double[] quantiles) { * Gets the iterator for this sketch, which is not sorted. * @return the iterator for this sketch */ - QuantilesDoublesSketchIterator iterator(); + QuantilesDoublesSketchIteratorAPI iterator(); /** * Returns a byte array representation of this sketch. diff --git a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesSketchIterator.java b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesSketchIteratorAPI.java similarity index 90% rename from src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesSketchIterator.java rename to src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesSketchIteratorAPI.java index f4a923f8c..87131f3fb 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesSketchIterator.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesSketchIteratorAPI.java @@ -21,10 +21,10 @@ /** * The quantiles sketch iterator for primitive type double. - * @see QuantilesSketchIterator + * @see QuantilesSketchIteratorAPI * @author Lee Rhodes */ -public interface QuantilesDoublesSketchIterator extends QuantilesSketchIterator { +public interface QuantilesDoublesSketchIteratorAPI extends QuantilesSketchIteratorAPI { /** * Gets the double quantile at the current index. diff --git a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesFloatsSketchIterator.java b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesFloatsSketchIterator.java index e806a6b02..176cffcea 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesFloatsSketchIterator.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesFloatsSketchIterator.java @@ -21,10 +21,10 @@ /** * The quantiles sketch iterator for primitive type float. - * @see QuantilesSketchIterator + * @see QuantilesSketchIteratorAPI * @author Lee Rhodes */ -public interface QuantilesFloatsSketchIterator extends QuantilesSketchIterator { +public interface QuantilesFloatsSketchIterator extends QuantilesSketchIteratorAPI { /** * Gets the float quantile at the current index. diff --git a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericAPI.java b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericAPI.java index d1592e244..6251a9596 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericAPI.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericAPI.java @@ -297,7 +297,7 @@ default double[] getRanks(final T[] quantiles) { * Gets the iterator for this sketch, which is not sorted. * @return the iterator for this sketch */ - QuantilesGenericSketchIterator iterator(); + QuantilesGenericSketchIteratorAPI iterator(); /** * Updates this sketch with the given item. diff --git a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericSketchIterator.java b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericSketchIteratorAPI.java similarity index 90% rename from src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericSketchIterator.java rename to src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericSketchIteratorAPI.java index f379eaab6..d2c50c450 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericSketchIterator.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericSketchIteratorAPI.java @@ -21,11 +21,11 @@ /** * The quantiles sketch iterator for generic types. - * @see QuantilesSketchIterator + * @see QuantilesSketchIteratorAPI * @param The generic quantile type * @author Lee Rhodes */ -public interface QuantilesGenericSketchIterator extends QuantilesSketchIterator { +public interface QuantilesGenericSketchIteratorAPI extends QuantilesSketchIteratorAPI { /** * Gets the generic quantile at the current index. diff --git a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesLongsSketchIterator.java b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesLongsSketchIterator.java index 7ed0d9805..5e2912e85 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesLongsSketchIterator.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesLongsSketchIterator.java @@ -21,10 +21,10 @@ /** * The quantiles sketch iterator for primitive type long. - * @see QuantilesSketchIterator + * @see QuantilesSketchIteratorAPI * @author Zac Blanco */ -public interface QuantilesLongsSketchIterator extends QuantilesSketchIterator { +public interface QuantilesLongsSketchIterator extends QuantilesSketchIteratorAPI { /** * Gets the long quantile at the current index. diff --git a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesSketchIterator.java b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesSketchIteratorAPI.java similarity index 87% rename from src/main/java/org/apache/datasketches/quantilescommon/QuantilesSketchIterator.java rename to src/main/java/org/apache/datasketches/quantilescommon/QuantilesSketchIteratorAPI.java index dbeb3ac47..4358bd9ec 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/QuantilesSketchIterator.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/QuantilesSketchIteratorAPI.java @@ -20,8 +20,8 @@ package org.apache.datasketches.quantilescommon; /** - * This is the base interface for the SketchIterator hierarchy used for viewing the - * non-ordered quantiles retained by a sketch. + * This is the base API for the iterator hierarchy used for viewing the + * non-ordered quantiles retained by the classic Quantiles* sketches and KLL sketches, for example. * *

    Prototype example of the recommended iteration loop:

    *
    {@code
    @@ -34,7 +34,7 @@
      * @author Lee Rhodes
      */
     
    -public interface QuantilesSketchIterator {
    +public interface QuantilesSketchIteratorAPI {
     
       /**
        * Gets the natural weight at the current index.
    diff --git a/src/main/java/org/apache/datasketches/tdigest/BinarySearch.java b/src/main/java/org/apache/datasketches/tdigest/BinarySearch.java
    index fdb0ca3c6..cdd14b89b 100644
    --- a/src/main/java/org/apache/datasketches/tdigest/BinarySearch.java
    +++ b/src/main/java/org/apache/datasketches/tdigest/BinarySearch.java
    @@ -24,6 +24,11 @@
      */
     public final class BinarySearch {
     
    +  /**
    +   * No argument constructor.
    +   */
    +  public BinarySearch() { }
    +
       /**
        * Returns an index to the first element in the range [first, last) such that
        * element < value is false (i.e. that is greater than or equal to value),
    @@ -43,7 +48,7 @@ public final class BinarySearch {
       static int lowerBound(final double[] values, int first, final int last, final double value) {
         int current;
         int step;
    -    int count = last - first; 
    +    int count = last - first;
         while (count > 0) {
           step = count / 2;
           current = first + step;
    @@ -76,9 +81,9 @@ static int lowerBound(final double[] values, int first, final int last, final do
       static int upperBound(final double[] values, int first, final int last, final double value) {
         int current;
         int step;
    -    int count = last - first; 
    +    int count = last - first;
         while (count > 0) {
    -      step = count / 2; 
    +      step = count / 2;
           current = first + step;
           if (!(value < values[current])) {
             first = ++current;
    diff --git a/src/main/java/org/apache/datasketches/tdigest/Sort.java b/src/main/java/org/apache/datasketches/tdigest/Sort.java
    index 331a3433f..849f36a09 100644
    --- a/src/main/java/org/apache/datasketches/tdigest/Sort.java
    +++ b/src/main/java/org/apache/datasketches/tdigest/Sort.java
    @@ -26,6 +26,11 @@
      */
     public final class Sort {
     
    +  /**
    +   * No argument constructor.
    +   */
    +  public Sort() { }
    +
       /**
        * Stable sort two arrays.
        * The first array is sorted while the second array is permuted the same way.
    @@ -139,7 +144,7 @@ private static void stableLimitedInsertionSort(final double[] keys, final long[]
           }
         }
       }
    -  
    +
       private static void swap(final double[] values, final int i, final int j) {
         final double tmpValue = values[i];
         values[i] = values[j];
    diff --git a/src/main/java/org/apache/datasketches/theta/CompactThetaSketch.java b/src/main/java/org/apache/datasketches/theta/CompactThetaSketch.java
    index 9dedaac46..5b784469c 100644
    --- a/src/main/java/org/apache/datasketches/theta/CompactThetaSketch.java
    +++ b/src/main/java/org/apache/datasketches/theta/CompactThetaSketch.java
    @@ -60,6 +60,11 @@
      */
     public abstract class CompactThetaSketch extends ThetaSketch {
     
    +  /**
    +   * No argument constructor.
    +   */
    +  public CompactThetaSketch() { }
    +
       /**
        * Heapify takes a CompactThetaSketch image in a MemorySegment and instantiates an on-heap CompactThetaSketch.
        *
    diff --git a/src/main/java/org/apache/datasketches/theta/ThetaIntersection.java b/src/main/java/org/apache/datasketches/theta/ThetaIntersection.java
    index a1d0809cd..e72aa62ff 100644
    --- a/src/main/java/org/apache/datasketches/theta/ThetaIntersection.java
    +++ b/src/main/java/org/apache/datasketches/theta/ThetaIntersection.java
    @@ -35,6 +35,11 @@
      */
     public abstract class ThetaIntersection extends ThetaSetOperation {
     
    +  /**
    +   * No argument constructor.
    +   */
    +  public ThetaIntersection() { }
    +
       @Override
       public Family getFamily() {
         return Family.INTERSECTION;
    diff --git a/src/main/java/org/apache/datasketches/theta/ThetaUnion.java b/src/main/java/org/apache/datasketches/theta/ThetaUnion.java
    index 72da65053..5ba80d14c 100644
    --- a/src/main/java/org/apache/datasketches/theta/ThetaUnion.java
    +++ b/src/main/java/org/apache/datasketches/theta/ThetaUnion.java
    @@ -37,6 +37,11 @@
      */
     public abstract class ThetaUnion extends ThetaSetOperation {
     
    +  /**
    +   * No argument constructor.
    +   */
    +  public ThetaUnion() { }
    +
       /**
        * Wrap a ThetaUnion object around a ThetaUnion MemorySegment object containing data.
        * This method assumes the Default Update Seed.
    diff --git a/src/main/java/org/apache/datasketches/theta/package-info.java b/src/main/java/org/apache/datasketches/theta/package-info.java
    index 870f4f968..6da1a6a62 100644
    --- a/src/main/java/org/apache/datasketches/theta/package-info.java
    +++ b/src/main/java/org/apache/datasketches/theta/package-info.java
    @@ -18,10 +18,10 @@
      */
     
     /**
    - * The /theta/ package contains the basic sketch classes that are members of the
    - * ThetaSketch Framework.
    + * The theta package contains the basic sketch classes that are members of the
    + * Theta-Sketch Framework.
      *
      * 

    There is a separate /tuple/ package for many of the sketches that are derived from the - * same algorithms defined in the ThetaSketch Framework paper.

    + * same algorithms defined in the Theta-Sketch Framework paper.

    */ package org.apache.datasketches.theta; diff --git a/src/main/java/org/apache/datasketches/thetacommon/SetOperationCornerCases.java b/src/main/java/org/apache/datasketches/thetacommon/SetOperationCornerCases.java index 2457b37fe..d77496bc2 100644 --- a/src/main/java/org/apache/datasketches/thetacommon/SetOperationCornerCases.java +++ b/src/main/java/org/apache/datasketches/thetacommon/SetOperationCornerCases.java @@ -32,6 +32,11 @@ public class SetOperationCornerCases { private static final long MAX = Long.MAX_VALUE; + /** + * No argument constructor. + */ + public SetOperationCornerCases() { } + /** Intersection actions */ public enum IntersectAction { /** Degenerate{MinTheta, 0, F} */ diff --git a/src/main/java/org/apache/datasketches/tuple/JaccardSimilarity.java b/src/main/java/org/apache/datasketches/tuple/JaccardSimilarity.java index 3df418737..bc0c1e5b3 100644 --- a/src/main/java/org/apache/datasketches/tuple/JaccardSimilarity.java +++ b/src/main/java/org/apache/datasketches/tuple/JaccardSimilarity.java @@ -43,6 +43,11 @@ public final class JaccardSimilarity { private static final double[] ZEROS = {0.0, 0.0, 0.0}; // LB, Estimate, UB private static final double[] ONES = {1.0, 1.0, 1.0}; + /** + * No argument constructor. + */ + public JaccardSimilarity() { } + /** * Computes the Jaccard similarity index with upper and lower bounds. The Jaccard similarity index * J(A,B) = (A ^ B)/(A U B) is used to measure how similar the two sketches are to each diff --git a/src/main/java/org/apache/datasketches/tuple/SerializerDeserializer.java b/src/main/java/org/apache/datasketches/tuple/SerializerDeserializer.java index 367ef9971..6088e2022 100644 --- a/src/main/java/org/apache/datasketches/tuple/SerializerDeserializer.java +++ b/src/main/java/org/apache/datasketches/tuple/SerializerDeserializer.java @@ -31,6 +31,11 @@ */ public final class SerializerDeserializer { + /** + * No argument constructor. + */ + public SerializerDeserializer() { } + /** * Defines the sketch classes that this SerializerDeserializer can handle. */ diff --git a/src/main/java/org/apache/datasketches/tuple/TupleAnotB.java b/src/main/java/org/apache/datasketches/tuple/TupleAnotB.java index 7676211b8..cdc6f18cf 100644 --- a/src/main/java/org/apache/datasketches/tuple/TupleAnotB.java +++ b/src/main/java/org/apache/datasketches/tuple/TupleAnotB.java @@ -87,6 +87,11 @@ public final class TupleAnotB { } } + /** + * No argument constructor. + */ + public TupleAnotB() { } + /** * This is part of a multistep, stateful TupleAnotB operation and sets the given TupleSketch as the * first argument A of A-AND-NOT-B. This overwrites the internal state of this diff --git a/src/main/java/org/apache/datasketches/tuple/Util.java b/src/main/java/org/apache/datasketches/tuple/Util.java index 46f069724..45168fa4a 100644 --- a/src/main/java/org/apache/datasketches/tuple/Util.java +++ b/src/main/java/org/apache/datasketches/tuple/Util.java @@ -34,6 +34,11 @@ public final class Util { private static final int PRIME = 0x7A3C_CA71; + /** + * No argument constructor. + */ + public Util() { } + /** * Converts a double to a long[]. * @param value the given double value diff --git a/src/main/java/org/apache/datasketches/tuple/adouble/DoubleSummaryDeserializer.java b/src/main/java/org/apache/datasketches/tuple/adouble/DoubleSummaryDeserializer.java index b105a6b16..3027a3777 100644 --- a/src/main/java/org/apache/datasketches/tuple/adouble/DoubleSummaryDeserializer.java +++ b/src/main/java/org/apache/datasketches/tuple/adouble/DoubleSummaryDeserializer.java @@ -30,6 +30,11 @@ */ public class DoubleSummaryDeserializer implements SummaryDeserializer { + /** + * No argument constructor. + */ + public DoubleSummaryDeserializer() { } + @Override public DeserializeResult heapifySummary(final MemorySegment seg) { return DoubleSummary.fromMemorySegment(seg); diff --git a/src/main/java/org/apache/datasketches/tuple/aninteger/IntegerSummaryDeserializer.java b/src/main/java/org/apache/datasketches/tuple/aninteger/IntegerSummaryDeserializer.java index 0941a1088..0fb8f55a5 100644 --- a/src/main/java/org/apache/datasketches/tuple/aninteger/IntegerSummaryDeserializer.java +++ b/src/main/java/org/apache/datasketches/tuple/aninteger/IntegerSummaryDeserializer.java @@ -30,6 +30,11 @@ */ public class IntegerSummaryDeserializer implements SummaryDeserializer { + /** + * No argument constructor. + */ + public IntegerSummaryDeserializer() { } + @Override public DeserializeResult heapifySummary(final MemorySegment seg) { return IntegerSummary.fromMemorySegment(seg); diff --git a/src/main/java/org/apache/datasketches/tuple/package-info.java b/src/main/java/org/apache/datasketches/tuple/package-info.java index d7ea21cd7..4a6be9210 100644 --- a/src/main/java/org/apache/datasketches/tuple/package-info.java +++ b/src/main/java/org/apache/datasketches/tuple/package-info.java @@ -18,7 +18,7 @@ */ /** - * The tuple package contains a number of sketches based on the same + * The tuple package contains a number of sketches based on the same * fundamental algorithms of the Theta Sketch Framework and extend these * concepts for whole new families of sketches. */ diff --git a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummary.java b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummary.java index 12d587398..4197cd285 100644 --- a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummary.java +++ b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummary.java @@ -38,6 +38,9 @@ public final class ArrayOfStringsSummary implements UpdatableSummary { private String[] stringArr = null; + /** + * No argument constructor. + */ ArrayOfStringsSummary() { //required for ArrayOfStringsSummaryFactory stringArr = null; } diff --git a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummaryDeserializer.java b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummaryDeserializer.java index 5363605d4..dffe91983 100644 --- a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummaryDeserializer.java +++ b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummaryDeserializer.java @@ -32,6 +32,11 @@ */ public class ArrayOfStringsSummaryDeserializer implements SummaryDeserializer { + /** + * No argument constructor. + */ + public ArrayOfStringsSummaryDeserializer() { } + @Override public DeserializeResult heapifySummary(final MemorySegment seg) { return ArrayOfStringsSummaryDeserializer.fromMemorySegment(seg); diff --git a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummaryFactory.java b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummaryFactory.java index 98fb7fb58..8ca2a6a1a 100644 --- a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummaryFactory.java +++ b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummaryFactory.java @@ -27,6 +27,11 @@ */ public class ArrayOfStringsSummaryFactory implements SummaryFactory { + /** + * No argument constructor. + */ + public ArrayOfStringsSummaryFactory() { } + @Override public ArrayOfStringsSummary newSummary() { return new ArrayOfStringsSummary(); diff --git a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummarySetOperations.java b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummarySetOperations.java index 2650b84ae..270acbe3c 100644 --- a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummarySetOperations.java +++ b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSummarySetOperations.java @@ -27,6 +27,11 @@ */ public class ArrayOfStringsSummarySetOperations implements SummarySetOperations { + /** + * No argument constructor. + */ + public ArrayOfStringsSummarySetOperations() { } + @Override public ArrayOfStringsSummary union(final ArrayOfStringsSummary a, final ArrayOfStringsSummary b) { return a.copy(); diff --git a/src/test/java/org/apache/datasketches/hash/MurmurHash3FFM21Test.java b/src/test/java/org/apache/datasketches/hash/MurmurHash3FFMTest.java similarity index 85% rename from src/test/java/org/apache/datasketches/hash/MurmurHash3FFM21Test.java rename to src/test/java/org/apache/datasketches/hash/MurmurHash3FFMTest.java index d389aef0a..4e2bb00e7 100644 --- a/src/test/java/org/apache/datasketches/hash/MurmurHash3FFM21Test.java +++ b/src/test/java/org/apache/datasketches/hash/MurmurHash3FFMTest.java @@ -38,7 +38,7 @@ /** * @author Lee Rhodes */ -public class MurmurHash3FFM21Test { +public class MurmurHash3FFMTest { private final Random rand = new Random(); private static final int trials = 1 << 20; @@ -158,25 +158,25 @@ private static final long[] hashV1(final byte[] key, final long seed) { } private static final long[] hashV2(final long[] key, final long seed) { - return MurmurHash3FFM21.hash(key, seed); + return MurmurHash3FFM.hash(key, seed); } private static final long[] hashV2(final int[] key2, final long seed) { - return MurmurHash3FFM21.hash(key2, seed); + return MurmurHash3FFM.hash(key2, seed); } private static final long[] hashV2(final char[] key, final long seed) { - return MurmurHash3FFM21.hash(key, seed); + return MurmurHash3FFM.hash(key, seed); } private static final long[] hashV2(final byte[] key, final long seed) { - return MurmurHash3FFM21.hash(key, seed); + return MurmurHash3FFM.hash(key, seed); } //V2 single primitives private static final long[] hashV2(final long key, final long seed, final long[] out) { - return MurmurHash3FFM21.hash(key, seed, out); + return MurmurHash3FFM.hash(key, seed, out); } // private static final long[] hashV2(double key, long seed, long[] out) { @@ -201,7 +201,7 @@ public void offsetChecks() { for (int offset = 0; offset < 16; offset++) { final int arrLen = cap - offset; - hash1 = MurmurHash3FFM21.hash(wseg, offset, arrLen, seed, hash1); + hash1 = MurmurHash3FFM.hash(wseg, offset, arrLen, seed, hash1); final byte[] byteArr2 = new byte[arrLen]; MemorySegment.copy(wseg, JAVA_BYTE, offset, byteArr2, 0, arrLen); hash2 = MurmurHash3.hash(byteArr2, seed); @@ -224,8 +224,8 @@ public void byteArrChecks() { for (int i = 0; i < j; i++) { wseg.set(JAVA_BYTE, i, (byte) (-128 + i)); } final long[] hash1 = MurmurHash3.hash(in, seed); - hash2 = MurmurHash3FFM21.hash(wseg, offset, bytes, seed, hash2); - final long[] hash3 = MurmurHash3FFM21.hash(in, seed); + hash2 = MurmurHash3FFM.hash(wseg, offset, bytes, seed, hash2); + final long[] hash3 = MurmurHash3FFM.hash(in, seed); assertEquals(hash1, hash2); assertEquals(hash1, hash3); @@ -248,8 +248,8 @@ public void charArrChecks() { for (int i = 0; i < j; i++) { wseg.set(JAVA_INT_UNALIGNED, i, i); } final long[] hash1 = MurmurHash3.hash(in, 0); - hash2 = MurmurHash3FFM21.hash(wseg, offset, bytes, seed, hash2); - final long[] hash3 = MurmurHash3FFM21.hash(in, seed); + hash2 = MurmurHash3FFM.hash(wseg, offset, bytes, seed, hash2); + final long[] hash3 = MurmurHash3FFM.hash(in, seed); assertEquals(hash1, hash2); assertEquals(hash1, hash3); @@ -272,8 +272,8 @@ public void intArrChecks() { for (int i = 0; i < j; i++) { wseg.set(JAVA_INT_UNALIGNED, i, i); } final long[] hash1 = MurmurHash3.hash(in, 0); - hash2 = MurmurHash3FFM21.hash(wseg, offset, bytes, seed, hash2); - final long[] hash3 = MurmurHash3FFM21.hash(in, seed); + hash2 = MurmurHash3FFM.hash(wseg, offset, bytes, seed, hash2); + final long[] hash3 = MurmurHash3FFM.hash(in, seed); assertEquals(hash1, hash2); assertEquals(hash1, hash3); @@ -296,8 +296,8 @@ public void longArrChecks() { for (int i = 0; i < j; i++) { wseg.set(JAVA_LONG_UNALIGNED, i, i); } final long[] hash1 = MurmurHash3.hash(in, 0); - hash2 = MurmurHash3FFM21.hash(wseg, offset, bytes, seed, hash2); - final long[] hash3 = MurmurHash3FFM21.hash(in, seed); + hash2 = MurmurHash3FFM.hash(wseg, offset, bytes, seed, hash2); + final long[] hash3 = MurmurHash3FFM.hash(in, seed); assertEquals(hash1, hash2); assertEquals(hash1, hash3); @@ -315,8 +315,8 @@ public void longCheck() { final MemorySegment wseg = MemorySegment.ofArray(in); final long[] hash1 = MurmurHash3.hash(in, 0); - hash2 = MurmurHash3FFM21.hash(wseg, offset, bytes, seed, hash2); - final long[] hash3 = MurmurHash3FFM21.hash(in, seed); + hash2 = MurmurHash3FFM.hash(wseg, offset, bytes, seed, hash2); + final long[] hash3 = MurmurHash3FFM.hash(in, seed); assertEquals(hash1, hash2); assertEquals(hash1, hash3); @@ -327,57 +327,57 @@ public void checkEmptiesNulls() { final long seed = 123; final long[] hashOut = new long[2]; try { - MurmurHash3FFM21.hash(MemorySegment.ofArray(new long[0]), 0, 0, seed, hashOut); //seg empty + MurmurHash3FFM.hash(MemorySegment.ofArray(new long[0]), 0, 0, seed, hashOut); //seg empty fail(); } catch (final IllegalArgumentException e) { } //OK try { final String s = ""; - MurmurHash3FFM21.hash(s, seed, hashOut); //string empty + MurmurHash3FFM.hash(s, seed, hashOut); //string empty fail(); } catch (final IllegalArgumentException e) { } //OK try { final String s = null; - MurmurHash3FFM21.hash(s, seed, hashOut); //string null + MurmurHash3FFM.hash(s, seed, hashOut); //string null fail(); } catch (final IllegalArgumentException e) { } //OK try { final byte[] barr = {}; - MurmurHash3FFM21.hash(barr, seed); //byte[] empty + MurmurHash3FFM.hash(barr, seed); //byte[] empty fail(); } catch (final IllegalArgumentException e) { } //OK try { final byte[] barr = null; - MurmurHash3FFM21.hash(barr, seed); //byte[] null + MurmurHash3FFM.hash(barr, seed); //byte[] null fail(); } catch (final IllegalArgumentException e) { } //OK try { final char[] carr = {}; - MurmurHash3FFM21.hash(carr, seed); //char[] empty + MurmurHash3FFM.hash(carr, seed); //char[] empty fail(); } catch (final IllegalArgumentException e) { } //OK try { final char[] carr = null; - MurmurHash3FFM21.hash(carr, seed); //char[] null + MurmurHash3FFM.hash(carr, seed); //char[] null fail(); } catch (final IllegalArgumentException e) { } //OK try { final int[] iarr = {}; - MurmurHash3FFM21.hash(iarr, seed); //int[] empty + MurmurHash3FFM.hash(iarr, seed); //int[] empty fail(); } catch (final IllegalArgumentException e) { } //OK try { final int[] iarr = null; - MurmurHash3FFM21.hash(iarr, seed); //int[] null + MurmurHash3FFM.hash(iarr, seed); //int[] null fail(); } catch (final IllegalArgumentException e) { } //OK try { final long[] larr = {}; - MurmurHash3FFM21.hash(larr, seed); //long[] empty + MurmurHash3FFM.hash(larr, seed); //long[] empty fail(); } catch (final IllegalArgumentException e) { } //OK try { final long[] larr = null; - MurmurHash3FFM21.hash(larr, seed); //long[] null + MurmurHash3FFM.hash(larr, seed); //long[] null fail(); } catch (final IllegalArgumentException e) { } //OK } @@ -387,9 +387,9 @@ public void checkStringLong() { final long seed = 123; final long[] hashOut = new long[2]; final String s = "123"; - assertTrue(MurmurHash3FFM21.hash(s, seed, hashOut)[0] != 0); + assertTrue(MurmurHash3FFM.hash(s, seed, hashOut)[0] != 0); final long v = 123; - assertTrue(MurmurHash3FFM21.hash(v, seed, hashOut)[0] != 0); + assertTrue(MurmurHash3FFM.hash(v, seed, hashOut)[0] != 0); } @Test @@ -417,8 +417,8 @@ private static long[] checkDouble(final double dbl) { final MemorySegment wseg = MemorySegment.ofArray(dataArr); final long[] hash1 = MurmurHash3.hash(dataArr, 0); - hash2 = MurmurHash3FFM21.hash(wseg, offset, bytes, seed, hash2); - final long[] hash3 = MurmurHash3FFM21.hash(dbl, seed, hash2); + hash2 = MurmurHash3FFM.hash(wseg, offset, bytes, seed, hash2); + final long[] hash3 = MurmurHash3FFM.hash(dbl, seed, hash2); assertEquals(hash1, hash2); assertEquals(hash1, hash3); diff --git a/src/test/java/org/apache/datasketches/hash/MurmurHash3FFM21bTest.java b/src/test/java/org/apache/datasketches/hash/MurmurHash3FFMbTest.java similarity index 98% rename from src/test/java/org/apache/datasketches/hash/MurmurHash3FFM21bTest.java rename to src/test/java/org/apache/datasketches/hash/MurmurHash3FFMbTest.java index 867f4a126..ab61a33a2 100644 --- a/src/test/java/org/apache/datasketches/hash/MurmurHash3FFM21bTest.java +++ b/src/test/java/org/apache/datasketches/hash/MurmurHash3FFMbTest.java @@ -20,7 +20,7 @@ package org.apache.datasketches.hash; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.datasketches.hash.MurmurHash3FFM21.hash; +import static org.apache.datasketches.hash.MurmurHash3FFM.hash; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -36,7 +36,7 @@ * * @author Lee Rhodes */ -public class MurmurHash3FFM21bTest { +public class MurmurHash3FFMbTest { @Test public void checkByteArrRemainderGT8() { //byte[], remainder > 8 @@ -195,7 +195,7 @@ public void checkByteArrAllOnesZeros() { //byte[], test a ones byte and a zeros 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67, (byte) 0xff, 0x64, 0x6f, 0x67, 0x00 }; - final long[] result = MurmurHash3FFM21.hash(key, 0); + final long[] result = MurmurHash3FFM.hash(key, 0); //Should be: final long h1 = 0xe88abda785929c9eL; final long h2 = 0x96b98587cacc83d6L; diff --git a/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java b/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java index d40cd3723..45fb4d8c9 100644 --- a/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java +++ b/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java @@ -41,9 +41,9 @@ import org.apache.datasketches.kll.KllHeapItemsSketch; import org.apache.datasketches.kll.KllItemsSketch; import org.apache.datasketches.kll.KllLongsSketch; -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; import org.apache.datasketches.quantilescommon.QuantilesFloatsSketchIterator; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; import org.testng.annotations.Test; /** @@ -156,7 +156,7 @@ public void kllDouble() throws IOException { assertEquals(sketch.getMinItem(), 1); assertEquals(sketch.getMaxItem(), n); long weight = 0; - final QuantilesDoublesSketchIterator it = sketch.iterator(); + final QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); while (it.next()) { assertTrue(it.getQuantile() >= sketch.getMinItem()); assertTrue(it.getQuantile() <= sketch.getMaxItem()); @@ -198,7 +198,7 @@ public int compare(final String s1, final String s2) { assertEquals(sketch.getMinItem(), Integer.toString(1)); assertEquals(sketch.getMaxItem(), Integer.toString(n)); long weight = 0; - final QuantilesGenericSketchIterator it = sketch.iterator(); + final QuantilesGenericSketchIteratorAPI it = sketch.iterator(); while (it.next()) { assertTrue(numericOrder.compare(it.getQuantile(), sketch.getMinItem()) >= 0); assertTrue(numericOrder.compare(it.getQuantile(), sketch.getMaxItem()) <= 0); diff --git a/src/test/java/org/apache/datasketches/kll/KllDirectCompactItemsSketchIteratorTest.java b/src/test/java/org/apache/datasketches/kll/KllDirectCompactItemsSketchIteratorTest.java index 74d3d5448..a41eb321e 100644 --- a/src/test/java/org/apache/datasketches/kll/KllDirectCompactItemsSketchIteratorTest.java +++ b/src/test/java/org/apache/datasketches/kll/KllDirectCompactItemsSketchIteratorTest.java @@ -34,7 +34,7 @@ import org.apache.datasketches.kll.KllItemsSketch; import org.apache.datasketches.quantilescommon.GenericSortedViewIterator; import org.apache.datasketches.quantilescommon.ItemsSketchSortedView; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; import org.testng.Assert; import org.testng.annotations.Test; @@ -48,7 +48,7 @@ public void emptySketch() { final byte[] byteArr = sk.toByteArray(); final KllItemsSketch sk2 = KllItemsSketch.wrap(MemorySegment.ofArray(byteArr), Comparator.naturalOrder(), serDe); assertTrue(sk2 instanceof KllDirectCompactItemsSketch); - final QuantilesGenericSketchIterator itr = sk2.iterator(); + final QuantilesGenericSketchIteratorAPI itr = sk2.iterator(); assertFalse(itr.next()); } @@ -59,7 +59,7 @@ public void oneItemSketch() { final byte[] byteArr = sk.toByteArray(); final KllItemsSketch sk2 = KllItemsSketch.wrap(MemorySegment.ofArray(byteArr), Comparator.naturalOrder(), serDe); assertTrue(sk2 instanceof KllDirectCompactItemsSketch); - final QuantilesGenericSketchIterator itr = sk2.iterator(); + final QuantilesGenericSketchIteratorAPI itr = sk2.iterator(); assertTrue(itr.next()); assertEquals(itr.getQuantile(), "1"); assertEquals(itr.getWeight(), 1); @@ -74,7 +74,7 @@ public void twoItemSketchForIterator() { final byte[] byteArr = sk.toByteArray(); final KllItemsSketch sk2 = KllItemsSketch.wrap(MemorySegment.ofArray(byteArr), Comparator.naturalOrder(), serDe); assertTrue(sk2 instanceof KllDirectCompactItemsSketch); - final QuantilesGenericSketchIterator itr = sk2.iterator(); + final QuantilesGenericSketchIteratorAPI itr = sk2.iterator(); assertTrue(itr.next()); assertEquals(itr.getQuantile(), "2"); @@ -128,7 +128,7 @@ public void bigSketches() { final byte[] byteArr = sk.toByteArray(); final KllItemsSketch sk2 = KllItemsSketch.wrap(MemorySegment.ofArray(byteArr), Comparator.naturalOrder(), serDe); assertTrue(sk2 instanceof KllDirectCompactItemsSketch); - final QuantilesGenericSketchIterator itr = sk2.iterator(); + final QuantilesGenericSketchIteratorAPI itr = sk2.iterator(); int count = 0; int weight = 0; while (itr.next()) { diff --git a/src/test/java/org/apache/datasketches/kll/KllDirectDoublesSketchIteratorTest.java b/src/test/java/org/apache/datasketches/kll/KllDirectDoublesSketchIteratorTest.java index 20afe16b2..06a0b8ce1 100644 --- a/src/test/java/org/apache/datasketches/kll/KllDirectDoublesSketchIteratorTest.java +++ b/src/test/java/org/apache/datasketches/kll/KllDirectDoublesSketchIteratorTest.java @@ -23,7 +23,7 @@ import org.apache.datasketches.kll.KllDoublesSketch; import org.apache.datasketches.kll.KllHelper; -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; import org.testng.Assert; import org.testng.annotations.Test; @@ -32,7 +32,7 @@ public class KllDirectDoublesSketchIteratorTest { @Test public void emptySketch() { final KllDoublesSketch sketch = getDDSketch(200, 0); - final QuantilesDoublesSketchIterator it = sketch.iterator(); + final QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); Assert.assertFalse(it.next()); } @@ -40,7 +40,7 @@ public void emptySketch() { public void oneItemSketch() { final KllDoublesSketch sketch = getDDSketch(200, 0); sketch.update(0); - final QuantilesDoublesSketchIterator it = sketch.iterator(); + final QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); Assert.assertTrue(it.next()); Assert.assertEquals(it.getQuantile(), 0); Assert.assertEquals(it.getWeight(), 1); @@ -54,7 +54,7 @@ public void bigSketches() { for (int i = 0; i < n; i++) { sketch.update(i); } - final QuantilesDoublesSketchIterator it = sketch.iterator(); + final QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); int count = 0; int weight = 0; while (it.next()) { diff --git a/src/test/java/org/apache/datasketches/kll/KllDoublesSketchIteratorTest.java b/src/test/java/org/apache/datasketches/kll/KllDoublesSketchIteratorTest.java index 2abb30022..ff66caccd 100644 --- a/src/test/java/org/apache/datasketches/kll/KllDoublesSketchIteratorTest.java +++ b/src/test/java/org/apache/datasketches/kll/KllDoublesSketchIteratorTest.java @@ -26,7 +26,7 @@ import org.apache.datasketches.kll.KllDoublesSketch; import org.apache.datasketches.quantilescommon.DoublesSortedViewIterator; -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; import org.testng.Assert; import org.testng.annotations.Test; @@ -35,7 +35,7 @@ public class KllDoublesSketchIteratorTest { @Test public void emptySketch() { KllDoublesSketch sketch = KllDoublesSketch.newHeapInstance(); - QuantilesDoublesSketchIterator it = sketch.iterator(); + QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); Assert.assertFalse(it.next()); } @@ -43,7 +43,7 @@ public void emptySketch() { public void oneItemSketch() { KllDoublesSketch sketch = KllDoublesSketch.newHeapInstance(); sketch.update(1); - QuantilesDoublesSketchIterator it = sketch.iterator(); + QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); Assert.assertTrue(it.next()); Assert.assertEquals(it.getQuantile(), 1.0); Assert.assertEquals(it.getWeight(), 1); @@ -55,7 +55,7 @@ public void twoItemSketchForIterator() { KllDoublesSketch sketch = KllDoublesSketch.newHeapInstance(); sketch.update(1); sketch.update(2); - QuantilesDoublesSketchIterator itr = sketch.iterator(); + QuantilesDoublesSketchIteratorAPI itr = sketch.iterator(); assertTrue(itr.next()); assertEquals(itr.getQuantile(), 2.0); @@ -100,7 +100,7 @@ public void bigSketches() { for (int i = 0; i < n; i++) { sketch.update(i); } - QuantilesDoublesSketchIterator it = sketch.iterator(); + QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); int count = 0; int weight = 0; while (it.next()) { diff --git a/src/test/java/org/apache/datasketches/kll/KllItemsSketchTest.java b/src/test/java/org/apache/datasketches/kll/KllItemsSketchTest.java index c249961a8..193c1e502 100644 --- a/src/test/java/org/apache/datasketches/kll/KllItemsSketchTest.java +++ b/src/test/java/org/apache/datasketches/kll/KllItemsSketchTest.java @@ -51,7 +51,7 @@ import org.apache.datasketches.kll.KllSketch.SketchType; import org.apache.datasketches.quantilescommon.GenericSortedView; import org.apache.datasketches.quantilescommon.GenericSortedViewIterator; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; import org.testng.annotations.Test; public class KllItemsSketchTest { @@ -767,7 +767,7 @@ public void checkL0SortDuringMergeIssue527() throws NumberFormatException { sk1.merge(sk2); println(sk1.toString(true, true)); //L1 and above should be sorted in reverse. Ignore L0. final int lvl1size = sk1.levelsArr[2] - sk1.levelsArr[1]; - final QuantilesGenericSketchIterator itr = sk1.iterator(); + final QuantilesGenericSketchIteratorAPI itr = sk1.iterator(); itr.next(); int prev = Integer.parseInt(itr.getQuantile().trim()); for (int i = 1; i < lvl1size; i++) { diff --git a/src/test/java/org/apache/datasketches/kll/KllItemsSketchiteratorTest.java b/src/test/java/org/apache/datasketches/kll/KllItemsSketchiteratorTest.java index 2533802ac..1e8623b47 100644 --- a/src/test/java/org/apache/datasketches/kll/KllItemsSketchiteratorTest.java +++ b/src/test/java/org/apache/datasketches/kll/KllItemsSketchiteratorTest.java @@ -30,7 +30,7 @@ import org.apache.datasketches.common.Util; import org.apache.datasketches.kll.KllItemsSketch; import org.apache.datasketches.quantilescommon.GenericSortedViewIterator; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; import org.testng.Assert; import org.testng.annotations.Test; @@ -40,7 +40,7 @@ public class KllItemsSketchiteratorTest { @Test public void emptySketch() { final KllItemsSketch sketch = KllItemsSketch.newHeapInstance(Comparator.naturalOrder(), serDe); - final QuantilesGenericSketchIterator it = sketch.iterator(); + final QuantilesGenericSketchIteratorAPI it = sketch.iterator(); Assert.assertFalse(it.next()); } @@ -48,7 +48,7 @@ public void emptySketch() { public void oneItemSketch() { final KllItemsSketch sketch = KllItemsSketch.newHeapInstance(Comparator.naturalOrder(), serDe); sketch.update("1"); - final QuantilesGenericSketchIterator it = sketch.iterator(); + final QuantilesGenericSketchIteratorAPI it = sketch.iterator(); Assert.assertTrue(it.next()); Assert.assertEquals(it.getQuantile(), "1"); Assert.assertEquals(it.getWeight(), 1); @@ -60,7 +60,7 @@ public void twoItemSketchForIterator() { final KllItemsSketch sketch = KllItemsSketch.newHeapInstance(Comparator.naturalOrder(), serDe); sketch.update("1"); sketch.update("2"); - final QuantilesGenericSketchIterator itr = sketch.iterator(); + final QuantilesGenericSketchIteratorAPI itr = sketch.iterator(); assertTrue(itr.next()); assertEquals(itr.getQuantile(), "2"); @@ -106,7 +106,7 @@ public void bigSketches() { for (int i = 0; i < n; i++) { sketch.update(Util.longToFixedLengthString(i, digits)); } - final QuantilesGenericSketchIterator it = sketch.iterator(); + final QuantilesGenericSketchIteratorAPI it = sketch.iterator(); int count = 0; int weight = 0; while (it.next()) { diff --git a/src/test/java/org/apache/datasketches/partitions/ClassicPartitionsTest.java b/src/test/java/org/apache/datasketches/partitions/ClassicPartitionsTest.java index 52e6c50d7..5175ecab0 100644 --- a/src/test/java/org/apache/datasketches/partitions/ClassicPartitionsTest.java +++ b/src/test/java/org/apache/datasketches/partitions/ClassicPartitionsTest.java @@ -27,7 +27,7 @@ import org.apache.datasketches.common.SketchesArgumentException; import org.apache.datasketches.partitions.Partitioner.PartitionBoundsRow; -import org.apache.datasketches.quantiles.ItemsSketch; +import org.apache.datasketches.quantiles.QuantilesItemsSketch; import org.apache.datasketches.quantilescommon.QuantileSearchCriteria; import org.testng.annotations.Test; @@ -94,9 +94,9 @@ public void classicPartitioner( final long startTime_mS = System.currentTimeMillis(); final ItemsSketchFillRequestLongAsString fillReq = new ItemsSketchFillRequestLongAsString(k, totalN); - final ItemsSketch sk = fillReq.getRange(1L, totalN, INCLUDE_BOTH); + final QuantilesItemsSketch sk = fillReq.getRange(1L, totalN, INCLUDE_BOTH); final long endFillInitialSketchTime_mS = System.currentTimeMillis(); - final Partitioner> partitioner = new Partitioner<>( + final Partitioner> partitioner = new Partitioner<>( tgtPartitionSize, maxPartsPerSk, fillReq, diff --git a/src/test/java/org/apache/datasketches/partitions/ItemsSketchFillRequestLongAsString.java b/src/test/java/org/apache/datasketches/partitions/ItemsSketchFillRequestLongAsString.java index 9f3cfb9fb..8e39ba55f 100644 --- a/src/test/java/org/apache/datasketches/partitions/ItemsSketchFillRequestLongAsString.java +++ b/src/test/java/org/apache/datasketches/partitions/ItemsSketchFillRequestLongAsString.java @@ -27,13 +27,13 @@ import java.util.Comparator; import org.apache.datasketches.common.SketchesArgumentException; -import org.apache.datasketches.quantiles.ItemsSketch; +import org.apache.datasketches.quantiles.QuantilesItemsSketch; /** * This is an simulated data set with a given N used for testing. * @author Lee Rhodes */ -public class ItemsSketchFillRequestLongAsString implements SketchFillRequest> { +public class ItemsSketchFillRequestLongAsString implements SketchFillRequest> { private int k; private int numDigits; @@ -48,9 +48,9 @@ public ItemsSketchFillRequestLongAsString(final int k, final long totalN) { } @Override - public ItemsSketch getRange(final String lowerQuantile, final String upperQuantile, + public QuantilesItemsSketch getRange(final String lowerQuantile, final String upperQuantile, final BoundsRule bounds) { - final ItemsSketch sk = ItemsSketch.getInstance(String.class, k, Comparator.naturalOrder()); + final QuantilesItemsSketch sk = QuantilesItemsSketch.getInstance(String.class, k, Comparator.naturalOrder()); long upper, lower; try { lower = Long.parseLong(lowerQuantile.trim()); @@ -66,8 +66,8 @@ public ItemsSketch getRange(final String lowerQuantile, final String upp return sk; } - public ItemsSketch getRange(final long lowerQuantile, final long upperQuantile, final BoundsRule bounds) { - final ItemsSketch sk = ItemsSketch.getInstance(String.class, k, Comparator.naturalOrder()); + public QuantilesItemsSketch getRange(final long lowerQuantile, final long upperQuantile, final BoundsRule bounds) { + final QuantilesItemsSketch sk = QuantilesItemsSketch.getInstance(String.class, k, Comparator.naturalOrder()); final long lower = lowerQuantile; final long upper = upperQuantile; if (bounds == INCLUDE_BOTH) { diff --git a/src/test/java/org/apache/datasketches/partitions/PartitionResults.java b/src/test/java/org/apache/datasketches/partitions/PartitionResults.java index b061ce921..65d8a2ba8 100644 --- a/src/test/java/org/apache/datasketches/partitions/PartitionResults.java +++ b/src/test/java/org/apache/datasketches/partitions/PartitionResults.java @@ -74,7 +74,7 @@ public static void output( final double rmsRelErr = sqrt(normMeanSqErr); //a.k.a. Normalized RMS Error or NRMSE final double maxAbsErrFraction = maxAbsErr / meanPartSize; - println(LS + sketchType +" ItemsSketch Partitions Test"); + println(LS + sketchType + " Generic Quantiles Sketch Partitions Test"); println(LS + "INPUT:"); printf("Sketch K :%,20d\n", k); printf("Search Criteria :%20s\n", searchCrit.name()); diff --git a/src/test/java/org/apache/datasketches/quantiles/AccuracyTest.java b/src/test/java/org/apache/datasketches/quantiles/AccuracyTest.java index 015a4fbe5..2fed90dc8 100644 --- a/src/test/java/org/apache/datasketches/quantiles/AccuracyTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/AccuracyTest.java @@ -41,7 +41,7 @@ public void baseTest() { } double[] randArr = seqArr.clone(); shuffle(randArr); - UpdateDoublesSketch sketch = DoublesSketch.builder().setK(k).build(); + UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = 0; i < n; i++) { sketch.update(randArr[i]); } diff --git a/src/test/java/org/apache/datasketches/quantiles/ClassicQuantilesMemorySegmentRequestApp.java b/src/test/java/org/apache/datasketches/quantiles/ClassicQuantilesMemorySegmentRequestApp.java index cfd4f61e1..6e96578ca 100644 --- a/src/test/java/org/apache/datasketches/quantiles/ClassicQuantilesMemorySegmentRequestApp.java +++ b/src/test/java/org/apache/datasketches/quantiles/ClassicQuantilesMemorySegmentRequestApp.java @@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import org.apache.datasketches.common.MemorySegmentRequestExample; @@ -32,8 +31,8 @@ public class ClassicQuantilesMemorySegmentRequestApp { @Test /** - * This method emulates an application using an off-heap DoublesSketch that needs to expand off-heap. - * This demonstrates one example of how to manage a growing off-heap DoublesSketch where the + * This method emulates an application using an off-heap QuantilesDoublesSketch that needs to expand off-heap. + * This demonstrates one example of how to manage a growing off-heap QuantilesDoublesSketch where the * expanded MemorySegments are also off-heap. */ public void checkMemorySegmentRequestExample() { @@ -43,14 +42,14 @@ public void checkMemorySegmentRequestExample() { //Use the custom MemorySegmentRequestExample to do the allocations. final MemorySegmentRequestExample mSegReqEx = new MemorySegmentRequestExample(); - //The allocation of the original off-heap MemorySegment for the DoublesSketch + //The allocation of the original off-heap MemorySegment for the QuantilesDoublesSketch //Note that this targets the size to only handle 2k values, which is quite small. - final int initalBytes = DoublesSketch.getUpdatableStorageBytes(k, 2 * k); + final int initalBytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k, 2 * k); final MemorySegment seg = mSegReqEx.request(initalBytes); //Create a new KllLongsSketch and pass the mSegReqEx - final DoublesSketch sk = DoublesSketch.builder().setK(k).build(seg, mSegReqEx); + final QuantilesDoublesSketch sk = QuantilesDoublesSketch.builder().setK(k).build(seg, mSegReqEx); //Update the sketch with way more data than the original MemorySegment can handle, forcing it to request larger MemorySegments. for (int n = 1; n <= itemsIn; n++) { sk.update(n); } diff --git a/src/test/java/org/apache/datasketches/quantiles/CustomQuantilesTest.java b/src/test/java/org/apache/datasketches/quantiles/CustomQuantilesTest.java index 101c26cdd..d0816c4dc 100644 --- a/src/test/java/org/apache/datasketches/quantiles/CustomQuantilesTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/CustomQuantilesTest.java @@ -32,7 +32,7 @@ public class CustomQuantilesTest { /** - * Currently, this test only exercises the classic DoublesSketch, but all the quantiles + * Currently, this test only exercises the classic QuantilesDoublesSketch, but all the quantiles * sketches use the same code for getQuantile() and getRank() anyway. * This same pattern is also part of the CrossCheckQuantilesTest. * This structure of this test allows more detailed analysis for troubleshooting. @@ -49,7 +49,7 @@ public void checkQuantilesV400() { //quantiles sketches it is easier to create by loading the sorted view directly via //a package-private constructor. int k = 4; - UpdateDoublesSketch sk = DoublesSketch.builder().setK(k).build(); + UpdatableQuantilesDoublesSketch sk = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = 1; i <= 3; i++) { for (int q = 10; q <= k * 10; q += 10) { sk.update(q); diff --git a/src/test/java/org/apache/datasketches/quantiles/DebugUnionTest.java b/src/test/java/org/apache/datasketches/quantiles/DebugUnionTest.java index b7c70572c..cdc1f7a93 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DebugUnionTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DebugUnionTest.java @@ -27,7 +27,7 @@ import java.lang.foreign.MemorySegment; import java.util.HashSet; -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; import org.testng.annotations.Test; /** @@ -42,28 +42,28 @@ public void test() { final int numSketches = 3; final int sketchK = 8; final int unionK = 8; - final UpdateDoublesSketch[] sketchArr = new UpdateDoublesSketch[numSketches]; + final UpdatableQuantilesDoublesSketch[] sketchArr = new UpdatableQuantilesDoublesSketch[numSketches]; //builds the input sketches, all on heap - DoublesSketch.setRandom(1); //make deterministic for test + QuantilesDoublesSketch.setRandom(1); //make deterministic for test final HashSet set = new HashSet<>(); //holds input values for (int s = 0; s < numSketches; s++) { sketchArr[s] = buildHeapSketch(sketchK, n, valueLimit, set); } //loads the on heap union - DoublesSketch.setRandom(1); //make deterministic for test - final DoublesUnion hUnion = DoublesUnion.builder().setMaxK(unionK).build(); + QuantilesDoublesSketch.setRandom(1); //make deterministic for test + final QuantilesDoublesUnion hUnion = QuantilesDoublesUnion.builder().setMaxK(unionK).build(); for (int s = 0; s < numSketches; s++) { hUnion.union(sketchArr[s]); } - final DoublesSketch hSketch = hUnion.getResult(); + final QuantilesDoublesSketch hSketch = hUnion.getResult(); //loads the direct union - DoublesSketch.setRandom(1); //make deterministic for test - DoublesUnion dUnion; - DoublesSketch dSketch; + QuantilesDoublesSketch.setRandom(1); //make deterministic for test + QuantilesDoublesUnion dUnion; + QuantilesDoublesSketch dSketch; try (Arena arena = Arena.ofConfined()) { final MemorySegment wseg = arena.allocate(10_000_000); - dUnion = DoublesUnion.builder().setMaxK(8).build(wseg, null); + dUnion = QuantilesDoublesUnion.builder().setMaxK(8).build(wseg, null); for (int s = 0; s < numSketches; s++) { dUnion.union(sketchArr[s]); } dSketch = dUnion.getResult(); //result is on heap } catch (final Exception e) { @@ -79,8 +79,8 @@ public void test() { int hErrors = 0; int dErrors = 0; - final QuantilesDoublesSketchIterator hit = hSketch.iterator(); - final QuantilesDoublesSketchIterator dit = dSketch.iterator(); + final QuantilesDoublesSketchIteratorAPI hit = hSketch.iterator(); + final QuantilesDoublesSketchIteratorAPI dit = dSketch.iterator(); while (hit.next() && dit.next()) { final double v = hit.getQuantile(); @@ -100,11 +100,11 @@ public void test() { //println(dSketch.toString(true, true)); } - private static UpdateDoublesSketch buildHeapSketch(final int k, final int n, final int valueLimit, + private static UpdatableQuantilesDoublesSketch buildHeapSketch(final int k, final int n, final int valueLimit, final HashSet set) { - final UpdateDoublesSketch uSk = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch uSk = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = 0; i < n; i++) { - final double value = DoublesSketch.rand.nextInt(valueLimit) + 1; + final double value = QuantilesDoublesSketch.rand.nextInt(valueLimit) + 1; uSk.update(value); set.add(value); } diff --git a/src/test/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketchTest.java index 973b42846..4e8d405c8 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketchTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketchTest.java @@ -38,14 +38,14 @@ public class DirectCompactDoublesSketchTest { @BeforeMethod public void setUp() { - DoublesSketch.rand.setSeed(32749); // make sketches deterministic for testing + QuantilesDoublesSketch.rand.setSeed(32749); // make sketches deterministic for testing } @Test(expectedExceptions = SketchesArgumentException.class) public void wrapFromUpdateSketch() { final int k = 4; final int n = 27; - final UpdateDoublesSketch qs = HeapUpdateDoublesSketchTest.buildAndLoadQS(k, n); + final UpdatableQuantilesDoublesSketch qs = HeapUpdateDoublesSketchTest.buildAndLoadQS(k, n); final byte[] qsBytes = qs.toByteArray(); final MemorySegment qsSeg = MemorySegment.ofArray(qsBytes); @@ -58,7 +58,7 @@ public void wrapFromUpdateSketch() { public void createFromUnsortedUpdateSketch() { final int k = 4; final int n = 13; - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = n; i > 0; --i) { qs.update(i); } @@ -94,10 +94,10 @@ public void wrapFromCompactSketch() { @Test public void wrapEmptyCompactSketch() { - final CompactDoublesSketch s1 = DoublesSketch.builder().build().compact(); + final CompactQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build().compact(); final MemorySegment seg = MemorySegment.ofBuffer(ByteBuffer.wrap(s1.toByteArray()).order(ByteOrder.nativeOrder())); - final DoublesSketch s2 = DoublesSketch.wrap(seg); + final QuantilesDoublesSketch s2 = QuantilesDoublesSketch.wrap(seg); assertTrue(s2.isEmpty()); assertEquals(s2.getN(), 0); assertTrue(Double.isNaN(s2.isEmpty() ? Double.NaN : s2.getMinItem())); @@ -141,7 +141,7 @@ static DirectCompactDoublesSketch buildAndLoadDCQS(final int k, final int n) { } static DirectCompactDoublesSketch buildAndLoadDCQS(final int k, final int n, final int startV) { - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = 1; i <= n; i++) { qs.update(startV + i); } diff --git a/src/test/java/org/apache/datasketches/quantiles/DirectQuantilesMemoryRequestTest.java b/src/test/java/org/apache/datasketches/quantiles/DirectQuantilesMemoryRequestTest.java index 060e28f00..2b37b00a4 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DirectQuantilesMemoryRequestTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DirectQuantilesMemoryRequestTest.java @@ -53,7 +53,7 @@ public void checkLimitedMemoryScenarios() { //Requesting application //########## Receiving Application // The receiving application has been given wseg to use for a sketch, // but alas, it is not ultimately large enough. - final UpdateDoublesSketch usk = DoublesSketch.builder().setK(k).build(wseg); + final UpdatableQuantilesDoublesSketch usk = QuantilesDoublesSketch.builder().setK(k).build(wseg); assertTrue(usk.isEmpty()); //Load the sketch @@ -84,7 +84,7 @@ public void checkGrowBaseBuf() { try (Arena arena = Arena.ofConfined()) { wseg = arena.allocate(initBytes); println("Initial seg size: " + wseg.byteSize()); - final UpdateDoublesSketch usk1 = DoublesSketch.builder().setK(k).build(wseg); + final UpdatableQuantilesDoublesSketch usk1 = QuantilesDoublesSketch.builder().setK(k).build(wseg); for (int i = 1; i <= u; i++) { usk1.update(i); } @@ -105,7 +105,7 @@ public void checkGrowCombBuf() { try (Arena arena = Arena.ofConfined()) { wseg = arena.allocate(initBytes); println("Initial seg size: " + wseg.byteSize()); - final UpdateDoublesSketch usk1 = DoublesSketch.builder().setK(k).build(wseg); + final UpdatableQuantilesDoublesSketch usk1 = QuantilesDoublesSketch.builder().setK(k).build(wseg); for (int i = 1; i <= u; i++) { usk1.update(i); } @@ -123,9 +123,9 @@ public void checkGrowCombBuf() { @Test public void checkUpdatableStorageBytes() { final int k = 16; - final int initBytes = DoublesSketch.getUpdatableStorageBytes(k, 1); + final int initBytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k, 1); println("Predicted Updatable Storage Bytes: " + initBytes); - final UpdateDoublesSketch usk1 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch usk1 = QuantilesDoublesSketch.builder().setK(k).build(); usk1.update(1.0); final byte[] uarr = usk1.toByteArray(); println("Actual Storage Bytes " + uarr.length); @@ -138,14 +138,14 @@ public void checkUpdatableStorageBytes() { public void checkGrowFromWrappedEmptySketch() { final int k = 16; final int n = 0; - final int initBytes = DoublesSketch.getUpdatableStorageBytes(k, n); //empty: 8 bytes - final UpdateDoublesSketch usk1 = DoublesSketch.builder().setK(k).build(); + final int initBytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k, n); //empty: 8 bytes + final UpdatableQuantilesDoublesSketch usk1 = QuantilesDoublesSketch.builder().setK(k).build(); final MemorySegment origSketchSeg = MemorySegment.ofArray(usk1.toByteArray()); //on heap MemorySegment wseg; try (Arena arena = Arena.ofConfined()) { wseg = arena.allocate(initBytes); //off heap MemorySegment.copy(origSketchSeg, 0, wseg, 0, initBytes); - final UpdateDoublesSketch usk2 = DirectUpdateDoublesSketch.wrapInstance(wseg, null); + final UpdatableQuantilesDoublesSketch usk2 = DirectUpdateDoublesSketch.wrapInstance(wseg, null); assertTrue(isSameResource(wseg, usk2.getMemorySegment())); assertEquals(wseg.byteSize(), initBytes); assertTrue(wseg.isNative()); diff --git a/src/test/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchTest.java index 17c7b0384..088b4462c 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchTest.java @@ -40,16 +40,16 @@ public class DirectUpdateDoublesSketchTest { @BeforeMethod public void setUp() { - DoublesSketch.rand.setSeed(32749); // make sketches deterministic for testing + QuantilesDoublesSketch.rand.setSeed(32749); // make sketches deterministic for testing } @Test public void checkSmallMinMax () { final int k = 32; final int n = 8; - final UpdateDoublesSketch qs1 = buildDQS(k, n); - final UpdateDoublesSketch qs2 = buildDQS(k, n); - final UpdateDoublesSketch qs3 = buildDQS(k, n); + final UpdatableQuantilesDoublesSketch qs1 = buildDQS(k, n); + final UpdatableQuantilesDoublesSketch qs2 = buildDQS(k, n); + final UpdatableQuantilesDoublesSketch qs3 = buildDQS(k, n); for (int i = n; i >= 1; i--) { qs1.update(i); @@ -75,13 +75,13 @@ public void checkSmallMinMax () { assertEquals(resultsA[1], 5.0); assertEquals(resultsA[2], 8.0); - final DoublesUnion union1 = DoublesUnion.heapify(qs1); + final QuantilesDoublesUnion union1 = QuantilesDoublesUnion.heapify(qs1); union1.union(qs2); - final DoublesSketch result1 = union1.getResult(); + final QuantilesDoublesSketch result1 = union1.getResult(); - final DoublesUnion union2 = DoublesUnion.heapify(qs2); + final QuantilesDoublesUnion union2 = QuantilesDoublesUnion.heapify(qs2); union2.union(qs3); - final DoublesSketch result2 = union2.getResult(); + final QuantilesDoublesSketch result2 = union2.getResult(); final double[] resultsB = result1.getQuantiles(queries, EXCLUSIVE); printResults(resultsB); @@ -101,9 +101,9 @@ static void printResults(final double[] results) { @Test public void wrapEmptyUpdateSketch() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); final MemorySegment seg = MemorySegment.ofBuffer(ByteBuffer.wrap(s1.toByteArray()).order(ByteOrder.nativeOrder())); - final UpdateDoublesSketch s2 = DirectUpdateDoublesSketch.wrapInstance(seg, null); + final UpdatableQuantilesDoublesSketch s2 = DirectUpdateDoublesSketch.wrapInstance(seg, null); assertTrue(s2.isEmpty()); assertEquals(s2.getN(), 0); @@ -119,7 +119,7 @@ public void checkPutCombinedBuffer() { final int k = PreambleUtil.DEFAULT_K; final int cap = 32 + ((2 * k) << 3); MemorySegment seg = MemorySegment.ofArray(new byte[cap]); - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(seg); + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(seg); seg = qs.getMemorySegment(); assertEquals(seg.byteSize(), cap); assertTrue(qs.isEmpty()); @@ -147,7 +147,7 @@ public void checkMisc() { final int n = 48; final int cap = 32 + ((2 * k) << 3); MemorySegment seg = MemorySegment.ofArray(new byte[cap]); - UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(seg); + UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(seg); seg = qs.getMemorySegment(); assertEquals(seg.byteSize(), cap); double[] combBuf = qs.getCombinedBuffer(); @@ -213,14 +213,14 @@ public void checkCheckDirectSegCapacity() { @Test public void serializeDeserialize() { - final int sizeBytes = DoublesSketch.getUpdatableStorageBytes(128, 2000); + final int sizeBytes = QuantilesDoublesSketch.getUpdatableStorageBytes(128, 2000); final MemorySegment seg = MemorySegment.ofArray(new byte[sizeBytes]); - final UpdateDoublesSketch sketch1 = DoublesSketch.builder().build(seg); + final UpdatableQuantilesDoublesSketch sketch1 = QuantilesDoublesSketch.builder().build(seg); for (int i = 0; i < 1000; i++) { sketch1.update(i); } - final UpdateDoublesSketch sketch2 = UpdateDoublesSketch.wrap(seg, null); + final UpdatableQuantilesDoublesSketch sketch2 = UpdatableQuantilesDoublesSketch.wrap(seg, null); for (int i = 0; i < 1000; i++) { sketch2.update(i + 1000); } @@ -230,7 +230,7 @@ public void serializeDeserialize() { final byte[] arr2 = sketch2.toByteArray(false); assertEquals(arr2.length, sketch2.getSerializedSizeBytes()); - final DoublesSketch sketch3 = DoublesSketch.writableWrap(MemorySegment.ofArray(arr2), null); + final QuantilesDoublesSketch sketch3 = QuantilesDoublesSketch.writableWrap(MemorySegment.ofArray(arr2), null); assertEquals(sketch3.getMinItem(), 0.0); assertEquals(sketch3.getMaxItem(), 1999.0); assertEquals(sketch3.getQuantile(0.5), 1000.0, 10.0); @@ -238,12 +238,12 @@ public void serializeDeserialize() { @Test public void mergeTest() { - final DoublesSketch dqs1 = buildAndLoadDQS(128, 256); - final DoublesSketch dqs2 = buildAndLoadDQS(128, 256, 256); - final DoublesUnion union = DoublesUnion.builder().setMaxK(128).build(); + final QuantilesDoublesSketch dqs1 = buildAndLoadDQS(128, 256); + final QuantilesDoublesSketch dqs2 = buildAndLoadDQS(128, 256, 256); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(128).build(); union.union(dqs1); union.union(dqs2); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); final double median = result.getQuantile(0.5); println("Median: " + median); assertEquals(median, 258.0, .05 * 258); @@ -254,10 +254,10 @@ public void checkSimplePropagateCarryDirect() { final int k = 16; final int n = k * 2; - final int segBytes = DoublesSketch.getUpdatableStorageBytes(k, n); + final int segBytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k, n); final MemorySegment seg = MemorySegment.ofArray(new byte[segBytes]); - final DoublesSketchBuilder bldr = DoublesSketch.builder(); - final UpdateDoublesSketch ds = bldr.setK(k).build(seg); + final QuantilesDoublesSketchBuilder bldr = QuantilesDoublesSketch.builder(); + final UpdatableQuantilesDoublesSketch ds = bldr.setK(k).build(seg); for (int i = 1; i <= n; i++) { // 1 ... n ds.update(i); } @@ -275,9 +275,9 @@ public void checkSimplePropagateCarryDirect() { public void getRankAndGetCdfConsistency() { final int k = 128; final int n = 1_000_000; - final int segBytes = DoublesSketch.getUpdatableStorageBytes(k, n); + final int segBytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k, n); final MemorySegment seg = MemorySegment.ofArray(new byte[segBytes]); - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(seg); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(seg); final double[] values = new double[n]; for (int i = 0; i < n; i++) { sketch.update(i); @@ -289,22 +289,22 @@ public void getRankAndGetCdfConsistency() { } } - static UpdateDoublesSketch buildAndLoadDQS(final int k, final int n) { + static UpdatableQuantilesDoublesSketch buildAndLoadDQS(final int k, final int n) { return buildAndLoadDQS(k, n, 0); } - static UpdateDoublesSketch buildAndLoadDQS(final int k, final long n, final int startV) { - final UpdateDoublesSketch qs = buildDQS(k, n); + static UpdatableQuantilesDoublesSketch buildAndLoadDQS(final int k, final long n, final int startV) { + final UpdatableQuantilesDoublesSketch qs = buildDQS(k, n); for (long i = 1; i <= n; i++) { qs.update(startV + i); } return qs; } - static UpdateDoublesSketch buildDQS(final int k, final long n) { - int cap = DoublesSketch.getUpdatableStorageBytes(k, n); + static UpdatableQuantilesDoublesSketch buildDQS(final int k, final long n) { + int cap = QuantilesDoublesSketch.getUpdatableStorageBytes(k, n); if (cap < (2 * k)) { cap = 2 * k; } - final DoublesSketchBuilder bldr = new DoublesSketchBuilder(); + final QuantilesDoublesSketchBuilder bldr = new QuantilesDoublesSketchBuilder(); bldr.setK(k); return bldr.build(MemorySegment.ofArray(new byte[cap])); } diff --git a/src/test/java/org/apache/datasketches/quantiles/DoublesMiscTest.java b/src/test/java/org/apache/datasketches/quantiles/DoublesMiscTest.java index 40b349d84..51d062564 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DoublesMiscTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DoublesMiscTest.java @@ -36,7 +36,7 @@ public class DoublesMiscTest { @Test public void wrapAndUpdating() { - final UpdateDoublesSketch sk1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sk1 = QuantilesDoublesSketch.builder().build(); sk1.update(1); sk1.update(2); final byte[] bytes = sk1.toByteArray(false); @@ -44,7 +44,7 @@ public void wrapAndUpdating() { Assert.assertEquals(bytes.length, curBytes); //convert to MemorySegment final MemorySegment seg = MemorySegment.ofArray(bytes); - final UpdateDoublesSketch sk2 = (UpdateDoublesSketch) DoublesSketch.writableWrap(seg, null); + final UpdatableQuantilesDoublesSketch sk2 = (UpdatableQuantilesDoublesSketch) QuantilesDoublesSketch.writableWrap(seg, null); assertEquals(seg.byteSize(), curBytes); sk2.update(3); sk2.update(4); @@ -52,16 +52,16 @@ public void wrapAndUpdating() { assertEquals(sk2.getMaxItem(), 4.0); //check the size for just 4 elements final MemorySegment seg2 = sk2.getMemorySegment(); - assertEquals(seg2.byteSize(), DoublesSketch.getUpdatableStorageBytes(sk2.getK(), sk2.getN())); + assertEquals(seg2.byteSize(), QuantilesDoublesSketch.getUpdatableStorageBytes(sk2.getK(), sk2.getN())); } @Test public void wrapCompactSketch() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.compact().toByteArray()); - final DoublesSketch s2 = DoublesSketch.wrap(seg); // compact, so this is ok + final QuantilesDoublesSketch s2 = QuantilesDoublesSketch.wrap(seg); // compact, so this is ok assertEquals(s2.getMinItem(), 1.0); assertEquals(s2.getMaxItem(), 2.0); assertEquals(s2.getN(), 2); @@ -69,22 +69,22 @@ public void wrapCompactSketch() { @Test public void heapifySparseSketch() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(false)); - final DoublesSketch s2 = DoublesSketch.heapify(seg); + final QuantilesDoublesSketch s2 = QuantilesDoublesSketch.heapify(seg); assertEquals(s2.getMinItem(), 1.0); assertEquals(s2.getMaxItem(), 2.0); } @Test public void heapifyAndUpdateSparseSketch() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(false)); - final UpdateDoublesSketch s2 = (UpdateDoublesSketch) DoublesSketch.heapify(seg); + final UpdatableQuantilesDoublesSketch s2 = (UpdatableQuantilesDoublesSketch) QuantilesDoublesSketch.heapify(seg); s2.update(3); assertEquals(s2.getMinItem(), 1.0); assertEquals(s2.getMaxItem(), 3.0); @@ -92,36 +92,36 @@ public void heapifyAndUpdateSparseSketch() { @Test public void heapifyCompactSketch() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(true)); - final DoublesSketch s2 = DoublesSketch.heapify(seg); + final QuantilesDoublesSketch s2 = QuantilesDoublesSketch.heapify(seg); assertEquals(s2.getMinItem(), 1.0); assertEquals(s2.getMaxItem(), 2.0); } @Test public void heapifyEmptyUpdateSketch() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray()); - final DoublesSketch s2 = DoublesSketch.heapify(seg); + final QuantilesDoublesSketch s2 = QuantilesDoublesSketch.heapify(seg); assertTrue(s2.isEmpty()); } @Test public void heapifyEmptyCompactSketch() { - final CompactDoublesSketch s1 = DoublesSketch.builder().build().compact(); + final CompactQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build().compact(); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray()); - final DoublesSketch s2 = DoublesSketch.heapify(seg); + final QuantilesDoublesSketch s2 = QuantilesDoublesSketch.heapify(seg); assertTrue(s2.isEmpty()); } @Test public void wrapEmptyUpdateSketch() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray()).asReadOnly(); - final UpdateDoublesSketch s2 = (UpdateDoublesSketch) DoublesSketch.writableWrap(seg, null); + final UpdatableQuantilesDoublesSketch s2 = (UpdatableQuantilesDoublesSketch) QuantilesDoublesSketch.writableWrap(seg, null); assertTrue(s2.isEmpty()); // ensure the various put calls fail @@ -185,59 +185,59 @@ public void wrapEmptyUpdateSketch() { @Test public void wrapEmptyCompactSketch() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); final MemorySegment seg = MemorySegment.ofArray(s1.compact().toByteArray()); - final DoublesSketch s2 = DoublesSketch.wrap(seg); // compact, so this is ok + final QuantilesDoublesSketch s2 = QuantilesDoublesSketch.wrap(seg); // compact, so this is ok Assert.assertTrue(s2.isEmpty()); } @Test public void heapifyUnionFromSparse() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(false)); - final DoublesUnion u = DoublesUnion.heapify(seg); + final QuantilesDoublesUnion u = QuantilesDoublesUnion.heapify(seg); u.update(3); - final DoublesSketch s2 = u.getResult(); + final QuantilesDoublesSketch s2 = u.getResult(); Assert.assertEquals(s2.getMinItem(), 1.0); Assert.assertEquals(s2.getMaxItem(), 3.0); } @Test public void initializeUnionFromCompactSegment() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(true)); - final DoublesUnion u = DoublesUnion.heapify(seg); + final QuantilesDoublesUnion u = QuantilesDoublesUnion.heapify(seg); u.update(3); - final DoublesSketch s2 = u.getResult(); + final QuantilesDoublesSketch s2 = u.getResult(); Assert.assertEquals(s2.getMinItem(), 1.0); Assert.assertEquals(s2.getMaxItem(), 3.0); } @Test public void unionFromUpdatableSegment() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(false)); - final DoublesUnion u = DoublesUnion.wrap(seg); + final QuantilesDoublesUnion u = QuantilesDoublesUnion.wrap(seg); u.update(3); - final DoublesSketch s2 = u.getResult(); + final QuantilesDoublesSketch s2 = u.getResult(); Assert.assertEquals(s2.getMinItem(), 1.0); Assert.assertEquals(s2.getMaxItem(), 3.0); } @Test public void wrapUnionFromHeap() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(false)).asReadOnly(); try { - final DoublesUnion u = DoublesUnion.wrap(seg, null); + final QuantilesDoublesUnion u = QuantilesDoublesUnion.wrap(seg, null); } catch (final SketchesReadOnlyException e) { //expected } @@ -246,11 +246,11 @@ public void wrapUnionFromHeap() { @Test(expectedExceptions = SketchesArgumentException.class) public void wrapUnionFromCompact() { - final UpdateDoublesSketch s1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().build(); s1.update(1); s1.update(2); final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(true)); - DoublesUnion.wrap(seg, null); //compact seg + QuantilesDoublesUnion.wrap(seg, null); //compact seg fail(); } diff --git a/src/test/java/org/apache/datasketches/quantiles/DoublesSketchBuilderTest.java b/src/test/java/org/apache/datasketches/quantiles/DoublesSketchBuilderTest.java index 55c29fc28..c6759ac03 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DoublesSketchBuilderTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DoublesSketchBuilderTest.java @@ -32,19 +32,19 @@ public class DoublesSketchBuilderTest { @Test public void checkBuilder() { final int k = 256; //default is 128 - DoublesSketchBuilder bldr = DoublesSketch.builder(); + QuantilesDoublesSketchBuilder bldr = QuantilesDoublesSketch.builder(); bldr.setK(k); assertEquals(bldr.getK(), k); //confirms new k println(bldr.toString()); - final int bytes = DoublesSketch.getUpdatableStorageBytes(k, 0); + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k, 0); final byte[] byteArr = new byte[bytes]; final MemorySegment seg = MemorySegment.ofArray(byteArr); - final DoublesSketch ds = bldr.build(seg); + final QuantilesDoublesSketch ds = bldr.build(seg); assertTrue(ds.hasMemorySegment()); assertFalse(ds.isOffHeap()); println(bldr.toString()); - bldr = DoublesSketch.builder(); + bldr = QuantilesDoublesSketch.builder(); assertEquals(bldr.getK(), PreambleUtil.DEFAULT_K); } diff --git a/src/test/java/org/apache/datasketches/quantiles/DoublesSketchIteratorTest.java b/src/test/java/org/apache/datasketches/quantiles/DoublesSketchIteratorTest.java index e10e72351..a84c0f068 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DoublesSketchIteratorTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DoublesSketchIteratorTest.java @@ -19,7 +19,7 @@ package org.apache.datasketches.quantiles; -import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI; import org.testng.Assert; import org.testng.annotations.Test; @@ -27,16 +27,16 @@ public class DoublesSketchIteratorTest { @Test public void emptySketch() { - DoublesSketch sketch = DoublesSketch.builder().build(); - QuantilesDoublesSketchIterator it = sketch.iterator(); + QuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(); + QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); Assert.assertFalse(it.next()); } @Test public void oneItemSketch() { - UpdateDoublesSketch sketch = DoublesSketch.builder().build(); + UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(); sketch.update(0); - QuantilesDoublesSketchIterator it = sketch.iterator(); + QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); Assert.assertTrue(it.next()); Assert.assertEquals(it.getQuantile(), 0.0); Assert.assertEquals(it.getWeight(), 1); @@ -46,11 +46,11 @@ public void oneItemSketch() { @Test public void bigSketches() { for (int n = 1000; n < 100000; n += 2000) { - UpdateDoublesSketch sketch = DoublesSketch.builder().build(); + UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(); for (int i = 0; i < n; i++) { sketch.update(i); } - QuantilesDoublesSketchIterator it = sketch.iterator(); + QuantilesDoublesSketchIteratorAPI it = sketch.iterator(); int count = 0; int weight = 0; while (it.next()) { diff --git a/src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java index bcbb16cc2..48d361ed8 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java @@ -39,11 +39,11 @@ public class DoublesSketchTest { @Test public void heapToDirect() { - final UpdateDoublesSketch heapSketch = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch heapSketch = QuantilesDoublesSketch.builder().build(); for (int i = 0; i < 1000; i++) { heapSketch.update(i); } - final DoublesSketch directSketch = DoublesSketch.writableWrap(MemorySegment.ofArray(heapSketch.toByteArray(false)), null); + final QuantilesDoublesSketch directSketch = QuantilesDoublesSketch.writableWrap(MemorySegment.ofArray(heapSketch.toByteArray(false)), null); assertEquals(directSketch.getMinItem(), 0.0); assertEquals(directSketch.getMaxItem(), 999.0); @@ -53,12 +53,12 @@ public void heapToDirect() { @Test public void directToHeap() { final int sizeBytes = 10000; - final UpdateDoublesSketch directSketch = DoublesSketch.builder().build(MemorySegment.ofArray(new byte[sizeBytes])); + final UpdatableQuantilesDoublesSketch directSketch = QuantilesDoublesSketch.builder().build(MemorySegment.ofArray(new byte[sizeBytes])); for (int i = 0; i < 1000; i++) { directSketch.update(i); } - UpdateDoublesSketch heapSketch; - heapSketch = (UpdateDoublesSketch) DoublesSketch.heapify(MemorySegment.ofArray(directSketch.toByteArray())); + UpdatableQuantilesDoublesSketch heapSketch; + heapSketch = (UpdatableQuantilesDoublesSketch) QuantilesDoublesSketch.heapify(MemorySegment.ofArray(directSketch.toByteArray())); for (int i = 0; i < 1000; i++) { heapSketch.update(i + 1000); } @@ -69,7 +69,7 @@ public void directToHeap() { @Test public void checkToByteArray() { - final UpdateDoublesSketch ds = DoublesSketch.builder().build(); //k = 128 + final UpdatableQuantilesDoublesSketch ds = QuantilesDoublesSketch.builder().build(); //k = 128 ds.update(1); ds.update(2); final byte[] arr = ds.toByteArray(false); @@ -83,8 +83,8 @@ public void checkToByteArray() { * @param sketch1 input sketch 1 * @param sketch2 input sketch 2 */ - static void testSketchEquality(final DoublesSketch sketch1, - final DoublesSketch sketch2) { + static void testSketchEquality(final QuantilesDoublesSketch sketch1, + final QuantilesDoublesSketch sketch2) { assertEquals(sketch1.getK(), sketch2.getK()); assertEquals(sketch1.getN(), sketch2.getN()); assertEquals(sketch1.getBitPattern(), sketch2.getBitPattern()); @@ -118,19 +118,19 @@ public void checkIsSameResource() { final MemorySegment seg = MemorySegment.ofArray(new byte[(k*16) +24]); final MemorySegment cseg = MemorySegment.ofArray(new byte[8]); final DirectUpdateDoublesSketch duds = - (DirectUpdateDoublesSketch) DoublesSketch.builder().setK(k).build(seg); + (DirectUpdateDoublesSketch) QuantilesDoublesSketch.builder().setK(k).build(seg); assertTrue(duds.isSameResource(seg)); final DirectCompactDoublesSketch dcds = (DirectCompactDoublesSketch) duds.compact(cseg); assertTrue(dcds.isSameResource(cseg)); - final UpdateDoublesSketch uds = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch uds = QuantilesDoublesSketch.builder().setK(k).build(); assertFalse(uds.isSameResource(seg)); } @Test public void checkEmptyExceptions() { final int k = 16; - final UpdateDoublesSketch uds = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch uds = QuantilesDoublesSketch.builder().setK(k).build(); try { uds.getMaxItem(); fail(); } catch (final IllegalArgumentException e) {} try { uds.getMinItem(); fail(); } catch (final IllegalArgumentException e) {} try { uds.getRank(1.0); fail(); } catch (final IllegalArgumentException e) {} @@ -142,7 +142,7 @@ public void checkEmptyExceptions() { public void directSketchShouldMoveOntoHeapEventually() { final Arena arena = Arena.ofConfined(); final MemorySegment wseg = arena.allocate(1000); - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(wseg); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(wseg); Assert.assertTrue(sketch.isSameResource(wseg)); for (int i = 0; i < 1000; i++) { sketch.update(i); @@ -157,7 +157,7 @@ public void directSketchShouldMoveOntoHeapEventually2() { final Arena arena = Arena.ofConfined(); int i = 0; final MemorySegment wseg = arena.allocate(50); - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(wseg); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(wseg); Assert.assertTrue(sketch.isSameResource(wseg)); for (; i < 1000; i++) { if (sketch.isSameResource(wseg)) { @@ -175,7 +175,7 @@ public void directSketchShouldMoveOntoHeapEventually2() { public void checkEmptyDirect() { try (Arena arena = Arena.ofConfined()) { final MemorySegment wseg = arena.allocate(1000); - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(wseg); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(wseg); sketch.toByteArray(); //exercises a specific path } catch (final Exception e) { throw new RuntimeException(e); @@ -184,7 +184,7 @@ public void checkEmptyDirect() { @Test public void sortedView() { - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(); sketch.update(3); sketch.update(1); sketch.update(2); @@ -209,7 +209,7 @@ public void sortedView() { @Test public void checkRankLBError() { - final UpdateDoublesSketch sk = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sk = QuantilesDoublesSketch.builder().build(); final double eps = sk.getNormalizedRankError(false); println("" + (2 * eps)); for (int i = 1; i <= 10000; i++) { sk.update(i); } @@ -220,7 +220,7 @@ public void checkRankLBError() { @Test public void checkRankUBError() { - final UpdateDoublesSketch sk = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sk = QuantilesDoublesSketch.builder().build(); final double eps = sk.getNormalizedRankError(false); println(""+ (2 * eps)); for (int i = 1; i <= 10000; i++) { sk.update(i); } @@ -231,7 +231,7 @@ public void checkRankUBError() { @Test public void checkGetRanks() { - final UpdateDoublesSketch sk = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sk = QuantilesDoublesSketch.builder().build(); for (int i = 1; i <= 10000; i++) { sk.update(i); } final double[] qArr = {1000,2000,3000,4000,5000,6000,7000,8000,9000,10000}; final double[] ranks = sk.getRanks(qArr, INCLUSIVE); @@ -246,7 +246,7 @@ public void checkGetRanks() { @Test public void checkToStringHeap() { - final DoublesSketch sk = DoublesSketch.builder().setK(8).build(); + final QuantilesDoublesSketch sk = QuantilesDoublesSketch.builder().setK(8).build(); final int n = 32; for (int i = 1; i <= n; i++) { final double item = i; diff --git a/src/test/java/org/apache/datasketches/quantiles/DoublesUnionBuilderTest.java b/src/test/java/org/apache/datasketches/quantiles/DoublesUnionBuilderTest.java index d2f1d6e9f..d41d79051 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DoublesUnionBuilderTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DoublesUnionBuilderTest.java @@ -30,7 +30,7 @@ public class DoublesUnionBuilderTest { @Test public void checkBuilds() { - final UpdateDoublesSketch qs1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().build(); for (int i=0; i<1000; i++) { qs1.update(i); } final int bytes = qs1.getCurrentCompactSerializedSizeBytes(); @@ -38,16 +38,16 @@ public void checkBuilds() { qs1.putIntoMemorySegment(dstSeg); final MemorySegment srcSeg = dstSeg; - final DoublesUnionBuilder bldr = new DoublesUnionBuilder(); + final QuantilesDoublesUnionBuilder bldr = new QuantilesDoublesUnionBuilder(); bldr.setMaxK(128); - DoublesUnion union = bldr.build(); //virgin union + QuantilesDoublesUnion union = bldr.build(); //virgin union - union = DoublesUnion.heapify(srcSeg); - final DoublesSketch qs2 = union.getResult(); + union = QuantilesDoublesUnion.heapify(srcSeg); + final QuantilesDoublesSketch qs2 = union.getResult(); assertEquals(qs1.getCurrentCompactSerializedSizeBytes(), qs2.getCurrentCompactSerializedSizeBytes()); - union = DoublesUnion.heapify(qs2); - final DoublesSketch qs3 = union.getResult(); + union = QuantilesDoublesUnion.heapify(qs2); + final QuantilesDoublesSketch qs3 = union.getResult(); assertEquals(qs2.getCurrentCompactSerializedSizeBytes(), qs3.getCurrentCompactSerializedSizeBytes()); assertFalse(qs2 == qs3); } @@ -55,7 +55,7 @@ public void checkBuilds() { @Test public void checkDeprecated1() { - final UpdateDoublesSketch qs1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().build(); for (int i=0; i<1000; i++) { qs1.update(i); } @@ -65,17 +65,17 @@ public void checkDeprecated1() { qs1.putIntoMemorySegment(dstSeg); final MemorySegment srcSeg = dstSeg; - final DoublesUnionBuilder bldr = new DoublesUnionBuilder(); + final QuantilesDoublesUnionBuilder bldr = new QuantilesDoublesUnionBuilder(); bldr.setMaxK(128); - DoublesUnion union = bldr.build(); //virgin union + QuantilesDoublesUnion union = bldr.build(); //virgin union - union = DoublesUnion.heapify(srcSeg); //heapify - final DoublesSketch qs2 = union.getResult(); + union = QuantilesDoublesUnion.heapify(srcSeg); //heapify + final QuantilesDoublesSketch qs2 = union.getResult(); assertEquals(qs1.getCurrentCompactSerializedSizeBytes(), qs2.getCurrentCompactSerializedSizeBytes()); assertEquals(qs1.getCurrentUpdatableSerializedSizeBytes(), qs2.getCurrentUpdatableSerializedSizeBytes()); - union = DoublesUnion.heapify(qs2); //heapify again - final DoublesSketch qs3 = union.getResult(); + union = QuantilesDoublesUnion.heapify(qs2); //heapify again + final QuantilesDoublesSketch qs3 = union.getResult(); assertEquals(qs2.getCurrentCompactSerializedSizeBytes(), qs3.getCurrentCompactSerializedSizeBytes()); assertEquals(qs2.getCurrentUpdatableSerializedSizeBytes(), qs3.getCurrentUpdatableSerializedSizeBytes()); assertFalse(qs2 == qs3); //different objects diff --git a/src/test/java/org/apache/datasketches/quantiles/DoublesUnionImplTest.java b/src/test/java/org/apache/datasketches/quantiles/DoublesUnionImplTest.java index 094b786d3..3c64cd87a 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DoublesUnionImplTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DoublesUnionImplTest.java @@ -38,11 +38,11 @@ public class DoublesUnionImplTest { @Test public void checkUnion1() { - DoublesSketch result; - final DoublesSketch qs1; - final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(); //virgin 256 + QuantilesDoublesSketch result; + final QuantilesDoublesSketch qs1; + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(); //virgin 256 - final DoublesSketch qs0 = buildAndLoadQS(256, 500); + final QuantilesDoublesSketch qs0 = buildAndLoadQS(256, 500); union.union(qs0); //me = null, that = valid, exact result = union.getResult(); assertEquals(result.getN(), 500); @@ -58,7 +58,7 @@ public void checkUnion1() { assertEquals(result.getK(), 256); //check merge me = valid, that = valid, both K's the same - final DoublesSketch qs2 = buildAndLoadQS(256, 1000, 1000); //add 1000 + final QuantilesDoublesSketch qs2 = buildAndLoadQS(256, 1000, 1000); //add 1000 union.union(qs2); result = union.getResult(); assertEquals(result.getN(), 2000); @@ -67,11 +67,11 @@ public void checkUnion1() { @Test public void checkUnion1Direct() { - DoublesSketch result; - final DoublesSketch qs1; - final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(); //virgin 256 + QuantilesDoublesSketch result; + final QuantilesDoublesSketch qs1; + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(); //virgin 256 - final DoublesSketch qs0 = buildAndLoadDQS(256, 500); + final QuantilesDoublesSketch qs0 = buildAndLoadDQS(256, 500); union.union(qs0); //me = null, that = valid, exact result = union.getResult(); assertEquals(result.getN(), 500); @@ -87,7 +87,7 @@ public void checkUnion1Direct() { assertEquals(result.getK(), 256); //check merge me = valid, that = valid, both K's the same - final DoublesSketch qs2 = buildAndLoadDQS(256, 1000, 1000).compact(); //add 1000 + final QuantilesDoublesSketch qs2 = buildAndLoadDQS(256, 1000, 1000).compact(); //add 1000 union.union(qs2); result = union.getResult(); assertEquals(result.getN(), 2000); @@ -96,19 +96,19 @@ public void checkUnion1Direct() { @Test public void checkUnion2() { - final DoublesSketch qs1 = buildAndLoadQS(256, 1000).compact(); - final DoublesSketch qs2 = buildAndLoadQS(128, 1000); - final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(); //virgin 256 + final QuantilesDoublesSketch qs1 = buildAndLoadQS(256, 1000).compact(); + final QuantilesDoublesSketch qs2 = buildAndLoadQS(128, 1000); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(); //virgin 256 assertEquals(union.getEffectiveK(), 256); union.union(qs1); - final DoublesSketch res1 = union.getResult(); + final QuantilesDoublesSketch res1 = union.getResult(); //println(res1.toString()); assertEquals(res1.getN(), 1000); assertEquals(res1.getK(), 256); union.union(qs2); - final DoublesSketch res2 = union.getResult(); + final QuantilesDoublesSketch res2 = union.getResult(); assertEquals(res2.getN(), 2000); assertEquals(res2.getK(), 128); assertEquals(union.getEffectiveK(), 128); @@ -117,19 +117,19 @@ public void checkUnion2() { @Test public void checkUnion2Direct() { - final DoublesSketch qs1 = buildAndLoadDQS(256, 1000); - final DoublesSketch qs2 = buildAndLoadDQS(128, 1000); - final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(); //virgin 256 + final QuantilesDoublesSketch qs1 = buildAndLoadDQS(256, 1000); + final QuantilesDoublesSketch qs2 = buildAndLoadDQS(128, 1000); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(); //virgin 256 assertEquals(union.getEffectiveK(), 256); union.union(qs1); - final DoublesSketch res1 = union.getResult(); + final QuantilesDoublesSketch res1 = union.getResult(); //println(res1.toString()); assertEquals(res1.getN(), 1000); assertEquals(res1.getK(), 256); union.union(qs2); - final DoublesSketch res2 = union.getResult(); + final QuantilesDoublesSketch res2 = union.getResult(); assertEquals(res2.getN(), 2000); assertEquals(res2.getK(), 128); assertEquals(union.getEffectiveK(), 128); @@ -142,14 +142,14 @@ public void checkUnion3() { //Union is direct, empty and with larger K than vali final int n1 = 2 * k1; final int k2 = 256; final int n2 = 2000; - final DoublesSketch sketchIn1 = buildAndLoadQS(k1, n1); - final int bytes = DoublesSketch.getUpdatableStorageBytes(k2, n2);//just for size + final QuantilesDoublesSketch sketchIn1 = buildAndLoadQS(k1, n1); + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k2, n2);//just for size final MemorySegment seg = MemorySegment.ofArray(new byte[bytes]); - final DoublesUnion union = DoublesUnion.builder().setMaxK(k2).build(seg, null); //virgin 256 + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(k2).build(seg, null); //virgin 256 union.union(sketchIn1); assertEquals(union.getMaxK(), k2); assertEquals(union.getEffectiveK(), k1); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getMaxItem(), n1, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); assertEquals(result.getK(), k1); @@ -161,14 +161,14 @@ public void checkUnion3Direct() { //Union is direct, empty and with larger K tha final int n1 = 2 * k1; final int k2 = 256; final int n2 = 2000; - final DoublesSketch sketchIn1 = buildAndLoadDQS(k1, n1); - final int bytes = DoublesSketch.getUpdatableStorageBytes(k2, n2);//just for size + final QuantilesDoublesSketch sketchIn1 = buildAndLoadDQS(k1, n1); + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k2, n2);//just for size final MemorySegment seg = MemorySegment.ofArray(new byte[bytes]); - final DoublesUnion union = DoublesUnion.builder().setMaxK(k2).build(seg, null); //virgin 256 + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(k2).build(seg, null); //virgin 256 union.union(sketchIn1); assertEquals(union.getMaxK(), k2); assertEquals(union.getEffectiveK(), k1); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getMaxItem(), n1, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); assertEquals(result.getK(), k1); @@ -180,25 +180,25 @@ public void checkUnion4() { //Union is direct, valid and with larger K than vali final int n1 = 2 * k1; //16 final int k2 = 4; final int n2 = 2 * k2; //8 - final int bytes = DoublesSketch.getUpdatableStorageBytes(256, 50);//just for size + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(256, 50);//just for size final MemorySegment skSeg = MemorySegment.ofArray(new byte[bytes]); - final UpdateDoublesSketch sketchIn1 = DoublesSketch.builder().setK(k1).build(skSeg); + final UpdatableQuantilesDoublesSketch sketchIn1 = QuantilesDoublesSketch.builder().setK(k1).build(skSeg); for (int i = 0; i < n1; i++) { sketchIn1.update(i + 1); } final MemorySegment uSeg = MemorySegment.ofArray(new byte[bytes]); - final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(uSeg, null); //virgin 256 - //DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(); //virgin 256 + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(uSeg, null); //virgin 256 + //QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(); //virgin 256 union.union(sketchIn1); assertEquals(union.getResult().getN(), n1); assertEquals(union.getMaxK(), 256); assertEquals(union.getEffectiveK(), k1); - DoublesSketch result = union.getResult(); + QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getN(), 16); assertEquals(result.getMaxItem(), n1, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); assertEquals(result.getK(), k1); - final DoublesSketch sketchIn2 = buildAndLoadQS(k2, n2, 17); + final QuantilesDoublesSketch sketchIn2 = buildAndLoadQS(k2, n2, 17); union.reset(); union.union(sketchIn2); result = union.getResult(); @@ -213,24 +213,24 @@ public void checkUnion4Direct() { //Union is direct, valid and with larger K tha final int n1 = 2 * k1; //16 final int k2 = 4; final int n2 = 2 * k2; //8 - final int bytes = DoublesSketch.getUpdatableStorageBytes(256, 50);//just for size + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(256, 50);//just for size final MemorySegment skSeg = MemorySegment.ofArray(new byte[bytes]); - final UpdateDoublesSketch sketchIn1 = DoublesSketch.builder().setK(k1).build(skSeg); + final UpdatableQuantilesDoublesSketch sketchIn1 = QuantilesDoublesSketch.builder().setK(k1).build(skSeg); for (int i = 0; i < n1; i++) { sketchIn1.update(i + 1); } final MemorySegment uSeg = MemorySegment.ofArray(new byte[bytes]); - final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(uSeg, null); //virgin 256 + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(uSeg, null); //virgin 256 union.union(sketchIn1); assertEquals(union.getResult().getN(), n1); assertEquals(union.getMaxK(), 256); assertEquals(union.getEffectiveK(), k1); - DoublesSketch result = union.getResult(); + QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getN(), 16); assertEquals(result.getMaxItem(), n1, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); assertEquals(result.getK(), k1); - final DoublesSketch sketchIn2 = buildAndLoadDQS(k2, n2, 17); + final QuantilesDoublesSketch sketchIn2 = buildAndLoadDQS(k2, n2, 17); union.reset(); union.union(sketchIn2); result = union.getResult(); @@ -245,25 +245,25 @@ public void checkUnion4DirectCompact() { final int n1 = 2 * k1; //16 final int k2 = 4; final int n2 = 5 * k2; //8 - final int bytes = DoublesSketch.getUpdatableStorageBytes(256, 50);//just for size + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(256, 50);//just for size final MemorySegment skSeg = MemorySegment.ofArray(new byte[bytes]); - final UpdateDoublesSketch sketchIn0 = DoublesSketch.builder().setK(k1).build(skSeg); + final UpdatableQuantilesDoublesSketch sketchIn0 = QuantilesDoublesSketch.builder().setK(k1).build(skSeg); for (int i = 0; i < n1; i++) { sketchIn0.update(i + 1); } - final CompactDoublesSketch sketchIn1 = sketchIn0.compact(); + final CompactQuantilesDoublesSketch sketchIn1 = sketchIn0.compact(); final MemorySegment uSeg = MemorySegment.ofArray(new byte[bytes]); - final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(uSeg, null); //virgin 256 + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(uSeg, null); //virgin 256 union.union(sketchIn1); assertEquals(union.getResult().getN(), n1); assertEquals(union.getMaxK(), 256); assertEquals(union.getEffectiveK(), k1); - DoublesSketch result = union.getResult(); + QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getN(), 16); assertEquals(result.getMaxItem(), n1, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); assertEquals(result.getK(), k1); - final CompactDoublesSketch sketchIn2 = buildAndLoadDQS(k2, n2, 17).compact(); + final CompactQuantilesDoublesSketch sketchIn2 = buildAndLoadDQS(k2, n2, 17).compact(); union.reset(); union.union(sketchIn2); result = union.getResult(); @@ -276,18 +276,18 @@ public void checkUnion4DirectCompact() { public void checkUnion5() { //Union is direct, valid and with larger K than valid input final int k2 = 4; final int n2 = 2 * k2; //8 - final int bytes = DoublesSketch.getUpdatableStorageBytes(256, 50);//big enough + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(256, 50);//big enough final MemorySegment skSeg = MemorySegment.ofArray(new byte[bytes]); - DoublesSketch.builder().setK(256).build(skSeg); + QuantilesDoublesSketch.builder().setK(256).build(skSeg); - final DoublesUnion union = DoublesUnionImpl.heapifyInstance(skSeg); + final QuantilesDoublesUnion union = QuantilesDoublesUnionImpl.heapifyInstance(skSeg); assertEquals(union.getResult().getN(), 0); assertEquals(union.getMaxK(), 256); assertEquals(union.getEffectiveK(), 256); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getK(), 256); - final DoublesSketch sketchIn2 = buildAndLoadQS(k2, n2, 17); + final QuantilesDoublesSketch sketchIn2 = buildAndLoadQS(k2, n2, 17); union.union(sketchIn2); println("\nFinal" + union.getResult().toString(true, true)); assertEquals(union.getResult().getN(), n2); @@ -297,18 +297,18 @@ public void checkUnion5() { //Union is direct, valid and with larger K than vali public void checkUnion5Direct() { //Union is direct, valid and with larger K than valid input final int k2 = 4; final int n2 = 2 * k2; //8 - final int bytes = DoublesSketch.getUpdatableStorageBytes(256, 50);//big enough + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(256, 50);//big enough final MemorySegment skSeg = MemorySegment.ofArray(new byte[bytes]); - DoublesSketch.builder().setK(256).build(skSeg); + QuantilesDoublesSketch.builder().setK(256).build(skSeg); - final DoublesUnion union = DoublesUnionImpl.heapifyInstance(skSeg); + final QuantilesDoublesUnion union = QuantilesDoublesUnionImpl.heapifyInstance(skSeg); assertEquals(union.getResult().getN(), 0); assertEquals(union.getMaxK(), 256); assertEquals(union.getEffectiveK(), 256); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getK(), 256); - final DoublesSketch sketchIn2 = buildAndLoadDQS(k2, n2, 17); + final QuantilesDoublesSketch sketchIn2 = buildAndLoadDQS(k2, n2, 17); union.union(sketchIn2); println("\nFinal" + union.getResult().toString(true, true)); assertEquals(union.getResult().getN(), n2); @@ -320,11 +320,11 @@ public void checkUnion6() { final int n1 = 2 * k1; //16 final int k2 = 16; final int n2 = 2 * k2; //32 - final DoublesSketch sk1 = buildAndLoadQS(k1, n1, 0); - final DoublesSketch sk2 = buildAndLoadQS(k2, n2, n1); - final DoublesUnion union = DoublesUnionImpl.heapifyInstance(sk1); + final QuantilesDoublesSketch sk1 = buildAndLoadQS(k1, n1, 0); + final QuantilesDoublesSketch sk2 = buildAndLoadQS(k2, n2, n1); + final QuantilesDoublesUnion union = QuantilesDoublesUnionImpl.heapifyInstance(sk1); union.union(sk2); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getMaxItem(), n1 + n2, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); println("\nFinal" + union.getResult().toString(true, true)); @@ -336,11 +336,11 @@ public void checkUnion6Direct() { final int n1 = 2 * k1; //16 final int k2 = 16; final int n2 = 2 * k2; //32 - final DoublesSketch sk1 = buildAndLoadDQS(k1, n1, 0); - final DoublesSketch sk2 = buildAndLoadDQS(k2, n2, n1); - final DoublesUnion union = DoublesUnionImpl.heapifyInstance(sk1); + final QuantilesDoublesSketch sk1 = buildAndLoadDQS(k1, n1, 0); + final QuantilesDoublesSketch sk2 = buildAndLoadDQS(k2, n2, n1); + final QuantilesDoublesUnion union = QuantilesDoublesUnionImpl.heapifyInstance(sk1); union.union(sk2); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getMaxItem(), n1 + n2, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); println("\nFinal" + union.getResult().toString(true, true)); @@ -348,12 +348,12 @@ public void checkUnion6Direct() { @Test public void checkUnion7() { - final DoublesUnion union = DoublesUnionImpl.heapInstance(16); - final DoublesSketch skEst = buildAndLoadQS(32, 64); //other is bigger, est + final QuantilesDoublesUnion union = QuantilesDoublesUnionImpl.heapInstance(16); + final QuantilesDoublesSketch skEst = buildAndLoadQS(32, 64); //other is bigger, est union.union(skEst); println(skEst.toString(true, true)); println(union.toString(true, true)); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getMaxItem(), 64, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); } @@ -365,13 +365,13 @@ public void checkUnionQuantiles() { final int n2 = (k * 8) + (k / 2); final int n = n1 + n2; final double errorTolerance = 0.0175 * n; // assuming k = 128 - final UpdateDoublesSketch sketch1 = buildAndLoadQS(k, n1); - final CompactDoublesSketch sketch2 = buildAndLoadQS(k, n2, n1).compact(); - final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build(); //virgin 256 + final UpdatableQuantilesDoublesSketch sketch1 = buildAndLoadQS(k, n1); + final CompactQuantilesDoublesSketch sketch2 = buildAndLoadQS(k, n2, n1).compact(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(256).build(); //virgin 256 union.union(sketch2); union.union(sketch1); final MemorySegment seg = MemorySegment.ofArray(union.getResult().toByteArray(true)); - final DoublesSketch result = DoublesSketch.wrap(seg); + final QuantilesDoublesSketch result = QuantilesDoublesSketch.wrap(seg); assertEquals(result.getN(), n1 + n2); assertEquals(result.getK(), k); @@ -382,10 +382,10 @@ public void checkUnionQuantiles() { @Test public void checkUnion7Direct() { - final DoublesUnion union = DoublesUnionImpl.heapInstance(16); - final DoublesSketch skEst = buildAndLoadDQS(32, 64); //other is bigger, est + final QuantilesDoublesUnion union = QuantilesDoublesUnionImpl.heapInstance(16); + final QuantilesDoublesSketch skEst = buildAndLoadDQS(32, 64); //other is bigger, est union.union(skEst); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getMaxItem(), 64, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); // println(skEst.toString(true, true)); @@ -394,16 +394,16 @@ public void checkUnion7Direct() { @Test public void checkUpdateMemory() { - final DoublesSketch qs1 = buildAndLoadQS(256, 1000); + final QuantilesDoublesSketch qs1 = buildAndLoadQS(256, 1000); final int bytes = qs1.getCurrentCompactSerializedSizeBytes(); final MemorySegment dstSeg = MemorySegment.ofArray(new byte[bytes]); qs1.putIntoMemorySegment(dstSeg); final MemorySegment srcSeg = dstSeg; - final DoublesUnion union = DoublesUnion.builder().build(); //virgin + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(); //virgin union.union(srcSeg); for (int i = 1000; i < 2000; i++) { union.update(i); } - final DoublesSketch qs2 = union.getResult(); + final QuantilesDoublesSketch qs2 = union.getResult(); assertEquals(qs2.getMaxItem(), 1999, 0.0); final String s = union.toString(); println(s); //enable printing to see @@ -412,16 +412,16 @@ public void checkUpdateMemory() { @Test public void checkUpdateMemoryDirect() { - final DoublesSketch qs1 = buildAndLoadDQS(256, 1000); + final QuantilesDoublesSketch qs1 = buildAndLoadDQS(256, 1000); final int bytes = qs1.getCurrentCompactSerializedSizeBytes(); final MemorySegment dstSeg = MemorySegment.ofArray(new byte[bytes]); qs1.putIntoMemorySegment(dstSeg); final MemorySegment srcSeg = dstSeg; - final DoublesUnion union = DoublesUnion.builder().build(); //virgin + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(); //virgin union.union(srcSeg); for (int i = 1000; i < 2000; i++) { union.update(i); } - final DoublesSketch qs2 = union.getResult(); + final QuantilesDoublesSketch qs2 = union.getResult(); assertEquals(qs2.getMaxItem(), 1999, 0.0); final String s = union.toString(); println(s); //enable printing to see @@ -432,10 +432,10 @@ public void checkUpdateMemoryDirect() { public void checkUnionUpdateLogic() { final HeapUpdateDoublesSketch qs1 = null; final HeapUpdateDoublesSketch qs2 = (HeapUpdateDoublesSketch) buildAndLoadQS(256, 0); - DoublesUnionImpl.updateLogic(256, qs1, qs2); //null, empty - DoublesUnionImpl.updateLogic(256, qs2, qs1); //empty, null + QuantilesDoublesUnionImpl.updateLogic(256, qs1, qs2); //null, empty + QuantilesDoublesUnionImpl.updateLogic(256, qs2, qs1); //empty, null qs2.update(1); //no longer empty - final DoublesSketch result = DoublesUnionImpl.updateLogic(256, qs2, qs1); //valid, null + final QuantilesDoublesSketch result = QuantilesDoublesUnionImpl.updateLogic(256, qs2, qs1); //valid, null assertEquals(result.getMaxItem(), result.getMinItem(), 0.0); } @@ -443,10 +443,10 @@ public void checkUnionUpdateLogic() { public void checkUnionUpdateLogicDirect() { final HeapUpdateDoublesSketch qs1 = null; final DirectUpdateDoublesSketch qs2 = (DirectUpdateDoublesSketch) buildAndLoadDQS(256, 0); - DoublesUnionImpl.updateLogic(256, qs1, qs2); //null, empty - DoublesUnionImpl.updateLogic(256, qs2, qs1); //empty, null + QuantilesDoublesUnionImpl.updateLogic(256, qs1, qs2); //null, empty + QuantilesDoublesUnionImpl.updateLogic(256, qs2, qs1); //empty, null qs2.update(1); //no longer empty - final DoublesSketch result = DoublesUnionImpl.updateLogic(256, qs2, qs1); //valid, null + final QuantilesDoublesSketch result = QuantilesDoublesUnionImpl.updateLogic(256, qs2, qs1); //valid, null assertEquals(result.getMaxItem(), result.getMinItem(), 0.0); } @@ -454,7 +454,7 @@ public void checkUnionUpdateLogicDirect() { public void checkUnionUpdateLogicDirectDownsampled() { final DirectUpdateDoublesSketch qs1 = (DirectUpdateDoublesSketch) buildAndLoadDQS(256, 1000); final DirectUpdateDoublesSketch qs2 = (DirectUpdateDoublesSketch) buildAndLoadDQS(128, 2000); - final DoublesSketch result = DoublesUnionImpl.updateLogic(128, qs1, qs2); + final QuantilesDoublesSketch result = QuantilesDoublesUnionImpl.updateLogic(128, qs1, qs2); assertEquals(result.getMaxItem(), 2000.0, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); assertEquals(result.getN(), 3000); @@ -463,15 +463,15 @@ public void checkUnionUpdateLogicDirectDownsampled() { @Test public void checkUnionUpdateLogic2() { - DoublesSketch qs1 = DoublesSketch.builder().build(); - final DoublesSketch qs2 = DoublesSketch.builder().build(); - final DoublesUnion union = DoublesUnion.builder().build(); + QuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().build(); + final QuantilesDoublesSketch qs2 = QuantilesDoublesSketch.builder().build(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(); union.union(qs1); union.union(qs2); //case 5 qs1 = buildAndLoadQS(128, 1000); union.union(qs1); union.union(qs2); //case 9 - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); //println(union.toString(true, true)); assertEquals(result.getMaxItem(), 1000.0, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); @@ -480,15 +480,15 @@ public void checkUnionUpdateLogic2() { @Test public void checkUnionUpdateLogic2Direct() { - DoublesSketch qs1 = DoublesSketch.builder().build(); - final DoublesSketch qs2 = DoublesSketch.builder().build(); - final DoublesUnion union = DoublesUnion.builder().build(); + QuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().build(); + final QuantilesDoublesSketch qs2 = QuantilesDoublesSketch.builder().build(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(); union.union(qs1); union.union(qs2); //case 5 qs1 = buildAndLoadDQS(128, 1000); union.union(qs1); union.union(qs2); //case 9 - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); //println(union.toString(true, true)); assertEquals(result.getMaxItem(), 1000.0, 0.0); assertEquals(result.getMinItem(), 1.0, 0.0); @@ -496,24 +496,24 @@ public void checkUnionUpdateLogic2Direct() { @Test public void checkResultAndReset() { - final DoublesSketch qs1 = buildAndLoadQS(256, 0); - final DoublesUnion union = DoublesUnion.heapify(qs1); - final DoublesSketch qs2 = union.getResultAndReset(); + final QuantilesDoublesSketch qs1 = buildAndLoadQS(256, 0); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.heapify(qs1); + final QuantilesDoublesSketch qs2 = union.getResultAndReset(); assertEquals(qs2.getK(), 256); } @Test public void checkResultAndResetDirect() { - final DoublesSketch qs1 = buildAndLoadDQS(256, 0); - final DoublesUnion union = DoublesUnion.heapify(qs1); - final DoublesSketch qs2 = union.getResultAndReset(); + final QuantilesDoublesSketch qs1 = buildAndLoadDQS(256, 0); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.heapify(qs1); + final QuantilesDoublesSketch qs2 = union.getResultAndReset(); assertEquals(qs2.getK(), 256); } @Test public void checkResultViaMemory() { // empty gadget - final DoublesUnion union = DoublesUnion.builder().build(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(); // MemorySegment too small MemorySegment seg = MemorySegment.ofArray(new byte[1]); @@ -526,13 +526,13 @@ public void checkResultViaMemory() { // sufficient MemorySegment seg = MemorySegment.ofArray(new byte[8]); - DoublesSketch result = union.getResult(seg, null); + QuantilesDoublesSketch result = union.getResult(seg, null); assertTrue(result.isEmpty()); final int k = 128; final int n = 1392; - seg = MemorySegment.ofArray(new byte[DoublesSketch.getUpdatableStorageBytes(k, n)]); - final DoublesSketch qs = buildAndLoadQS(k, n); + seg = MemorySegment.ofArray(new byte[QuantilesDoublesSketch.getUpdatableStorageBytes(k, n)]); + final QuantilesDoublesSketch qs = buildAndLoadQS(k, n); union.union(qs); result = union.getResult(seg, null); DoublesSketchTest.testSketchEquality(result, qs); @@ -540,16 +540,16 @@ public void checkResultViaMemory() { @Test public void updateWithDoubleValueOnly() { - final DoublesUnion union = DoublesUnion.builder().build(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(); union.update(123.456); - final DoublesSketch qs = union.getResultAndReset(); + final QuantilesDoublesSketch qs = union.getResultAndReset(); assertEquals(qs.getN(), 1); } @Test public void checkEmptyUnion() { - final DoublesUnionImpl union = DoublesUnionImpl.heapInstance(128); - final DoublesSketch sk = union.getResult(); + final QuantilesDoublesUnionImpl union = QuantilesDoublesUnionImpl.heapInstance(128); + final QuantilesDoublesSketch sk = union.getResult(); assertNotNull(sk); final byte[] bytes = union.toByteArray(); assertEquals(bytes.length, 8); // @@ -559,21 +559,21 @@ public void checkEmptyUnion() { @Test public void checkUnionNulls() { - final DoublesUnion union = DoublesUnionImpl.heapInstance(128); - final DoublesSketch sk1 = union.getResultAndReset(); - final DoublesSketch sk2 = union.getResultAndReset(); + final QuantilesDoublesUnion union = QuantilesDoublesUnionImpl.heapInstance(128); + final QuantilesDoublesSketch sk1 = union.getResultAndReset(); + final QuantilesDoublesSketch sk2 = union.getResultAndReset(); assertNull(sk1); assertNull(sk2); try { union.union(sk2); fail(); } catch (final NullPointerException e) { } - final DoublesSketch sk3 = union.getResultAndReset(); + final QuantilesDoublesSketch sk3 = union.getResultAndReset(); assertNull(sk3); } @Test public void differentLargerK() { - final DoublesUnion union = DoublesUnion.builder().setMaxK(128).build(); - final UpdateDoublesSketch sketch1 = buildAndLoadQS(256, 0); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(128).build(); + final UpdatableQuantilesDoublesSketch sketch1 = buildAndLoadQS(256, 0); union.union(sketch1); Assert.assertEquals(union.getResult().getK(), 128); sketch1.update(1.0); @@ -583,8 +583,8 @@ public void differentLargerK() { @Test public void differentLargerKDirect() { - final DoublesUnion union = DoublesUnion.builder().setMaxK(128).build(); - final UpdateDoublesSketch sketch1 = buildAndLoadDQS(256, 0); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(128).build(); + final UpdatableQuantilesDoublesSketch sketch1 = buildAndLoadDQS(256, 0); union.union(sketch1); Assert.assertEquals(union.getResult().getK(), 128); sketch1.update(1.0); @@ -596,7 +596,7 @@ public void differentLargerKDirect() { public void differentEmptySmallerK() { final int k128 = 128; final int k64 = 64; - final DoublesUnion union = DoublesUnion.builder().setMaxK(k128).build(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(k128).build(); assertTrue(union.isEmpty()); //gadget is null assertFalse(union.hasMemorySegment()); assertFalse(union.isOffHeap()); @@ -604,14 +604,14 @@ public void differentEmptySmallerK() { // byte[] unionByteArr = union.toByteArray(); // Assert.assertEquals(unionByteArr.length, 32 + 32); //empty - final UpdateDoublesSketch sketch1 = buildAndLoadQS(k64, 0); //build smaller empty sketch + final UpdatableQuantilesDoublesSketch sketch1 = buildAndLoadQS(k64, 0); //build smaller empty sketch union.union(sketch1); assertTrue(union.isEmpty()); //gadget is valid assertFalse(union.hasMemorySegment()); assertFalse(union.isOffHeap()); // unionByteArr = union.toByteArray(); - // int udBytes = DoublesSketch.getUpdatableStorageBytes(k64, 0); + // int udBytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k64, 0); // Assert.assertEquals(unionByteArr.length, udBytes); //empty assertEquals(union.getResult().getK(), 128); @@ -624,7 +624,7 @@ public void differentEmptySmallerK() { public void differentEmptySmallerKDirect() { final int k128 = 128; final int k64 = 64; - final DoublesUnion union = DoublesUnion.builder().setMaxK(k128).build(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().setMaxK(k128).build(); assertTrue(union.isEmpty()); //gadget is null assertFalse(union.hasMemorySegment()); assertFalse(union.isOffHeap()); @@ -632,14 +632,14 @@ public void differentEmptySmallerKDirect() { // byte[] unionByteArr = union.toByteArray(); // Assert.assertEquals(unionByteArr.length, 32 + 32); //empty - final UpdateDoublesSketch sketch1 = buildAndLoadDQS(k64, 0); //build smaller empty sketch + final UpdatableQuantilesDoublesSketch sketch1 = buildAndLoadDQS(k64, 0); //build smaller empty sketch union.union(sketch1); assertTrue(union.isEmpty()); //gadget is valid assertFalse(union.hasMemorySegment()); assertFalse(union.isOffHeap()); // unionByteArr = union.toByteArray(); - // int udBytes = DoublesSketch.getUpdatableStorageBytes(k64, 0); + // int udBytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k64, 0); // Assert.assertEquals(unionByteArr.length, udBytes); //empty assertEquals(union.getResult().getK(), 128); @@ -652,13 +652,13 @@ public void differentEmptySmallerKDirect() { public void checkDirectInstance() { final int k = 128; final int n = 1000; - final DoublesUnionBuilder bldr = DoublesUnion.builder(); + final QuantilesDoublesUnionBuilder bldr = QuantilesDoublesUnion.builder(); bldr.setMaxK(k); assertEquals(bldr.getMaxK(), k); - final int bytes = DoublesSketch.getUpdatableStorageBytes(k, n); + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k, n); final byte[] byteArr = new byte[bytes]; final MemorySegment seg = MemorySegment.ofArray(byteArr); - final DoublesUnion union = bldr.build(seg, null); + final QuantilesDoublesUnion union = bldr.build(seg, null); assertTrue(union.isEmpty()); assertTrue(union.hasMemorySegment()); assertFalse(union.isOffHeap()); @@ -666,7 +666,7 @@ public void checkDirectInstance() { union.update(i); } assertFalse(union.isEmpty()); - final DoublesSketch res = union.getResult(); + final QuantilesDoublesSketch res = union.getResult(); final double median = res.getQuantile(.5); assertEquals(median, 500, 10); println(union.toString()); @@ -676,7 +676,7 @@ public void checkDirectInstance() { public void checkWrapInstance() { final int k = 128; final int n = 1000; - final UpdateDoublesSketch sketch = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = 1; i <= n; i++) { sketch.update(i); } @@ -685,11 +685,11 @@ public void checkWrapInstance() { final byte[] byteArr = sketch.toByteArray(false); final MemorySegment seg = MemorySegment.ofArray(byteArr); - final DoublesUnion union = DoublesUnion.wrap(seg, null); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.wrap(seg, null); Assert.assertFalse(union.isEmpty()); assertTrue(union.hasMemorySegment()); assertFalse(union.isOffHeap()); - final DoublesSketch sketch2 = union.getResult(); + final QuantilesDoublesSketch sketch2 = union.getResult(); final double uMedian = sketch2.getQuantile(0.5); Assert.assertEquals(skMedian, uMedian, 0.0); @@ -701,14 +701,14 @@ public void checkWrapInstance() { @Test public void isSameResourceHeap() { - final DoublesUnion union = DoublesUnion.builder().build(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(); Assert.assertFalse(union.isSameResource(null)); } @Test public void isSameResourceDirect() { final MemorySegment seg1 = MemorySegment.ofArray(new byte[1000000]); - final DoublesUnion union = DoublesUnion.builder().build(seg1, null); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(seg1, null); Assert.assertTrue(union.isSameResource(seg1)); final MemorySegment seg2 = MemorySegment.ofArray(new byte[1000000]); Assert.assertFalse(union.isSameResource(seg2)); @@ -716,10 +716,10 @@ public void isSameResourceDirect() { @Test public void emptyUnionSerDeIssue195() { - final DoublesUnion union = DoublesUnion.builder().build(); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.builder().build(); final byte[] byteArr = union.toByteArray(); final MemorySegment seg = MemorySegment.ofArray(byteArr); - final DoublesUnion union2 = DoublesUnion.heapify(seg); + final QuantilesDoublesUnion union2 = QuantilesDoublesUnion.heapify(seg); Assert.assertEquals(seg.byteSize(), 8L); Assert.assertTrue(union2.isEmpty()); } diff --git a/src/test/java/org/apache/datasketches/quantiles/DoublesUtilTest.java b/src/test/java/org/apache/datasketches/quantiles/DoublesUtilTest.java index 91f86f74f..24fb53a8e 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DoublesUtilTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DoublesUtilTest.java @@ -32,7 +32,7 @@ public class DoublesUtilTest { public void checkPrintSegmentData() { final int k = 16; final int n = 1000; - final DoublesSketch qs = buildAndLoadQS(k,n); + final QuantilesDoublesSketch qs = buildAndLoadQS(k,n); byte[] byteArr = qs.toByteArray(false); MemorySegment seg = MemorySegment.ofArray(byteArr); @@ -47,7 +47,7 @@ public void checkPrintSegmentData() { public void checkPrintSegmentData2() { final int k = PreambleUtil.DEFAULT_K; final int n = 0; - final DoublesSketch qs = buildAndLoadQS(k,n); + final QuantilesDoublesSketch qs = buildAndLoadQS(k,n); final byte[] byteArr = qs.toByteArray(); final MemorySegment seg = MemorySegment.ofArray(byteArr); @@ -56,7 +56,7 @@ public void checkPrintSegmentData2() { static String segToString(final boolean withLevels, final boolean withLevelsAndItems, final MemorySegment seg) { - final DoublesSketch ds = DoublesSketch.heapify(seg); + final QuantilesDoublesSketch ds = QuantilesDoublesSketch.heapify(seg); return ds.toString(withLevels, withLevelsAndItems); } @@ -72,20 +72,20 @@ public void checkCopyToHeap() { // DirectUpdateDoublesSketch final MemorySegment seg1 = MemorySegment.ofArray(huds.toByteArray()); - final DirectUpdateDoublesSketch duds = (DirectUpdateDoublesSketch) UpdateDoublesSketch.wrap(seg1, null); + final DirectUpdateDoublesSketch duds = (DirectUpdateDoublesSketch) UpdatableQuantilesDoublesSketch.wrap(seg1, null); final HeapUpdateDoublesSketch target2 = DoublesUtil.copyToHeap(duds); DoublesSketchTest.testSketchEquality(huds, duds); DoublesSketchTest.testSketchEquality(duds, target2); // HeapCompactDoublesSketch - final CompactDoublesSketch hcds = huds.compact(); + final CompactQuantilesDoublesSketch hcds = huds.compact(); final HeapUpdateDoublesSketch target3 = DoublesUtil.copyToHeap(hcds); DoublesSketchTest.testSketchEquality(huds, hcds); DoublesSketchTest.testSketchEquality(hcds, target3); // DirectCompactDoublesSketch final MemorySegment seg2 = MemorySegment.ofArray(hcds.toByteArray()); - final DirectCompactDoublesSketch dcds = (DirectCompactDoublesSketch) DoublesSketch.wrap(seg2); + final DirectCompactDoublesSketch dcds = (DirectCompactDoublesSketch) QuantilesDoublesSketch.wrap(seg2); final HeapUpdateDoublesSketch target4 = DoublesUtil.copyToHeap(dcds); DoublesSketchTest.testSketchEquality(huds, dcds); DoublesSketchTest.testSketchEquality(dcds, target4); diff --git a/src/test/java/org/apache/datasketches/quantiles/HeapCompactDoublesSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/HeapCompactDoublesSketchTest.java index fb5380a0a..9fe37355c 100644 --- a/src/test/java/org/apache/datasketches/quantiles/HeapCompactDoublesSketchTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/HeapCompactDoublesSketchTest.java @@ -37,14 +37,14 @@ public class HeapCompactDoublesSketchTest { @BeforeMethod public void setUp() { - DoublesSketch.rand.setSeed(32749); // make sketches deterministic for testing + QuantilesDoublesSketch.rand.setSeed(32749); // make sketches deterministic for testing } @Test public void heapifyFromUpdateSketch() { final int k = 4; final int n = 45; - final UpdateDoublesSketch qs = buildAndLoadQS(k, n); + final UpdatableQuantilesDoublesSketch qs = buildAndLoadQS(k, n); final byte[] qsBytes = qs.toByteArray(); final MemorySegment qsSeg = MemorySegment.ofArray(qsBytes); @@ -58,7 +58,7 @@ public void heapifyFromUpdateSketch() { public void createFromUnsortedUpdateSketch() { final int k = 4; final int n = 13; - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = n; i > 0; --i) { qs.update(i); } @@ -72,7 +72,7 @@ public void createFromUnsortedUpdateSketch() { public void heapifyFromCompactSketch() { final int k = 8; final int n = 177; - final UpdateDoublesSketch qs = buildAndLoadQS(k, n); // assuming reverse ordered inserts + final UpdatableQuantilesDoublesSketch qs = buildAndLoadQS(k, n); // assuming reverse ordered inserts final byte[] qsBytes = qs.compact().toByteArray(); final MemorySegment qsSeg = MemorySegment.ofArray(qsBytes); @@ -84,7 +84,7 @@ public void heapifyFromCompactSketch() { @Test public void checkHeapifyUnsortedCompactV2() { final int k = 64; - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(64).build(); + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(64).build(); for (int i = 0; i < (3 * k); ++i) { qs.update(i); } @@ -107,7 +107,7 @@ public void checkHeapifyUnsortedCompactV2() { @Test public void checkEmpty() { final int k = PreambleUtil.DEFAULT_K; - final UpdateDoublesSketch qs1 = buildAndLoadQS(k, 0); + final UpdatableQuantilesDoublesSketch qs1 = buildAndLoadQS(k, 0); final byte[] byteArr = qs1.compact().toByteArray(); final byte[] byteArr2 = qs1.toByteArray(true); final MemorySegment seg = MemorySegment.ofArray(byteArr); @@ -135,12 +135,12 @@ static void checkBaseBufferIsSorted(final HeapCompactDoublesSketch qs) { } } - static UpdateDoublesSketch buildAndLoadQS(final int k, final int n) { + static UpdatableQuantilesDoublesSketch buildAndLoadQS(final int k, final int n) { return buildAndLoadQS(k, n, 0); } - static UpdateDoublesSketch buildAndLoadQS(final int k, final int n, final int startV) { - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); + static UpdatableQuantilesDoublesSketch buildAndLoadQS(final int k, final int n, final int startV) { + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = 1; i <= n; i++) { qs.update(startV + i); } diff --git a/src/test/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketchTest.java index 78fb8c0c3..e9d72d1fa 100644 --- a/src/test/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketchTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketchTest.java @@ -49,7 +49,7 @@ public class HeapUpdateDoublesSketchTest { @BeforeMethod public void setUp() { - DoublesSketch.rand.setSeed(32749); // make sketches deterministic for testing + QuantilesDoublesSketch.rand.setSeed(32749); // make sketches deterministic for testing } // Please note that this is a randomized test that could probabilistically fail @@ -58,8 +58,8 @@ public void setUp() { @Test public void checkEndToEnd() { final int k = 256; - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); - final UpdateDoublesSketch qs2 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs2 = QuantilesDoublesSketch.builder().setK(k).build(); final int n = 1000000; for (int item = n; item >= 1; item--) { if ((item % 4) == 0) { @@ -70,9 +70,9 @@ public void checkEndToEnd() { } } assertEquals(qs.getN() + qs2.getN(), n); - final DoublesUnion union = DoublesUnion.heapify(qs); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.heapify(qs); union.union(qs2); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); final int numPhiValues = 99; final double[] phiArr = new double[numPhiValues]; @@ -117,9 +117,9 @@ public void checkEndToEnd() { public void checkSmallMinMax () { final int k = 32; final int n = 8; - final UpdateDoublesSketch qs1 = DoublesSketch.builder().setK(k).build(); - final UpdateDoublesSketch qs2 = DoublesSketch.builder().setK(k).build(); - final UpdateDoublesSketch qs3 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs2 = QuantilesDoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs3 = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = n; i >= 1; i--) { qs1.update(i); @@ -145,13 +145,13 @@ public void checkSmallMinMax () { assertEquals(resultsA[1], 5.0); assertEquals(resultsA[2], 8.0); - final DoublesUnion union1 = DoublesUnion.heapify(qs1); + final QuantilesDoublesUnion union1 = QuantilesDoublesUnion.heapify(qs1); union1.union(qs2); - final DoublesSketch result1 = union1.getResult(); + final QuantilesDoublesSketch result1 = union1.getResult(); - final DoublesUnion union2 = DoublesUnion.heapify(qs2); + final QuantilesDoublesUnion union2 = QuantilesDoublesUnion.heapify(qs2); union2.union(qs3); - final DoublesSketch result2 = union2.getResult(); + final QuantilesDoublesSketch result2 = union2.getResult(); final double[] resultsB = result1.getQuantiles(queries, EXCLUSIVE); assertEquals(resultsB[0], 1.0); @@ -168,7 +168,7 @@ public void checkSmallMinMax () { public void checkMisc() { final int k = PreambleUtil.DEFAULT_K; final int n = 10000; - final UpdateDoublesSketch qs = buildAndLoadQS(k, n); + final UpdatableQuantilesDoublesSketch qs = buildAndLoadQS(k, n); qs.update(Double.NaN); //ignore final int n2 = (int)qs.getN(); assertEquals(n2, n); @@ -182,7 +182,7 @@ public void checkMisc() { public void checkToStringDetail() { final int k = PreambleUtil.DEFAULT_K; final int n = 1000000; - UpdateDoublesSketch qs = buildAndLoadQS(k, 0); + UpdatableQuantilesDoublesSketch qs = buildAndLoadQS(k, 0); String s = qs.toString(); s = qs.toString(false, true); //println(s); @@ -201,13 +201,13 @@ public void checkToStringDetail() { @Test(expectedExceptions = SketchesArgumentException.class) public void checkConstructorException() { - DoublesSketch.builder().setK(0).build(); + QuantilesDoublesSketch.builder().setK(0).build(); } @Test public void checkPreLongsFlagsAndSize() { byte[] byteArr; - final UpdateDoublesSketch ds = DoublesSketch.builder().build(); //k = 128 + final UpdatableQuantilesDoublesSketch ds = QuantilesDoublesSketch.builder().build(); //k = 128 //empty byteArr = ds.toByteArray(true); // compact assertEquals(byteArr.length, 8); @@ -247,7 +247,7 @@ public void checkPreLongsFlagsSerVer3() { public void checkGetQuantiles() { final int k = PreambleUtil.DEFAULT_K; final int n = 1000000; - final DoublesSketch qs = buildAndLoadQS(k, n); + final QuantilesDoublesSketch qs = buildAndLoadQS(k, n); final double[] frac = {-0.5}; qs.getQuantiles(frac); } @@ -256,14 +256,14 @@ public void checkGetQuantiles() { public void checkGetQuantile() { final int k = PreambleUtil.DEFAULT_K; final int n = 1000000; - final DoublesSketch qs = buildAndLoadQS(k, n); + final QuantilesDoublesSketch qs = buildAndLoadQS(k, n); final double frac = -0.5; //negative not allowed qs.getQuantile(frac); } //@Test //visual only public void summaryCheckViaMemory() { - final DoublesSketch qs = buildAndLoadQS(256, 1000000); + final QuantilesDoublesSketch qs = buildAndLoadQS(256, 1000000); String s = qs.toString(); println(s); println(""); @@ -301,7 +301,7 @@ public void checkValidateSplitPointsOrder() { @Test public void checkGetStorageBytes() { final int k = PreambleUtil.DEFAULT_K; //128 - DoublesSketch qs = buildAndLoadQS(k, 0); //k, n + QuantilesDoublesSketch qs = buildAndLoadQS(k, 0); //k, n int stor = qs.getCurrentCompactSerializedSizeBytes(); assertEquals(stor, 8); @@ -321,7 +321,7 @@ public void checkGetStorageBytes() { public void checkGetStorageBytes2() { final int k = PreambleUtil.DEFAULT_K; long v = 1; - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(); for (int i = 0; i< 1000; i++) { qs.update(v++); // for (int j = 0; j < 1000; j++) { @@ -336,11 +336,11 @@ public void checkGetStorageBytes2() { public void checkMerge() { final int k = PreambleUtil.DEFAULT_K; final int n = 1000000; - final DoublesSketch qs1 = buildAndLoadQS(k,n,0); - final DoublesSketch qs2 = buildAndLoadQS(k,0,0); //empty - final DoublesUnion union = DoublesUnion.heapify(qs2); + final QuantilesDoublesSketch qs1 = buildAndLoadQS(k,n,0); + final QuantilesDoublesSketch qs2 = buildAndLoadQS(k,0,0); //empty + final QuantilesDoublesUnion union = QuantilesDoublesUnion.heapify(qs2); union.union(qs1); - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); final double med1 = qs1.getQuantile(0.5); final double med2 = result.getQuantile(0.5); assertEquals(med1, med2, 0.0); @@ -350,11 +350,11 @@ public void checkMerge() { @Test public void checkReverseMerge() { final int k = PreambleUtil.DEFAULT_K; - final DoublesSketch qs1 = buildAndLoadQS(k, 1000, 0); - final DoublesSketch qs2 = buildAndLoadQS(2*k,1000, 1000); - final DoublesUnion union = DoublesUnion.heapify(qs2); + final QuantilesDoublesSketch qs1 = buildAndLoadQS(k, 1000, 0); + final QuantilesDoublesSketch qs2 = buildAndLoadQS(2*k,1000, 1000); + final QuantilesDoublesUnion union = QuantilesDoublesUnion.heapify(qs2); union.union(qs1); //attempt merge into larger k - final DoublesSketch result = union.getResult(); + final QuantilesDoublesSketch result = union.getResult(); assertEquals(result.getK(), k); } @@ -362,7 +362,7 @@ public void checkReverseMerge() { public void checkInternalBuildHistogram() { final int k = PreambleUtil.DEFAULT_K; final int n = 1000000; - final DoublesSketch qs = buildAndLoadQS(k,n,0); + final QuantilesDoublesSketch qs = buildAndLoadQS(k,n,0); final double eps = qs.getNormalizedRankError(true); //println("EPS:"+eps); final double[] spts = {100000, 500000, 900000}; @@ -394,15 +394,15 @@ public void checkToFromByteArray() { } private static void checkToFromByteArray2(final int k, final int n) { - final DoublesSketch qs = buildAndLoadQS(k, n); + final QuantilesDoublesSketch qs = buildAndLoadQS(k, n); byte[] byteArr; MemorySegment seg; - DoublesSketch qs2; + QuantilesDoublesSketch qs2; // from compact byteArr = qs.toByteArray(true); seg = MemorySegment.ofArray(byteArr); - qs2 = UpdateDoublesSketch.heapify(seg); + qs2 = UpdatableQuantilesDoublesSketch.heapify(seg); for (double f = 0.1; f < 0.95; f += 0.1) { assertEquals(qs.getQuantile(f), qs2.getQuantile(f), 0.0); } @@ -410,7 +410,7 @@ private static void checkToFromByteArray2(final int k, final int n) { // ordered, non-compact byteArr = qs.toByteArray(false); seg = MemorySegment.ofArray(byteArr); - qs2 = DoublesSketch.heapify(seg); + qs2 = QuantilesDoublesSketch.heapify(seg); final DoublesSketchAccessor dsa = DoublesSketchAccessor.wrap(qs2, false); dsa.sort(); for (double f = 0.1; f < 0.95; f += 0.1) { @@ -420,7 +420,7 @@ private static void checkToFromByteArray2(final int k, final int n) { // not ordered, not compact byteArr = qs.toByteArray(false); seg = MemorySegment.ofArray(byteArr); - qs2 = DoublesSketch.heapify(seg); + qs2 = QuantilesDoublesSketch.heapify(seg); for (double f = 0.1; f < 0.95; f += 0.1) { assertEquals(qs.getQuantile(f), qs2.getQuantile(f), 0.0); } @@ -429,10 +429,10 @@ private static void checkToFromByteArray2(final int k, final int n) { @Test public void checkEmpty() { final int k = PreambleUtil.DEFAULT_K; - final DoublesSketch qs1 = buildAndLoadQS(k, 0); + final QuantilesDoublesSketch qs1 = buildAndLoadQS(k, 0); final byte[] byteArr = qs1.toByteArray(); final MemorySegment seg = MemorySegment.ofArray(byteArr); - final DoublesSketch qs2 = DoublesSketch.heapify(seg); + final QuantilesDoublesSketch qs2 = QuantilesDoublesSketch.heapify(seg); assertTrue(qs2.isEmpty()); final int expectedSizeBytes = 8; //COMBINED_BUFFER + ((2 * MIN_K) << 3); assertEquals(byteArr.length, expectedSizeBytes); @@ -508,7 +508,7 @@ public void checkFlags() { @Test public void checkZeroPatternReturn() { final int k = PreambleUtil.DEFAULT_K; - final DoublesSketch qs1 = buildAndLoadQS(k, 64); + final QuantilesDoublesSketch qs1 = buildAndLoadQS(k, 64); final byte[] byteArr = qs1.toByteArray(); final MemorySegment seg = MemorySegment.ofArray(byteArr); HeapUpdateDoublesSketch.heapifyInstance(seg); @@ -517,7 +517,7 @@ public void checkZeroPatternReturn() { @Test(expectedExceptions = SketchesArgumentException.class) public void checkBadDownSamplingRatio() { final int k1 = 64; - final DoublesSketch qs1 = buildAndLoadQS(k1, k1); + final QuantilesDoublesSketch qs1 = buildAndLoadQS(k1, k1); qs1.downSample(qs1, 2*k1, null, null);//should be smaller } @@ -561,7 +561,7 @@ public void checkDownSampling() { public void testDownSampling2() { final HeapUpdateDoublesSketch sketch1 = HeapUpdateDoublesSketch.newInstance(8); final HeapUpdateDoublesSketch sketch2 = HeapUpdateDoublesSketch.newInstance(2); - DoublesSketch downSketch; + QuantilesDoublesSketch downSketch; downSketch = sketch1.downSample(sketch1, 2, null, null); assertTrue(sameStructurePredicate(sketch2, downSketch)); for (int i = 0; i < 50; i++) { @@ -577,9 +577,9 @@ public void testDownSampling3() { final int k1 = 8; final int k2 = 2; final int n = 50; - final UpdateDoublesSketch sketch1 = DoublesSketch.builder().setK(k1).build(); - final UpdateDoublesSketch sketch2 = DoublesSketch.builder().setK(k2).build(); - DoublesSketch downSketch; + final UpdatableQuantilesDoublesSketch sketch1 = QuantilesDoublesSketch.builder().setK(k1).build(); + final UpdatableQuantilesDoublesSketch sketch2 = QuantilesDoublesSketch.builder().setK(k2).build(); + QuantilesDoublesSketch downSketch; for (int i = 0; i < n; i++) { sketch1.update (i); sketch2.update (i); @@ -593,10 +593,10 @@ public void testDownSampling3withSeg() { final int k1 = 8; final int k2 = 2; final int n = 50; - final UpdateDoublesSketch sketch1 = DoublesSketch.builder().setK(k1).build(); - final UpdateDoublesSketch sketch2 = DoublesSketch.builder().setK(k2).build(); - DoublesSketch downSketch; - final int bytes = DoublesSketch.getUpdatableStorageBytes(k2, n); + final UpdatableQuantilesDoublesSketch sketch1 = QuantilesDoublesSketch.builder().setK(k1).build(); + final UpdatableQuantilesDoublesSketch sketch2 = QuantilesDoublesSketch.builder().setK(k2).build(); + QuantilesDoublesSketch downSketch; + final int bytes = QuantilesDoublesSketch.getUpdatableStorageBytes(k2, n); final MemorySegment seg = MemorySegment.ofArray(new byte[bytes]); for (int i = 0; i < n; i++) { sketch1.update (i); @@ -635,22 +635,22 @@ public void testDownSampling4() { @Test(expectedExceptions = SketchesArgumentException.class) public void testDownSamplingExceptions1() { - final UpdateDoublesSketch qs1 = DoublesSketch.builder().setK(4).build(); // not smaller - final DoublesSketch qs2 = DoublesSketch.builder().setK(3).build(); + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().setK(4).build(); // not smaller + final QuantilesDoublesSketch qs2 = QuantilesDoublesSketch.builder().setK(3).build(); DoublesMergeImpl.mergeInto(qs2, qs1); } @Test(expectedExceptions = SketchesArgumentException.class) public void testDownSamplingExceptions2() { - final UpdateDoublesSketch qs1 = DoublesSketch.builder().setK(4).build(); - final DoublesSketch qs2 = DoublesSketch.builder().setK(7).build(); // 7/4 not pwr of 2 + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().setK(4).build(); + final QuantilesDoublesSketch qs2 = QuantilesDoublesSketch.builder().setK(7).build(); // 7/4 not pwr of 2 DoublesMergeImpl.mergeInto(qs2, qs1); } @Test(expectedExceptions = SketchesArgumentException.class) public void testDownSamplingExceptions3() { - final UpdateDoublesSketch qs1 = DoublesSketch.builder().setK(4).build(); - final DoublesSketch qs2 = DoublesSketch.builder().setK(12).build(); // 12/4 not pwr of 2 + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().setK(4).build(); + final QuantilesDoublesSketch qs2 = QuantilesDoublesSketch.builder().setK(12).build(); // 12/4 not pwr of 2 DoublesMergeImpl.mergeInto(qs2, qs1); } @@ -658,7 +658,7 @@ public void testDownSamplingExceptions3() { public void quantilesCheckViaMemory() { final int k = 256; final int n = 1000000; - final DoublesSketch qs = buildAndLoadQS(k, n); + final QuantilesDoublesSketch qs = buildAndLoadQS(k, n); final double[] ranks = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; final String s = getRanksTable(qs, ranks); println(s); @@ -670,7 +670,7 @@ public void quantilesCheckViaMemory() { println(getRanksTable(qs2, ranks)); } - static String getRanksTable(final DoublesSketch qs, final double[] ranks) { + static String getRanksTable(final QuantilesDoublesSketch qs, final double[] ranks) { final double rankError = qs.getNormalizedRankError(false); final double[] values = qs.getQuantiles(ranks); final double maxV = qs.getMaxItem(); @@ -714,34 +714,34 @@ static String getRanksTable(final DoublesSketch qs, final double[] ranks) { @Test public void checkKisTwo() { final int k = 2; - final UpdateDoublesSketch qs1 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().setK(k).build(); final double err = qs1.getNormalizedRankError(false); assertTrue(err < 1.0); byte[] arr = qs1.toByteArray(true); //8 - assertEquals(arr.length, DoublesSketch.getCompactSerialiedSizeBytes(k, 0)); + assertEquals(arr.length, QuantilesDoublesSketch.getCompactSerialiedSizeBytes(k, 0)); qs1.update(1.0); arr = qs1.toByteArray(true); //40 - assertEquals(arr.length, DoublesSketch.getCompactSerialiedSizeBytes(k, 1)); + assertEquals(arr.length, QuantilesDoublesSketch.getCompactSerialiedSizeBytes(k, 1)); } @Test public void checkKisTwoDeprecated() { final int k = 2; - final UpdateDoublesSketch qs1 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().setK(k).build(); final double err = qs1.getNormalizedRankError(false); assertTrue(err < 1.0); byte[] arr = qs1.toByteArray(true); //8 - assertEquals(arr.length, DoublesSketch.getCompactSerialiedSizeBytes(k, 0)); + assertEquals(arr.length, QuantilesDoublesSketch.getCompactSerialiedSizeBytes(k, 0)); assertEquals(arr.length, qs1.getCurrentCompactSerializedSizeBytes()); qs1.update(1.0); arr = qs1.toByteArray(true); //40 - assertEquals(arr.length, DoublesSketch.getCompactSerialiedSizeBytes(k, 1)); + assertEquals(arr.length, QuantilesDoublesSketch.getCompactSerialiedSizeBytes(k, 1)); assertEquals(arr.length, qs1.getCurrentCompactSerializedSizeBytes()); } @Test public void checkPutMemory() { - final UpdateDoublesSketch qs1 = DoublesSketch.builder().build(); //k = 128 + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().build(); //k = 128 for (int i=0; i<1000; i++) { qs1.update(i); } @@ -749,14 +749,14 @@ public void checkPutMemory() { final MemorySegment dstSeg = MemorySegment.ofArray(new byte[bytes]); qs1.putIntoMemorySegment(dstSeg, false); final MemorySegment srcSeg = dstSeg; - final DoublesSketch qs2 = DoublesSketch.heapify(srcSeg); + final QuantilesDoublesSketch qs2 = QuantilesDoublesSketch.heapify(srcSeg); assertEquals(qs1.getMinItem(), qs2.getMinItem(), 0.0); assertEquals(qs1.getMaxItem(), qs2.getMaxItem(), 0.0); } @Test(expectedExceptions = SketchesArgumentException.class) public void checkPutMemoryTooSmall() { - final UpdateDoublesSketch qs1 = DoublesSketch.builder().build(); //k = 128 + final UpdatableQuantilesDoublesSketch qs1 = QuantilesDoublesSketch.builder().build(); //k = 128 for (int i=0; i<1000; i++) { qs1.update(i); } @@ -772,11 +772,11 @@ public void testIt() { final MemorySegment seg = MemorySegment.ofBuffer(bb); final int k = 1024; - final DoublesSketch qsk = new DoublesSketchBuilder().setK(k).build(); - final DoublesUnion u1 = DoublesUnion.heapify(qsk); + final QuantilesDoublesSketch qsk = new QuantilesDoublesSketchBuilder().setK(k).build(); + final QuantilesDoublesUnion u1 = QuantilesDoublesUnion.heapify(qsk); u1.getResult().putIntoMemorySegment(seg); - final DoublesUnion u2 = DoublesUnion.heapify(seg); - final DoublesSketch qsk2 = u2.getResult(); + final QuantilesDoublesUnion u2 = QuantilesDoublesUnion.heapify(seg); + final QuantilesDoublesSketch qsk2 = u2.getResult(); assertTrue(qsk2.isEmpty()); } @@ -795,7 +795,7 @@ public void checkEquallySpacedRanks() { @Test public void checkPMFonEmpty() { - final DoublesSketch qsk = buildAndLoadQS(32, 1001); + final QuantilesDoublesSketch qsk = buildAndLoadQS(32, 1001); final double[] array = {}; final double[] qOut = qsk.getQuantiles(array); assertEquals(qOut.length, 0); @@ -808,7 +808,7 @@ public void checkPMFonEmpty() { @Test public void checkPuts() { final long n1 = 1001; - final UpdateDoublesSketch qsk = buildAndLoadQS(32, (int)n1); + final UpdatableQuantilesDoublesSketch qsk = buildAndLoadQS(32, (int)n1); final long n2 = qsk.getN(); assertEquals(n2, n1); @@ -832,12 +832,12 @@ public void checkPuts() { @Test public void serializeDeserializeCompact() { - final UpdateDoublesSketch sketch1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sketch1 = QuantilesDoublesSketch.builder().build(); for (int i = 0; i < 1000; i++) { sketch1.update(i); } - UpdateDoublesSketch sketch2; - sketch2 = (UpdateDoublesSketch) DoublesSketch.heapify(MemorySegment.ofArray(sketch1.toByteArray())); + UpdatableQuantilesDoublesSketch sketch2; + sketch2 = (UpdatableQuantilesDoublesSketch) QuantilesDoublesSketch.heapify(MemorySegment.ofArray(sketch1.toByteArray())); for (int i = 0; i < 1000; i++) { sketch2.update(i + 1000); } @@ -848,11 +848,11 @@ public void serializeDeserializeCompact() { @Test public void serializeDeserializeEmptyNonCompact() { - final UpdateDoublesSketch sketch1 = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sketch1 = QuantilesDoublesSketch.builder().build(); final byte[] byteArr = sketch1.toByteArray(false); //Ordered, Not Compact, Empty assertEquals(byteArr.length, sketch1.getSerializedSizeBytes()); final MemorySegment seg = MemorySegment.ofArray(byteArr); - final UpdateDoublesSketch sketch2 = (UpdateDoublesSketch) DoublesSketch.heapify(seg); + final UpdatableQuantilesDoublesSketch sketch2 = (UpdatableQuantilesDoublesSketch) QuantilesDoublesSketch.heapify(seg); for (int i = 0; i < 1000; i++) { sketch2.update(i); } @@ -863,7 +863,7 @@ public void serializeDeserializeEmptyNonCompact() { @Test public void getRankAndGetCdfConsistency() { - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(); final int n = 1_000_000; final double[] values = new double[n]; for (int i = 0; i < n; i++) { @@ -886,13 +886,13 @@ public void getRankAndGetCdfConsistency() { @Test public void maxK() { - final UpdateDoublesSketch sketch = DoublesSketch.builder().setK(32768).build(); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().setK(32768).build(); Assert.assertEquals(sketch.getK(), 32768); } @Test public void checkBounds() { - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(); for (int i = 0; i < 1000; i++) { sketch.update(i); } @@ -909,19 +909,19 @@ public void checkBounds() { @Test public void checkGetKFromEqs() { - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(); final int k = sketch.getK(); - final double eps = DoublesSketch.getNormalizedRankError(k, false); - final double epsPmf = DoublesSketch.getNormalizedRankError(k, true); - final int kEps = DoublesSketch.getKFromEpsilon(eps, false); - final int kEpsPmf = DoublesSketch.getKFromEpsilon(epsPmf, true); + final double eps = QuantilesDoublesSketch.getNormalizedRankError(k, false); + final double epsPmf = QuantilesDoublesSketch.getNormalizedRankError(k, true); + final int kEps = QuantilesDoublesSketch.getKFromEpsilon(eps, false); + final int kEpsPmf = QuantilesDoublesSketch.getKFromEpsilon(epsPmf, true); assertEquals(kEps, k); assertEquals(kEpsPmf, k); } @Test public void tenItems() { - final UpdateDoublesSketch sketch = DoublesSketch.builder().build(); + final UpdatableQuantilesDoublesSketch sketch = QuantilesDoublesSketch.builder().build(); for (int i = 1; i <= 10; i++) { sketch.update(i); } assertFalse(sketch.isEmpty()); assertEquals(sketch.getN(), 10); @@ -979,13 +979,13 @@ public void tenItems() { private static void checksForImproperK(final int k) { final String s = "Did not catch improper k: " + k; try { - DoublesSketch.builder().setK(k); + QuantilesDoublesSketch.builder().setK(k); fail(s); } catch (final SketchesArgumentException e) { //pass } try { - DoublesSketch.builder().setK(k).build(); + QuantilesDoublesSketch.builder().setK(k).build(); fail(s); } catch (final SketchesArgumentException e) { //pass @@ -998,7 +998,7 @@ private static void checksForImproperK(final int k) { } } - private static boolean sameStructurePredicate(final DoublesSketch mq1, final DoublesSketch mq2) { + private static boolean sameStructurePredicate(final QuantilesDoublesSketch mq1, final QuantilesDoublesSketch mq2) { final boolean b1 = ( (mq1.getK() == mq2.getK()) && (mq1.getN() == mq2.getN()) @@ -1018,12 +1018,12 @@ private static boolean sameStructurePredicate(final DoublesSketch mq1, final Dou return b1 && b2; } - static UpdateDoublesSketch buildAndLoadQS(final int k, final int n) { + static UpdatableQuantilesDoublesSketch buildAndLoadQS(final int k, final int n) { return buildAndLoadQS(k, n, 0); } - static UpdateDoublesSketch buildAndLoadQS(final int k, final int n, final int startV) { - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); + static UpdatableQuantilesDoublesSketch buildAndLoadQS(final int k, final int n, final int startV) { + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(); for (int i=1; i<=n; i++) { qs.update(startV + i); } diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchIteratorTest.java b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchIteratorTest.java index 34ccf8099..912d6237e 100644 --- a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchIteratorTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchIteratorTest.java @@ -21,7 +21,7 @@ import java.util.Comparator; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; import org.testng.Assert; import org.testng.annotations.Test; @@ -29,16 +29,16 @@ public class ItemsSketchIteratorTest { @Test public void emptySketch() { - ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); - QuantilesGenericSketchIterator it = sketch.iterator(); + QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); + QuantilesGenericSketchIteratorAPI it = sketch.iterator(); Assert.assertFalse(it.next()); } @Test public void oneItemSketch() { - ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); + QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); sketch.update(0); - QuantilesGenericSketchIterator it = sketch.iterator(); + QuantilesGenericSketchIteratorAPI it = sketch.iterator(); Assert.assertTrue(it.next()); Assert.assertEquals(it.getQuantile(), Integer.valueOf(0)); Assert.assertEquals(it.getWeight(), 1); @@ -48,11 +48,11 @@ public void oneItemSketch() { @Test public void bigSketches() { for (int n = 1000; n < 100000; n += 2000) { - ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); + QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); for (int i = 0; i < n; i++) { sketch.update(i); } - QuantilesGenericSketchIterator it = sketch.iterator(); + QuantilesGenericSketchIteratorAPI it = sketch.iterator(); int count = 0; int weight = 0; while (it.next()) { diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java index 7eaee1238..d557868b9 100644 --- a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java @@ -43,7 +43,7 @@ import org.apache.datasketches.quantilescommon.GenericSortedView; import org.apache.datasketches.quantilescommon.GenericSortedViewIterator; import org.apache.datasketches.quantilescommon.ItemsSketchSortedView; -import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator; +import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -51,12 +51,12 @@ public class ItemsSketchTest { @BeforeMethod public void setUp() { - ItemsSketch.rand.setSeed(32749); // make sketches deterministic for testing + QuantilesItemsSketch.rand.setSeed(32749); // make sketches deterministic for testing } @Test public void empty() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, 128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, 128, Comparator.naturalOrder()); assertNotNull(sketch); sketch.update(null); assertTrue(sketch.isEmpty()); @@ -77,7 +77,7 @@ public void empty() { @Test public void oneItem() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, 128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, 128, Comparator.naturalOrder()); sketch.update("a"); assertEquals(sketch.getN(), 1); assertEquals(sketch.getNumRetained(), 1); @@ -123,7 +123,7 @@ public void oneItem() { @Test public void tenItems() { - final ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); for (int i = 1; i <= 10; i++) { sketch.update(i); } assertFalse(sketch.isEmpty()); assertFalse(sketch.isReadOnly()); @@ -189,7 +189,7 @@ public void tenItems() { @Test public void estimation() { - final ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, 128, Comparator.naturalOrder()); for (int i = 1; i <= 1000; i++) { sketch.update(i); } @@ -255,15 +255,15 @@ public void estimation() { @Test public void serializeDeserializeLong() { - final ItemsSketch sketch1 = ItemsSketch.getInstance(Long.class, 128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch1 = QuantilesItemsSketch.getInstance(Long.class, 128, Comparator.naturalOrder()); for (int i = 1; i <= 500; i++) { sketch1.update((long) i); } final ArrayOfItemsSerDe serDe = new ArrayOfLongsSerDe(); final byte[] bytes = sketch1.toByteArray(serDe); - final ItemsSketch sketch2 = - ItemsSketch.heapify(Long.class, MemorySegment.ofArray(bytes), Comparator.naturalOrder(), serDe); + final QuantilesItemsSketch sketch2 = + QuantilesItemsSketch.heapify(Long.class, MemorySegment.ofArray(bytes), Comparator.naturalOrder(), serDe); for (int i = 501; i <= 1000; i++) { sketch2.update((long) i); @@ -278,15 +278,15 @@ public void serializeDeserializeLong() { @Test public void serializeDeserializeDouble() { - final ItemsSketch sketch1 = ItemsSketch.getInstance(Double.class, 128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch1 = QuantilesItemsSketch.getInstance(Double.class, 128, Comparator.naturalOrder()); for (int i = 1; i <= 500; i++) { sketch1.update((double) i); } final ArrayOfItemsSerDe serDe = new ArrayOfDoublesSerDe(); final byte[] bytes = sketch1.toByteArray(serDe); - final ItemsSketch sketch2 = - ItemsSketch.heapify(Double.class, MemorySegment.ofArray(bytes), Comparator.naturalOrder(), serDe); + final QuantilesItemsSketch sketch2 = + QuantilesItemsSketch.heapify(Double.class, MemorySegment.ofArray(bytes), Comparator.naturalOrder(), serDe); for (int i = 501; i <= 1000; i++) { sketch2.update((double) i); @@ -310,7 +310,7 @@ public int compare(final String s1, final String s2) { return i1.compareTo(i2); } }; - final ItemsSketch sketch1 = ItemsSketch.getInstance(String.class, 128, numericOrder); + final QuantilesItemsSketch sketch1 = QuantilesItemsSketch.getInstance(String.class, 128, numericOrder); for (int i = 1; i <= 500; i++) { sketch1.update(Integer.toBinaryString(i << 10)); // to make strings longer @@ -318,7 +318,7 @@ public int compare(final String s1, final String s2) { final ArrayOfItemsSerDe serDe = new ArrayOfStringsSerDe(); final byte[] bytes = sketch1.toByteArray(serDe); - final ItemsSketch sketch2 = ItemsSketch.heapify(String.class, MemorySegment.ofArray(bytes), numericOrder, serDe); + final QuantilesItemsSketch sketch2 = QuantilesItemsSketch.heapify(String.class, MemorySegment.ofArray(bytes), numericOrder, serDe); for (int i = 501; i <= 1000; i++) { sketch2.update(Integer.toBinaryString(i << 10)); @@ -333,7 +333,7 @@ public int compare(final String s1, final String s2) { @Test public void toStringCrudeCheck() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, Comparator.naturalOrder()); String brief, full, part; brief = sketch.toString(); full = sketch.toString(true, true); @@ -347,15 +347,15 @@ public void toStringCrudeCheck() { assertTrue(part.length() < full.length()); final ArrayOfItemsSerDe serDe = new ArrayOfStringsSerDe(); final byte[] bytes = sketch.toByteArray(serDe); - ItemsSketch.toString(bytes); - ItemsSketch.toString(MemorySegment.ofArray(bytes)); - //PreambleUtil.toString(bytes, true); // not a DoublesSketch so this will fail - //ItemsSketch sketch2 = ItemsSketch.getInstance(MemorySegment.wrap(bytes), Comparator.naturalOrder(), serDe); + QuantilesItemsSketch.toString(bytes); + QuantilesItemsSketch.toString(MemorySegment.ofArray(bytes)); + //PreambleUtil.toString(bytes, true); // not a QuantilesDoublesSketch so this will fail + //QuantilesItemsSketch sketch2 = QuantilesItemsSketch.getInstance(MemorySegment.wrap(bytes), Comparator.naturalOrder(), serDe); } @Test public void toStringBiggerCheck() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); for (int i=0; i<40; i++) { sketch.update(Integer.toString(i)); } @@ -367,7 +367,7 @@ public void toStringBiggerCheck() { @Test(expectedExceptions = SketchesArgumentException.class) public void checkDownsampleException() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); for (int i=0; i<40; i++) { sketch.update(Integer.toString(i)); } @@ -376,7 +376,7 @@ public void checkDownsampleException() { @Test(expectedExceptions = SketchesArgumentException.class) public void negativeQuantileMustThrow() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); sketch.update("ABC"); sketch.getQuantile(-0.1); } @@ -384,50 +384,50 @@ public void negativeQuantileMustThrow() { @Test(expectedExceptions = SketchesArgumentException.class) public void checkGetInstanceExcep1() { final MemorySegment seg = MemorySegment.ofArray(new byte[4]); - ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new ArrayOfStringsSerDe()); + QuantilesItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new ArrayOfStringsSerDe()); } @Test(expectedExceptions = SketchesArgumentException.class) public void checkGetInstanceExcep2() { final MemorySegment seg = MemorySegment.ofArray(new byte[8]); - ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new ArrayOfStringsSerDe()); + QuantilesItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new ArrayOfStringsSerDe()); } @Test public void checkGoodSerDeId() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, Comparator.naturalOrder()); final byte[] byteArr = sketch.toByteArray(new ArrayOfStringsSerDe()); final MemorySegment seg = MemorySegment.ofArray(byteArr); - ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new ArrayOfStringsSerDe()); + QuantilesItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new ArrayOfStringsSerDe()); } @Test public void checkDownsample() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); for (int i=0; i<40; i++) { sketch.update(Integer.toString(i)); } - final ItemsSketch out = sketch.downSample(8); + final QuantilesItemsSketch out = sketch.downSample(8); assertEquals(out.getK(), 8); } @Test(expectedExceptions = SketchesArgumentException.class) public void unorderedSplitPoints() { - final ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); sketch.update(1); sketch.getPMF(new Integer[] {2, 1}); } @Test(expectedExceptions = SketchesArgumentException.class) public void nonUniqueSplitPoints() { - final ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); sketch.update(1); sketch.getPMF(new Integer[] {1, 1}); } @Test(expectedExceptions = SketchesArgumentException.class) public void nullInSplitPoints() { - final ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); sketch.update(1); sketch.getPMF(new Integer[] {1, null}); } @@ -435,17 +435,17 @@ public void nullInSplitPoints() { @Test(expectedExceptions = SketchesArgumentException.class) public void compactNotSupported() { final ArrayOfDoublesSerDe serDe = new ArrayOfDoublesSerDe(); - final ItemsSketch sketch = ItemsSketch.getInstance(Double.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Double.class, Comparator.naturalOrder()); final byte[] byteArr = sketch.toByteArray(serDe); final MemorySegment seg = MemorySegment.ofArray(byteArr); clearBits(seg, PreambleUtil.FLAGS_BYTE, (byte) PreambleUtil.COMPACT_FLAG_MASK); println(PreambleUtil.toString(seg, false)); - ItemsSketch.heapify(Double.class, seg, Comparator.naturalOrder(), serDe); + QuantilesItemsSketch.heapify(Double.class, seg, Comparator.naturalOrder(), serDe); } @Test public void checkPutMemory() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); for (int i=0; i<40; i++) { sketch.update(Integer.toString(i)); } @@ -456,7 +456,7 @@ public void checkPutMemory() { @Test(expectedExceptions = SketchesArgumentException.class) public void checkPutMemoryException() { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, 16, Comparator.naturalOrder()); for (int i=0; i<40; i++) { sketch.update(Integer.toString(i)); } @@ -467,7 +467,7 @@ public void checkPutMemoryException() { @Test public void checkPMFonEmpty() { - final ItemsSketch iss = buildStringIS(32, 32); + final QuantilesItemsSketch iss = buildStringIS(32, 32); final double[] ranks = {}; final String[] qOut = iss.getQuantiles(ranks); println("qOut: "+qOut.length); @@ -487,7 +487,7 @@ public void checkToFromByteArray() { @Test public void getRankAndGetCdfConsistency() { - final ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); final int n = 1_000_000; final Integer[] values = new Integer[n]; for (int i = 0; i < n; i++) { @@ -510,8 +510,8 @@ public void getRankAndGetCdfConsistency() { @Test public void getRankAndGetCdfConsistencyReverseComparator() { - final ItemsSketch sketch = - ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder().reversed()); + final QuantilesItemsSketch sketch = + QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder().reversed()); final int n = 1_000_000; final Integer[] values = new Integer[n]; for (int i = 0; i < n; i++) { @@ -527,7 +527,7 @@ public void getRankAndGetCdfConsistencyReverseComparator() { @Test public void checkBounds() { - final ItemsSketch sketch = ItemsSketch.getInstance(Double.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Double.class, Comparator.naturalOrder()); for (int i = 0; i < 1000; i++) { sketch.update((double)i); } @@ -544,27 +544,27 @@ public void checkBounds() { @Test public void checkGetKFromEqs() { - final ItemsSketch sketch = ItemsSketch.getInstance(Double.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Double.class, Comparator.naturalOrder()); final int k = sketch.getK(); - final double eps = ItemsSketch.getNormalizedRankError(k, false); - final double epsPmf = ItemsSketch.getNormalizedRankError(k, true); - final int kEps = ItemsSketch.getKFromEpsilon(eps, false); - final int kEpsPmf = ItemsSketch.getKFromEpsilon(epsPmf, true); + final double eps = QuantilesItemsSketch.getNormalizedRankError(k, false); + final double epsPmf = QuantilesItemsSketch.getNormalizedRankError(k, true); + final int kEps = QuantilesItemsSketch.getKFromEpsilon(eps, false); + final int kEpsPmf = QuantilesItemsSketch.getKFromEpsilon(epsPmf, true); assertEquals(kEps, k); assertEquals(kEpsPmf, k); } private static void checkToFromByteArray2(final int k, final int n) { - final ItemsSketch is = buildStringIS(k, n); + final QuantilesItemsSketch is = buildStringIS(k, n); byte[] byteArr; MemorySegment seg; - ItemsSketch is2; + QuantilesItemsSketch is2; final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe(); //ordered byteArr = is.toByteArray(true, serDe); seg = MemorySegment.ofArray(byteArr); - is2 = ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), serDe); + is2 = QuantilesItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), serDe); for (double f = 0.1; f < 0.95; f += 0.1) { assertEquals(is.getQuantile(f), is2.getQuantile(f)); } @@ -572,18 +572,18 @@ private static void checkToFromByteArray2(final int k, final int n) { //Not-ordered byteArr = is.toByteArray(false, serDe); seg = MemorySegment.ofArray(byteArr); - is2 = ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), serDe); + is2 = QuantilesItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), serDe); for (double f = 0.1; f < 0.95; f += 0.1) { assertEquals(is.getQuantile(f), is2.getQuantile(f)); } } - static ItemsSketch buildStringIS(final int k, final int n) { + static QuantilesItemsSketch buildStringIS(final int k, final int n) { return buildStringIS(k, n, 0); } - static ItemsSketch buildStringIS(final int k, final int n, final int start) { - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, k, Comparator.naturalOrder()); + static QuantilesItemsSketch buildStringIS(final int k, final int n, final int start) { + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, k, Comparator.naturalOrder()); for (int i = 0; i < n; i++) { sketch.update(Integer.toString(i + start)); } @@ -592,7 +592,7 @@ static ItemsSketch buildStringIS(final int k, final int n, final int sta @Test public void sortedView() { - final ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); sketch.update(3); sketch.update(1); sketch.update(2); @@ -618,15 +618,15 @@ public void sortedView() { @Test public void checkIssue484() { final Boolean[] items = { true,false,true,false,true,false,true,false,true,false }; - final ItemsSketch sketch = ItemsSketch.getInstance(Boolean.class, Boolean::compareTo); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Boolean.class, Boolean::compareTo); for (int i = 0; i < items.length; i++) { sketch.update(items[i]); } final byte[] serialized = sketch.toByteArray(new ArrayOfBooleansSerDe()); - final ItemsSketch deserialized = - ItemsSketch.heapify(Boolean.class, MemorySegment.ofArray(serialized), Boolean::compareTo, new ArrayOfBooleansSerDe()); + final QuantilesItemsSketch deserialized = + QuantilesItemsSketch.heapify(Boolean.class, MemorySegment.ofArray(serialized), Boolean::compareTo, new ArrayOfBooleansSerDe()); checkSketchesEqual(sketch, deserialized); } - private static void checkSketchesEqual(final ItemsSketch expected, final ItemsSketch actual) { + private static void checkSketchesEqual(final QuantilesItemsSketch expected, final QuantilesItemsSketch actual) { final ItemsSketchSortedView expSV = expected.getSortedView(); final ItemsSketchSortedView actSV = actual.getSortedView(); final int N = (int)actSV.getN(); @@ -648,8 +648,8 @@ private static void checkSketchesEqual(final ItemsSketch expected, final //Otherwise the higher levels would not be sorted properly. public void checkL0SortDuringMergeIssue527() throws NumberFormatException { final Random rand = new Random(); - final ItemsSketch sk1 = ItemsSketch.getInstance(String.class, 8, Comparator.reverseOrder()); - final ItemsSketch sk2 = ItemsSketch.getInstance(String.class, 8, Comparator.reverseOrder()); + final QuantilesItemsSketch sk1 = QuantilesItemsSketch.getInstance(String.class, 8, Comparator.reverseOrder()); + final QuantilesItemsSketch sk2 = QuantilesItemsSketch.getInstance(String.class, 8, Comparator.reverseOrder()); final int n = 24; //don't change this for (int i = 1; i <= n; i++ ) { final int j = rand.nextInt(n) + 1; @@ -657,13 +657,13 @@ public void checkL0SortDuringMergeIssue527() throws NumberFormatException { sk2.update(getString(j +100, 3)); } final int k = 8; - final ItemsUnion union = ItemsUnion.getInstance(String.class, k, Comparator.reverseOrder()); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(String.class, k, Comparator.reverseOrder()); union.union(sk1); union.union(sk2); - final ItemsSketch sk3 = union.getResult(); + final QuantilesItemsSketch sk3 = union.getResult(); println(sk3.toString(true, true)); //L0 and above should be sorted in reverse. Ignore BB. - final QuantilesGenericSketchIterator itr = sk3.iterator(); + final QuantilesGenericSketchIteratorAPI itr = sk3.iterator(); itr.next(); int prev = Integer.parseInt(itr.getQuantile().trim()); for (int i = 1; i < (2 * k); i++) { diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsUnionTest.java b/src/test/java/org/apache/datasketches/quantiles/ItemsUnionTest.java index 31281c768..27b3f7083 100644 --- a/src/test/java/org/apache/datasketches/quantiles/ItemsUnionTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/ItemsUnionTest.java @@ -35,16 +35,16 @@ public class ItemsUnionTest { @Test public void nullAndEmpty() { - final ItemsSketch emptySk = ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); - final ItemsSketch validSk = ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); - ItemsSketch result; + final QuantilesItemsSketch emptySk = QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); + final QuantilesItemsSketch validSk = QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); + QuantilesItemsSketch result; validSk.update(1); - ItemsUnion union = ItemsUnion.getInstance(Integer.class, Comparator.naturalOrder()); + QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Integer.class, Comparator.naturalOrder()); union.union(validSk); - union = ItemsUnion.initialize(emptySk); + union = QuantilesItemsUnion.initialize(emptySk); // internal sketch is empty at this point - union.union((ItemsSketch) null); + union.union((QuantilesItemsSketch) null); union.union(emptySk); Assert.assertTrue(union.isEmpty()); Assert.assertEquals(union.getMaxK(), DEFAULT_K); @@ -58,7 +58,7 @@ public void nullAndEmpty() { union.reset(); // internal sketch is null again - union.union((ItemsSketch) null); + union.union((QuantilesItemsSketch) null); result = union.getResult(); Assert.assertTrue(result.isEmpty()); Assert.assertEquals(result.getN(), 0); @@ -66,7 +66,7 @@ public void nullAndEmpty() { try { result.getMaxItem(); fail(); } catch (final IllegalArgumentException e) {} // internal sketch is not null again because getResult() instantiated it - union.union(ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder())); + union.union(QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder())); result = union.getResult(); Assert.assertTrue(result.isEmpty()); Assert.assertEquals(result.getN(), 0); @@ -75,7 +75,7 @@ public void nullAndEmpty() { union.reset(); // internal sketch is null again - union.union(ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder())); + union.union(QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder())); result = union.getResult(); Assert.assertTrue(result.isEmpty()); Assert.assertEquals(result.getN(), 0); @@ -85,22 +85,22 @@ public void nullAndEmpty() { @Test public void nullAndEmptyInputsToNonEmptyUnion() { - final ItemsUnion union = ItemsUnion.getInstance(Integer.class, 128, Comparator.naturalOrder()); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Integer.class, 128, Comparator.naturalOrder()); union.update(1); - ItemsSketch result = union.getResult(); + QuantilesItemsSketch result = union.getResult(); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getN(), 1); Assert.assertEquals(result.getMinItem(), Integer.valueOf(1)); Assert.assertEquals(result.getMaxItem(), Integer.valueOf(1)); - union.union((ItemsSketch) null); + union.union((QuantilesItemsSketch) null); result = union.getResult(); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getN(), 1); Assert.assertEquals(result.getMinItem(), Integer.valueOf(1)); Assert.assertEquals(result.getMaxItem(), Integer.valueOf(1)); - union.union(ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder())); + union.union(QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder())); result = union.getResult(); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getN(), 1); @@ -112,20 +112,20 @@ public void nullAndEmptyInputsToNonEmptyUnion() { public void basedOnSketch() { final Comparator comp = Comparator.naturalOrder(); final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe(); - final ItemsSketch sketch = ItemsSketch.getInstance(String.class, comp); - ItemsUnion union = ItemsUnion.initialize(sketch); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(String.class, comp); + QuantilesItemsUnion union = QuantilesItemsUnion.initialize(sketch); union.reset(); final byte[] byteArr = sketch.toByteArray(serDe); final MemorySegment seg = MemorySegment.ofArray(byteArr); - union = ItemsUnion.initializeWithMemorySegment(String.class, seg, comp, serDe); + union = QuantilesItemsUnion.initializeWithMemorySegment(String.class, seg, comp, serDe); Assert.assertEquals(byteArr.length, 8); union.reset(); } @Test public void sameK() { - final ItemsUnion union = ItemsUnion.getInstance(Long.class, 128, Comparator.naturalOrder()); - ItemsSketch result = union.getResult(); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, 128, Comparator.naturalOrder()); + QuantilesItemsSketch result = union.getResult(); Assert.assertEquals(result.getN(), 0); try { result.getMinItem(); fail(); } catch (final IllegalArgumentException e) { } try { result.getMaxItem(); fail(); } catch (final IllegalArgumentException e) { } @@ -137,7 +137,7 @@ public void sameK() { Assert.assertEquals(result.getMaxItem(), Long.valueOf(1000)); Assert.assertEquals(result.getQuantile(0.5), 500, 17); // ~1.7% normalized rank error - final ItemsSketch sketch1 = ItemsSketch.getInstance(Long.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch1 = QuantilesItemsSketch.getInstance(Long.class, Comparator.naturalOrder()); for (int i = 1001; i <= 2000; i++) { sketch1.update((long) i); } union.union(sketch1); result = union.getResult(); @@ -146,7 +146,7 @@ public void sameK() { Assert.assertEquals(result.getMaxItem(), Long.valueOf(2000)); Assert.assertEquals(result.getQuantile(0.5), 1000, 34); // ~1.7% normalized rank error - final ItemsSketch sketch2 = ItemsSketch.getInstance(Long.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch2 = QuantilesItemsSketch.getInstance(Long.class, Comparator.naturalOrder()); for (int i = 2001; i <= 3000; i++) { sketch2.update((long) i); } final ArrayOfItemsSerDe serDe = new ArrayOfLongsSerDe(); union.union(MemorySegment.ofArray(sketch2.toByteArray(serDe)), serDe); @@ -165,8 +165,8 @@ public void sameK() { @Test public void differentK() { - final ItemsUnion union = ItemsUnion.getInstance(Long.class, 512, Comparator.naturalOrder()); - ItemsSketch result = union.getResult(); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, 512, Comparator.naturalOrder()); + QuantilesItemsSketch result = union.getResult(); Assert.assertEquals(result.getN(), 0); try { result.getMinItem(); fail(); } catch (final IllegalArgumentException e) {} try { result.getMaxItem(); fail(); } catch (final IllegalArgumentException e) {} @@ -179,7 +179,7 @@ public void differentK() { Assert.assertEquals(result.getMaxItem(), Long.valueOf(10000)); Assert.assertEquals(result.getQuantile(0.5), 5000, 50); // ~0.5% normalized rank error - final ItemsSketch sketch1 = ItemsSketch.getInstance(Long.class, 256, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch1 = QuantilesItemsSketch.getInstance(Long.class, 256, Comparator.naturalOrder()); for (int i = 10001; i <= 20000; i++) { sketch1.update((long) i); } union.union(sketch1); result = union.getResult(); @@ -189,7 +189,7 @@ public void differentK() { Assert.assertEquals(result.getMaxItem(), Long.valueOf(20000)); Assert.assertEquals(result.getQuantile(0.5), 10000, 180); // ~0.9% normalized rank error - final ItemsSketch sketch2 = ItemsSketch.getInstance(Long.class,128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch2 = QuantilesItemsSketch.getInstance(Long.class,128, Comparator.naturalOrder()); for (int i = 20001; i <= 30000; i++) { sketch2.update((long) i); } final ArrayOfItemsSerDe serDe = new ArrayOfLongsSerDe(); union.union(MemorySegment.ofArray(sketch2.toByteArray(serDe)), serDe); @@ -209,8 +209,8 @@ public void differentK() { @Test public void differentLargerK() { - final ItemsUnion union = ItemsUnion.getInstance(Long.class, 128, Comparator.naturalOrder()); - final ItemsSketch sketch1 = ItemsSketch.getInstance(Long.class, 256, Comparator.naturalOrder()); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, 128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch1 = QuantilesItemsSketch.getInstance(Long.class, 256, Comparator.naturalOrder()); union.union(sketch1); Assert.assertEquals(union.getResult().getK(), 128); sketch1.update(1L); @@ -220,8 +220,8 @@ public void differentLargerK() { @Test public void differentSmallerK() { - final ItemsUnion union = ItemsUnion.getInstance(Long.class, 128, Comparator.naturalOrder()); - final ItemsSketch sketch1 = ItemsSketch.getInstance(Long.class, 64, Comparator.naturalOrder()); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, 128, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch1 = QuantilesItemsSketch.getInstance(Long.class, 64, Comparator.naturalOrder()); union.union(sketch1); //union empty, sketch1: empty Assert.assertEquals(union.getResult().getK(), 128); //union: empty, k=128 sketch1.update(1L); //union: empty, k=128; sketch: valid, k=64 @@ -231,7 +231,7 @@ public void differentSmallerK() { @Test public void toStringCrudeCheck() { - final ItemsUnion union = ItemsUnion.getInstance(String.class, 128, Comparator.naturalOrder()); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(String.class, 128, Comparator.naturalOrder()); union.update("a"); final String brief = union.toString(); final String full = union.toString(true, true); @@ -240,8 +240,8 @@ public void toStringCrudeCheck() { @Test public void meNullOtherExactBiggerSmaller() { - final ItemsUnion union = ItemsUnion.getInstance(Long.class, 16, Comparator.naturalOrder()); //me null - ItemsSketch skExact = buildIS(32, 31); //other is bigger, exact + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, 16, Comparator.naturalOrder()); //me null + QuantilesItemsSketch skExact = buildIS(32, 31); //other is bigger, exact union.union(skExact); println(skExact.toString(true, true)); println(union.toString(true, true)); @@ -257,8 +257,8 @@ public void meNullOtherExactBiggerSmaller() { @Test public void meNullOtherEstBiggerSmaller() { - final ItemsUnion union = ItemsUnion.getInstance(Long.class, 16, Comparator.naturalOrder()); //me null - ItemsSketch skEst = buildIS(32, 64); //other is bigger, est + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, 16, Comparator.naturalOrder()); //me null + QuantilesItemsSketch skEst = buildIS(32, 64); //other is bigger, est union.union(skEst); Assert.assertEquals(union.getResult().getMinItem(), skEst.getMinItem(), 0.0); Assert.assertEquals(union.getResult().getMaxItem(), skEst.getMaxItem(), 0.0); @@ -272,10 +272,10 @@ public void meNullOtherEstBiggerSmaller() { @Test public void meEmptyOtherExactBiggerSmaller() { - final ItemsUnion union = ItemsUnion.getInstance(Long.class, 16, Comparator.naturalOrder()); //me null - final ItemsSketch skEmpty = ItemsSketch.getInstance(Long.class, 64, Comparator.naturalOrder()); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, 16, Comparator.naturalOrder()); //me null + final QuantilesItemsSketch skEmpty = QuantilesItemsSketch.getInstance(Long.class, 64, Comparator.naturalOrder()); union.union(skEmpty); //empty at k = 16 - ItemsSketch skExact = buildIS(32, 63); //bigger, exact + QuantilesItemsSketch skExact = buildIS(32, 63); //bigger, exact union.union(skExact); Assert.assertEquals(union.getResult().getMinItem(), skExact.getMinItem(), 0.0); Assert.assertEquals(union.getResult().getMaxItem(), skExact.getMaxItem(), 0.0); @@ -290,10 +290,10 @@ public void meEmptyOtherExactBiggerSmaller() { @Test public void meEmptyOtherEstBiggerSmaller() { - final ItemsUnion union = ItemsUnion.getInstance(Long.class, 16, Comparator.naturalOrder()); //me null - final ItemsSketch skEmpty = ItemsSketch.getInstance(Long.class, 64, Comparator.naturalOrder()); + final QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, 16, Comparator.naturalOrder()); //me null + final QuantilesItemsSketch skEmpty = QuantilesItemsSketch.getInstance(Long.class, 64, Comparator.naturalOrder()); union.union(skEmpty); //empty at k = 16 - ItemsSketch skExact = buildIS(32, 64); //bigger, est + QuantilesItemsSketch skExact = buildIS(32, 64); //bigger, est union.union(skExact); Assert.assertEquals(union.getResult().getMinItem(), skExact.getMinItem(), 0.0); Assert.assertEquals(union.getResult().getMaxItem(), skExact.getMaxItem(), 0.0); @@ -308,13 +308,13 @@ public void meEmptyOtherEstBiggerSmaller() { @Test public void checkMergeIntoEqualKs() { - final ItemsSketch skEmpty1 = buildIS(32, 0); - final ItemsSketch skEmpty2 = buildIS(32, 0); + final QuantilesItemsSketch skEmpty1 = buildIS(32, 0); + final QuantilesItemsSketch skEmpty2 = buildIS(32, 0); ItemsMergeImpl.mergeInto(skEmpty1, skEmpty2); try { skEmpty2.getMinItem(); fail(); } catch (final IllegalArgumentException e) {} try { skEmpty2.getMaxItem(); fail(); } catch (final IllegalArgumentException e) {} - ItemsSketch skValid1, skValid2; + QuantilesItemsSketch skValid1, skValid2; int n = 64; skValid1 = buildIS(32, n, 0); skValid2 = buildIS(32, 0, 0); //empty @@ -350,7 +350,7 @@ public void checkMergeIntoEqualKs() { @Test public void checkDownSamplingMergeIntoUnequalKs() { - ItemsSketch sk1, sk2; + QuantilesItemsSketch sk1, sk2; final int n = 128; sk1 = buildIS(64, n, 0); sk2 = buildIS(32, n, 128); @@ -365,25 +365,25 @@ public void checkDownSamplingMergeIntoUnequalKs() { public void checkToByteArray() { final int k = 32; final ArrayOfLongsSerDe serDe = new ArrayOfLongsSerDe(); - ItemsUnion union = ItemsUnion.getInstance(Long.class, k, Comparator.naturalOrder()); + QuantilesItemsUnion union = QuantilesItemsUnion.getInstance(Long.class, k, Comparator.naturalOrder()); byte[] bytesOut = union.toByteArray(serDe); Assert.assertEquals(bytesOut.length, 8); Assert.assertTrue(union.isEmpty()); final byte[] byteArr = buildIS(k, (2 * k) + 5).toByteArray(serDe); final MemorySegment seg = MemorySegment.ofArray(byteArr); - union = ItemsUnion.initializeWithMemorySegment(Long.class, seg, Comparator.naturalOrder(), serDe); + union = QuantilesItemsUnion.initializeWithMemorySegment(Long.class, seg, Comparator.naturalOrder(), serDe); bytesOut = union.toByteArray(serDe); Assert.assertEquals(bytesOut.length, byteArr.length); Assert.assertEquals(bytesOut, byteArr); // assumes consistent internal use of toByteArray() } - private static ItemsSketch buildIS(final int k, final int n) { + private static QuantilesItemsSketch buildIS(final int k, final int n) { return buildIS(k, n, 0); } - private static ItemsSketch buildIS(final int k, final int n, final int startV) { - final ItemsSketch is = ItemsSketch.getInstance(Long.class, k, Comparator.naturalOrder()); + private static QuantilesItemsSketch buildIS(final int k, final int n, final int startV) { + final QuantilesItemsSketch is = QuantilesItemsSketch.getInstance(Long.class, k, Comparator.naturalOrder()); for (long i = 0; i < n; i++) { is.update(i + startV); } return is; } diff --git a/src/test/java/org/apache/datasketches/quantiles/PreambleUtilTest.java b/src/test/java/org/apache/datasketches/quantiles/PreambleUtilTest.java index a72d8ce00..4ea915c75 100644 --- a/src/test/java/org/apache/datasketches/quantiles/PreambleUtilTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/PreambleUtilTest.java @@ -167,19 +167,19 @@ public void checkInsertsAndExtracts() { public void checkToString() { final int k = PreambleUtil.DEFAULT_K; final int n = 1000000; - final UpdateDoublesSketch qs = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch qs = QuantilesDoublesSketch.builder().setK(k).build(); for (int i=0; i sk = ItemsSketch.getInstance(String.class, new Comparator() { + final QuantilesItemsSketch sk = QuantilesItemsSketch.getInstance(String.class, new Comparator() { @Override public int compare(final String s1, final String s2) { try { @@ -92,14 +92,14 @@ public void checkDoublesSketch() throws IOException { final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000}; for (final int n: nArr) { final byte[] byteArr = Files.readAllBytes(cppPath.resolve("quantiles_double_n" + n + "_cpp.sk")); - final DoublesSketch sk = DoublesSketch.wrap(MemorySegment.ofArray(byteArr)); + final QuantilesDoublesSketch sk = QuantilesDoublesSketch.wrap(MemorySegment.ofArray(byteArr)); assertTrue(n == 0 ? sk.isEmpty() : !sk.isEmpty()); assertTrue(n > 128 ? sk.isEstimationMode() : !sk.isEstimationMode()); assertEquals(sk.getN(), n); if (n > 0) { assertEquals(sk.getMinItem(), 1); assertEquals(sk.getMaxItem(), n); - final QuantilesDoublesSketchIterator it = sk.iterator(); + final QuantilesDoublesSketchIteratorAPI it = sk.iterator(); long weight = 0; while(it.next()) { assertTrue(it.getQuantile() >= sk.getMinItem()); @@ -129,7 +129,7 @@ public int compare(final String s1, final String s2) { final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000}; for (final int n: nArr) { final byte[] byteArr = Files.readAllBytes(cppPath.resolve("quantiles_string_n" + n + "_cpp.sk")); - final ItemsSketch sk = ItemsSketch.heapify( + final QuantilesItemsSketch sk = QuantilesItemsSketch.heapify( String.class, MemorySegment.ofArray(byteArr), numericOrder, @@ -141,7 +141,7 @@ public int compare(final String s1, final String s2) { if (n > 0) { assertEquals(sk.getMinItem(), "1"); assertEquals(sk.getMaxItem(), Integer.toString(n)); - final QuantilesGenericSketchIterator it = sk.iterator(); + final QuantilesGenericSketchIteratorAPI it = sk.iterator(); long weight = 0; while(it.next()) { assertTrue(numericOrder.compare(it.getQuantile(), sk.getMinItem()) >= 0); @@ -234,7 +234,7 @@ public void check083_1000() { } private static void getAndCheck(final String ver, final int n, final double quantile) { - DoublesSketch.rand.setSeed(131); //make deterministic + QuantilesDoublesSketch.rand.setSeed(131); //make deterministic //create fileName final int k = 128; final double nf = 0.5; @@ -246,7 +246,7 @@ private static void getAndCheck(final String ver, final int n, final double quan final MemorySegment srcSeg = MemorySegment.ofArray(byteArr); // heapify as update sketch - DoublesSketch qs2 = UpdateDoublesSketch.heapify(srcSeg); + QuantilesDoublesSketch qs2 = UpdatableQuantilesDoublesSketch.heapify(srcSeg); //Test the quantile double q2 = qs2.getQuantile(nf, EXCLUSIVE); println("New Median: " + q2); diff --git a/src/test/java/org/apache/datasketches/quantiles/SerDeCompatibilityTest.java b/src/test/java/org/apache/datasketches/quantiles/SerDeCompatibilityTest.java index d6d7eb9e3..7788c1a7b 100644 --- a/src/test/java/org/apache/datasketches/quantiles/SerDeCompatibilityTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/SerDeCompatibilityTest.java @@ -33,12 +33,12 @@ public class SerDeCompatibilityTest { @Test public void itemsToDoubles() { - final ItemsSketch sketch1 = ItemsSketch.getInstance(Double.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch1 = QuantilesItemsSketch.getInstance(Double.class, Comparator.naturalOrder()); for (int i = 1; i <= 500; i++) { sketch1.update((double) i); } final byte[] bytes = sketch1.toByteArray(serDe); - final UpdateDoublesSketch sketch2; - sketch2 = UpdateDoublesSketch.heapify(MemorySegment.ofArray(bytes)); + final UpdatableQuantilesDoublesSketch sketch2; + sketch2 = UpdatableQuantilesDoublesSketch.heapify(MemorySegment.ofArray(bytes)); for (int i = 501; i <= 1000; i++) { sketch2.update(i); } Assert.assertEquals(sketch2.getN(), 1000); @@ -51,16 +51,16 @@ public void itemsToDoubles() { @Test public void doublesToItems() { - final UpdateDoublesSketch sketch1 = DoublesSketch.builder().build(); //SerVer = 3 + final UpdatableQuantilesDoublesSketch sketch1 = QuantilesDoublesSketch.builder().build(); //SerVer = 3 for (int i = 1; i <= 500; i++) { sketch1.update(i); } - final CompactDoublesSketch cs = sketch1.compact(); + final CompactQuantilesDoublesSketch cs = sketch1.compact(); DoublesSketchTest.testSketchEquality(sketch1, cs); //final byte[] bytes = sketch1.compact().toByteArray(); // must be compact final byte[] bytes = cs.toByteArray(); // must be compact - //reconstruct with ItemsSketch - final ItemsSketch sketch2 = ItemsSketch.heapify(Double.class, MemorySegment.ofArray(bytes), + //reconstruct with QuantilesItemsSketch + final QuantilesItemsSketch sketch2 = QuantilesItemsSketch.heapify(Double.class, MemorySegment.ofArray(bytes), Comparator.naturalOrder(), serDe); for (int i = 501; i <= 1000; i++) { sketch2.update((double) i); } diff --git a/src/test/java/org/apache/datasketches/quantiles/UtilTest.java b/src/test/java/org/apache/datasketches/quantiles/UtilTest.java index b680c3df4..3181a2619 100644 --- a/src/test/java/org/apache/datasketches/quantiles/UtilTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/UtilTest.java @@ -177,7 +177,7 @@ private static void testBlockyTandemMergeSort(final int numTries, final int maxA arr = makeMergeTestInput(arrLen, blkSize); final long [] brr = makeTheTandemArray(arr); assertMergeTestPrecondition(arr, brr, arrLen, blkSize); - DoublesSketch.blockyTandemMergeSort(arr, brr, arrLen, blkSize); + QuantilesDoublesSketch.blockyTandemMergeSort(arr, brr, arrLen, blkSize); /* verify sorted order */ for (int i = 0; i < (arrLen-1); i++) { assert arr[i] <= arr[i+1]; diff --git a/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java b/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java index a67ddad61..06b011ea3 100644 --- a/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java +++ b/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java @@ -39,9 +39,9 @@ import org.apache.datasketches.kll.KllDoublesSketch; import org.apache.datasketches.kll.KllFloatsSketch; import org.apache.datasketches.kll.KllItemsSketch; -import org.apache.datasketches.quantiles.DoublesSketch; -import org.apache.datasketches.quantiles.ItemsSketch; -import org.apache.datasketches.quantiles.UpdateDoublesSketch; +import org.apache.datasketches.quantiles.QuantilesDoublesSketch; +import org.apache.datasketches.quantiles.QuantilesItemsSketch; +import org.apache.datasketches.quantiles.UpdatableQuantilesDoublesSketch; import org.apache.datasketches.req.ReqSketch; import org.testng.annotations.Test; @@ -132,9 +132,9 @@ public class CrossCheckQuantilesTest { ReqSketch reqFloatsSk = null; KllFloatsSketch kllFloatsSk = null; KllDoublesSketch kllDoublesSk = null; - UpdateDoublesSketch classicDoublesSk = null; + UpdatableQuantilesDoublesSketch classicDoublesSk = null; KllItemsSketch kllItemsSk = null; - ItemsSketch itemsSk = null; + QuantilesItemsSketch itemsSk = null; FloatsSketchSortedView floatsSV = null; DoublesSketchSortedView doublesSV = null; @@ -294,9 +294,9 @@ private void buildSketches(final int set) { reqFloatsSk = ReqSketch.builder().setK(k).build(); kllFloatsSk = KllFloatsSketch.newHeapInstance(k); kllDoublesSk = KllDoublesSketch.newHeapInstance(k); - classicDoublesSk = DoublesSketch.builder().setK(k).build(); + classicDoublesSk = QuantilesDoublesSketch.builder().setK(k).build(); kllItemsSk = KllItemsSketch.newHeapInstance(k, comparator, serDe); - itemsSk = ItemsSketch.getInstance(String.class, k, comparator); + itemsSk = QuantilesItemsSketch.getInstance(String.class, k, comparator); final int count = skFStreamValues[set].length; for (int i = 0; i < count; i++) { diff --git a/src/test/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnovTest.java b/src/test/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnovTest.java index 4361d5656..e80d61cd0 100644 --- a/src/test/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnovTest.java +++ b/src/test/java/org/apache/datasketches/quantilescommon/KolmogorovSmirnovTest.java @@ -28,8 +28,8 @@ import org.apache.datasketches.kll.KllDoublesSketch; import org.apache.datasketches.kll.KllFloatsSketch; import org.apache.datasketches.kll.KllSketch; -import org.apache.datasketches.quantiles.DoublesSketch; -import org.apache.datasketches.quantiles.UpdateDoublesSketch; +import org.apache.datasketches.quantiles.QuantilesDoublesSketch; +import org.apache.datasketches.quantiles.UpdatableQuantilesDoublesSketch; import org.testng.annotations.Test; public class KolmogorovSmirnovTest { @@ -38,8 +38,8 @@ public class KolmogorovSmirnovTest { @Test public void checkDisjointDistributionClassicDoubles() { final int k = 256; - final UpdateDoublesSketch s1 = DoublesSketch.builder().setK(k).build(); - final UpdateDoublesSketch s2 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s2 = QuantilesDoublesSketch.builder().setK(k).build(); final Random rand = new Random(1); @@ -49,7 +49,7 @@ public void checkDisjointDistributionClassicDoubles() { s1.update(x + 500); s2.update(x); } - final double eps = DoublesSketch.getNormalizedRankError(k, false); + final double eps = QuantilesDoublesSketch.getNormalizedRankError(k, false); println("Disjoint Classic Doubles"); println("D = " + KolmogorovSmirnov.computeKSDelta(s1, s2)); println("2*eps = " + (2 * eps) + LS); @@ -102,7 +102,7 @@ public void checkDisjointDistributionKllFloats() { @Test public void checkIdenticalDistributionClassicDoubles() { final int k = 256; - final UpdateDoublesSketch s1 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().setK(k).build(); final Random rand = new Random(1); @@ -156,8 +156,8 @@ public void checkIdenticalDistributionKllFloats() { @Test public void checkSameDistributionDifferentClassicDoublesSketches() { final int k = 256; - final UpdateDoublesSketch s1 = DoublesSketch.builder().setK(k).build(); - final UpdateDoublesSketch s2 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s2 = QuantilesDoublesSketch.builder().setK(k).build(); final Random rand = new Random(1); @@ -167,7 +167,7 @@ public void checkSameDistributionDifferentClassicDoublesSketches() { s1.update(x); s2.update(x); } - final double eps = DoublesSketch.getNormalizedRankError(k, false); + final double eps = QuantilesDoublesSketch.getNormalizedRankError(k, false); println("Same Classic Doubles"); println("D = " + KolmogorovSmirnov.computeKSDelta(s1, s2)); println("2*eps = " + (2 * eps) + LS); @@ -219,8 +219,8 @@ public void checkSameDistributionDifferentKllFloatsSketches() { @Test public void mediumResolutionClassicDoubles() { final int k = 2048; - final UpdateDoublesSketch s1 = DoublesSketch.builder().setK(k).build(); - final UpdateDoublesSketch s2 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s2 = QuantilesDoublesSketch.builder().setK(k).build(); final double tgtPvalue = .05; final Random rand = new Random(1); @@ -294,8 +294,8 @@ public void mediumResolutionKllFloats() { @Test public void highResolutionClassicDoubles() { final int k = 8192; - final UpdateDoublesSketch s1 = DoublesSketch.builder().setK(k).build(); - final UpdateDoublesSketch s2 = DoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s1 = QuantilesDoublesSketch.builder().setK(k).build(); + final UpdatableQuantilesDoublesSketch s2 = QuantilesDoublesSketch.builder().setK(k).build(); final double tgtPvalue = .05; final Random rand = new Random(1); diff --git a/src/test/java/org/apache/datasketches/quantilescommon/PartitionBoundariesTest.java b/src/test/java/org/apache/datasketches/quantilescommon/PartitionBoundariesTest.java index 81b628a25..7ff4596d5 100644 --- a/src/test/java/org/apache/datasketches/quantilescommon/PartitionBoundariesTest.java +++ b/src/test/java/org/apache/datasketches/quantilescommon/PartitionBoundariesTest.java @@ -32,11 +32,11 @@ import org.apache.datasketches.common.ArrayOfStringsSerDe; import org.apache.datasketches.common.SketchesArgumentException; import org.apache.datasketches.kll.KllItemsSketch; -import org.apache.datasketches.quantiles.ItemsSketch; +import org.apache.datasketches.quantiles.QuantilesItemsSketch; import org.testng.annotations.Test; /** - * This tests partition boundaries with both KllItemsSketch and classic ItemsSketch + * This tests partition boundaries with both KllItemsSketch and classic QuantilesItemsSketch */ public class PartitionBoundariesTest { private final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe(); @@ -61,7 +61,7 @@ public void checkSkewWithClassic() { final int numDigits = digits(totalN); final long v2 = 1000L; final QuantileSearchCriteria searchCrit = QuantileSearchCriteria.INCLUSIVE; - final ItemsSketch sk = ItemsSketch.getInstance(String.class,k, Comparator.naturalOrder()); + final QuantilesItemsSketch sk = QuantilesItemsSketch.getInstance(String.class,k, Comparator.naturalOrder()); for (long i = 1; i <= n; i++) { sk.update(getString(i, numDigits)); } for (long i = 1; i <= n2; i++) { sk.update(getString(v2, numDigits)); } @@ -149,7 +149,7 @@ public void getQuantilesVsPartitionBoundariesKll() { @Test public void getQuantilesVsPartitionBoundariesClassic() { - final ItemsSketch sketch = ItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); + final QuantilesItemsSketch sketch = QuantilesItemsSketch.getInstance(Integer.class, Comparator.naturalOrder()); sketch.update(1); sketch.update(2); sketch.update(3); diff --git a/src/test/java/org/apache/datasketches/tdigest/SortTest.java b/src/test/java/org/apache/datasketches/tdigest/SortTest.java index 86884f0ad..775b70547 100644 --- a/src/test/java/org/apache/datasketches/tdigest/SortTest.java +++ b/src/test/java/org/apache/datasketches/tdigest/SortTest.java @@ -42,15 +42,19 @@ public void smallWithRepetition() { assertEquals(values[3], 4); assertEquals(values[4], 5); } - + @Test public void large() { final int n = 1000; final double[] keys = new double[n]; final long[] values = new long[n]; - for (int i = 0; i < n; i++) values[i] = i; + for (int i = 0; i < n; i++) { + values[i] = i; + } Shuffle.shuffle(values); - for (int i = 0; i < n; i++) keys[i] = values[i]; + for (int i = 0; i < n; i++) { + keys[i] = values[i]; + } Sort.stableSort(keys, values, n); for (int i = 0; i < n; i++) { assertEquals(keys[i], i);