Skip to content
Permalink
Browse files
Renamed KllFloatsSketch to KllHeapFloatsSketch
and KllDoublesSketch to KllHeapDoublesSketch
  • Loading branch information
leerho committed Apr 6, 2022
1 parent 934e26a commit bc8fa6fa72b854983d946b74481cb5316b80f097
Showing 23 changed files with 507 additions and 428 deletions.
@@ -71,8 +71,8 @@ private KllDirectDoublesSketch(final WritableMemory wmem, final MemoryRequestSer
* @param mem the given Memory object.
* @return a KllDoublesSketch
*/
public static KllDoublesSketch heapify(final Memory mem) {
return KllDoublesSketch.heapify(mem);
public static KllHeapDoublesSketch heapify(final Memory mem) {
return KllHeapDoublesSketch.heapify(mem);
}

/**
@@ -71,8 +71,8 @@ private KllDirectFloatsSketch(final WritableMemory wmem, final MemoryRequestServ
* @param mem the given Memory object.
* @return a KllFloatsSketch
*/
public static KllFloatsSketch heapify(final Memory mem) {
return KllFloatsSketch.heapify(mem);
public static KllHeapFloatsSketch heapify(final Memory mem) {
return KllHeapFloatsSketch.heapify(mem);
}

/**
@@ -26,6 +26,7 @@
import static org.apache.datasketches.kll.KllSketch.Error.kllSketchThrow;

import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;

/**
* This class implements an on-heap doubles KllSketch.
@@ -35,7 +36,7 @@
*
* @author Lee Rhodes, Kevin Lang
*/
public final class KllDoublesSketch extends KllHeapSketch {
public final class KllHeapDoublesSketch extends KllSketch {
private double[] doubleItems_;
private double minDoubleValue_;
private double maxDoubleValue_;
@@ -45,16 +46,18 @@ public final class KllDoublesSketch extends KllHeapSketch {
* @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);
private KllHeapDoublesSketch(final Memory mem, final KllMemoryValidate memVal) {
super(SketchType.DOUBLES_SKETCH,null, null );
k = memVal.k;
m = memVal.m;
KllHelper.buildHeapKllSketchFromMemory(this, memVal);
}

/**
* Heap constructor with the default <em>k = 200</em>.
* This will have a rank error of about 1.65%.
*/
public KllDoublesSketch() {
public KllHeapDoublesSketch() {
this(KllSketch.DEFAULT_K, KllSketch.DEFAULT_M);
}

@@ -64,7 +67,7 @@ public KllDoublesSketch() {
* 1.65%. Higher values of K will have smaller error but the sketch will be larger (and slower).
* @param k parameter that controls size of the sketch and accuracy of estimates
*/
public KllDoublesSketch(final int k) {
public KllHeapDoublesSketch(final int k) {
this(k, KllSketch.DEFAULT_M);
}

@@ -79,8 +82,17 @@ public KllDoublesSketch(final int k) {
* The DEFAULT_M, which is 8 is recommended. Other values of <em>m</em> should be considered
* experimental as they have not been as well characterized.
*/
KllDoublesSketch(final int k, final int m) {
super(k, m, SketchType.DOUBLES_SKETCH);
KllHeapDoublesSketch(final int k, final int m) {
super(SketchType.DOUBLES_SKETCH, null, null);
KllHelper.checkM(m);
KllHelper.checkK(k, m);
this.k = k;
this.m = m;
n_ = 0;
minK_ = k;
numLevels_ = 1;
levels_ = new int[] {k, k};
isLevelZeroSorted_ = false;
doubleItems_ = new double[k];
minDoubleValue_ = Double.NaN;
maxDoubleValue_ = Double.NaN;
@@ -93,10 +105,10 @@ public KllDoublesSketch(final int k) {
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a heap-based sketch based on the given Memory.
*/
public static KllDoublesSketch heapify(final Memory mem) {
public static KllHeapDoublesSketch heapify(final Memory mem) {
final KllMemoryValidate memChk = new KllMemoryValidate(mem);
if (!memChk.doublesSketch) { Error.kllSketchThrow(SRC_MUST_BE_DOUBLE); }
return new KllDoublesSketch(mem, memChk);
return new KllHeapDoublesSketch(mem, memChk);
}

/**
@@ -353,4 +365,108 @@ public void update(final double value) {
@Override //Dummy
void setMinFloatValue(final float value) { kllSketchThrow(MUST_NOT_CALL); }

//************************************************************************************************
private final int k; // configured value of K.
private final int m; // configured value of M.
private long n_; // number of items input into this sketch.
private int minK_; // dynamic minK for error estimation after merging with different k.
private int numLevels_; // one-based number of current levels.
private int[] levels_; // array of index offsets into the items[]. Size = numLevels + 1.
private boolean isLevelZeroSorted_;

@Override
public int getK() {
return k;
}

@Override
public long getN() {
return n_;
}

@Override
int[] getLevelsArray() {
return levels_;
}

@Override
int getLevelsArrayAt(final int index) { return levels_[index]; }

@Override
int getM() {
return m;
}

@Override
int getMinK() {
return minK_;
}

@Override
int getNumLevels() {
return numLevels_;
}

@Override
void incN() {
n_++;
}

@Override
void incNumLevels() {
numLevels_++;
}

@Override
boolean isLevelZeroSorted() {
return isLevelZeroSorted_;
}

@Override
void setItemsArrayUpdatable(final WritableMemory itemsMem) { } //dummy

@Override
void setLevelsArray(final int[] levelsArr) {
levels_ = levelsArr;
}

@Override
void setLevelsArrayAt(final int index, final int value) { levels_[index] = value; }

@Override
void setLevelsArrayAtMinusEq(final int index, final int minusEq) {
levels_[index] -= minusEq;
}

@Override
void setLevelsArrayAtPlusEq(final int index, final int plusEq) {
levels_[index] += plusEq;
}

@Override
void setLevelsArrayUpdatable(final WritableMemory levelsMem) { } //dummy

@Override
void setLevelZeroSorted(final boolean sorted) {
this.isLevelZeroSorted_ = sorted;
}

@Override
void setMinK(final int minK) {
minK_ = minK;
}

@Override
void setMinMaxArrayUpdatable(final WritableMemory minMaxMem) { } //dummy

@Override
void setN(final long n) {
n_ = n;
}

@Override
void setNumLevels(final int numLevels) {
numLevels_ = numLevels;
}

}

0 comments on commit bc8fa6f

Please sign in to comment.