Skip to content
Permalink
Browse files
Found a few more miscellaneous items.
  • Loading branch information
leerho committed Mar 30, 2022
1 parent 71af0d9 commit 532a4e8a447ddb1ae175245ddd811caf16dcf9ea
Showing 5 changed files with 31 additions and 38 deletions.
@@ -39,12 +39,20 @@
* @author Lee Rhodes, Kevin Lang
*/
public final class KllDoublesSketch extends KllHeapSketch {

// Specific to the doubles sketch
private double[] doubleItems_; // the continuous array of double items
private double[] doubleItems_;
private double minDoubleValue_;
private double maxDoubleValue_;

/**
* Private heapify constructor.
* @param mem Memory object that contains data serialized by this sketch.
* @param memVal the MemoryCheck object
*/
private KllDoublesSketch(final Memory mem, final KllMemoryValidate memVal) {
super(memVal.k, memVal.m, SketchType.DOUBLES_SKETCH);
buildHeapKllSketchFromMemory(memVal);
}

/**
* Heap constructor with the default <em>k = 200</em>, and DEFAULT_M of 8.
* This will have a rank error of about 1.65%.
@@ -75,32 +83,20 @@ public KllDoublesSketch(final int k) {
* @param k parameter that controls size of the sketch and accuracy of estimates
* @param m parameter that controls the minimum level width.
*/
public KllDoublesSketch(final int k, final int m) {
KllDoublesSketch(final int k, final int m) {
super(k, m, SketchType.DOUBLES_SKETCH);
doubleItems_ = new double[k];
minDoubleValue_ = Double.NaN;
maxDoubleValue_ = Double.NaN;
}

/**
* Private heapify constructor.
* @param mem Memory object that contains data serialized by this sketch.
* @param memVal the MemoryCheck object
*/
private KllDoublesSketch(final Memory mem, final KllMemoryValidate memVal) {
super(memVal.k, memVal.m, SketchType.DOUBLES_SKETCH);
buildHeapKllSketchFromMemory(memVal);
}

/**
* Factory heapify takes the sketch image in Memory and instantiates an on-heap sketch.
* The resulting sketch will not retain any link to the source Memory.
* @param mem a Memory image of a sketch serialized by this sketch.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a heap-based sketch based on the given Memory.
*/
//To simplify the code, the MemoryValidate class does nearly all the validity checking.
//The validated Memory is then passed to the actual private heapify constructor.
public static KllDoublesSketch heapify(final Memory mem) {
final KllMemoryValidate memChk = new KllMemoryValidate(mem);
if (!memChk.doublesSketch) {
@@ -39,12 +39,20 @@
* @author Lee Rhodes, Kevin Lang
*/
public final class KllFloatsSketch extends KllHeapSketch {

// Specific to the floats sketch
private float[] floatItems_; // the continuous array of float items
private float[] floatItems_;
private float minFloatValue_;
private float maxFloatValue_;

/**
* Private heapify constructor.
* @param mem Memory object that contains data serialized by this sketch.
* @param memVal the MemoryCheck object
*/
private KllFloatsSketch(final Memory mem, final KllMemoryValidate memVal) {
super(memVal.k, memVal.m, SketchType.FLOATS_SKETCH);
buildHeapKllSketchFromMemory(memVal);
}

/**
* Heap constructor with the default <em>k = 200</em>, and DEFAULT_M of 8.
* This will have a rank error of about 1.65%.
@@ -75,32 +83,20 @@ public KllFloatsSketch(final int k) {
* @param k parameter that controls size of the sketch and accuracy of estimates
* @param m parameter that controls the minimum level width.
*/
public KllFloatsSketch(final int k, final int m) {
KllFloatsSketch(final int k, final int m) {
super(k, m, SketchType.FLOATS_SKETCH);
floatItems_ = new float[k];
minFloatValue_ = Float.NaN;
maxFloatValue_ = Float.NaN;
}

/**
* Private heapify constructor.
* @param mem Memory object that contains data serialized by this sketch.
* @param memVal the MemoryCheck object
*/
private KllFloatsSketch(final Memory mem, final KllMemoryValidate memVal) {
super(memVal.k, memVal.m, SketchType.FLOATS_SKETCH);
buildHeapKllSketchFromMemory(memVal);
}

/**
* Factory heapify takes the sketch image in Memory and instantiates an on-heap sketch.
* The resulting sketch will not retain any link to the source Memory.
* @param mem a Memory image of a sketch serialized by this sketch.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a heap-based sketch based on the given Memory.
*/
//To simplify the code, the MemoryValidate class does nearly all the validity checking.
//The validated Memory is then passed to the actual private heapify constructor.
public static KllFloatsSketch heapify(final Memory mem) {
final KllMemoryValidate memVal = new KllMemoryValidate(mem);
if (memVal.doublesSketch) {
@@ -24,10 +24,10 @@
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR_DOUBLE;
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR_FLOAT;
import static org.apache.datasketches.kll.KllPreambleUtil.MAX_K;
import static org.apache.datasketches.kll.KllPreambleUtil.MAX_M;
import static org.apache.datasketches.kll.KllPreambleUtil.MIN_M;
import static org.apache.datasketches.kll.KllSketch.CDF_COEF;
import static org.apache.datasketches.kll.KllSketch.CDF_EXP;
import static org.apache.datasketches.kll.KllSketch.MAX_M;
import static org.apache.datasketches.kll.KllSketch.MIN_M;
import static org.apache.datasketches.kll.KllSketch.PMF_COEF;
import static org.apache.datasketches.kll.KllSketch.PMF_EXP;
import static org.apache.datasketches.kll.KllSketch.SketchType.DOUBLES_SKETCH;
@@ -131,7 +131,9 @@ private KllPreambleUtil() {}
*/
public static final int DEFAULT_K = 200;
public static final int DEFAULT_M = 8;
static final int MAX_K = (1 << 16) - 1; // serialized as an unsigned short
public static final int MAX_K = (1 << 16) - 1; // serialized as an unsigned short
public static final int MAX_M = 8;
public static final int MIN_M = 2;

// Preamble byte addresses
static final int PREAMBLE_INTS_BYTE_ADR = 0;
@@ -153,7 +155,7 @@ private KllPreambleUtil() {}
static final int DATA_START_ADR_FLOAT = 20; // float sketch, not single item

// DOUBLE SKETCH 19 to 23 is reserved for future use in double sketch
static final int DATA_START_ADR_DOUBLE = 20; // double sketch, not single item //TODO??
static final int DATA_START_ADR_DOUBLE = 20; // double sketch, not single item

// Other static values
static final byte SERIAL_VERSION_EMPTY_FULL = 1; // Empty or full preamble, NOT single item format
@@ -32,6 +32,7 @@
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR_SINGLE_ITEM;
import static org.apache.datasketches.kll.KllPreambleUtil.DEFAULT_M;
import static org.apache.datasketches.kll.KllPreambleUtil.MAX_K;
import static org.apache.datasketches.kll.KllPreambleUtil.MIN_M;
import static org.apache.datasketches.kll.KllPreambleUtil.N_LONG_ADR;
import static org.apache.datasketches.kll.KllPreambleUtil.PREAMBLE_INTS_DOUBLE;
import static org.apache.datasketches.kll.KllPreambleUtil.PREAMBLE_INTS_EMPTY_SINGLE;
@@ -96,8 +97,6 @@
* @author Lee Rhodes, Kevin Lang
*/
public abstract class KllSketch {
static final int MIN_M = 2;
static final int MAX_M = 8;
static final double EPS_DELTA_THRESHOLD = 1E-6;
static final double MIN_EPS = 4.7634E-5;
static final double PMF_COEF = 2.446;

0 comments on commit 532a4e8

Please sign in to comment.