Skip to content
Permalink
Browse files
This post fixes all the issues in the last set of reviews except two: 1)
I haven't renamed the memory dedicated "insert*" and "extract*" methods,
and 2) I haven't done the hierarchy refactoring along the lines we
discussed. I want check this in so that we can at least resolve all the
other conversations.
  • Loading branch information
leerho committed Apr 5, 2022
1 parent d29627d commit 091635be25188068eced3ccbaf030c254c447710
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 335 deletions.
@@ -21,16 +21,16 @@

import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR_DOUBLE;
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR;
import static org.apache.datasketches.kll.KllPreambleUtil.DOUBLES_SKETCH_BIT_MASK;
import static org.apache.datasketches.kll.KllPreambleUtil.PREAMBLE_INTS_DOUBLE;
import static org.apache.datasketches.kll.KllPreambleUtil.PREAMBLE_INTS_FULL;
import static org.apache.datasketches.kll.KllPreambleUtil.SERIAL_VERSION_UPDATABLE;
import static org.apache.datasketches.kll.KllPreambleUtil.UPDATABLE_BIT_MASK;
import static org.apache.datasketches.kll.KllPreambleUtil.insertMinK;
import static org.apache.datasketches.kll.KllPreambleUtil.insertFamilyID;
import static org.apache.datasketches.kll.KllPreambleUtil.insertFlags;
import static org.apache.datasketches.kll.KllPreambleUtil.insertK;
import static org.apache.datasketches.kll.KllPreambleUtil.insertM;
import static org.apache.datasketches.kll.KllPreambleUtil.insertMinK;
import static org.apache.datasketches.kll.KllPreambleUtil.insertN;
import static org.apache.datasketches.kll.KllPreambleUtil.insertNumLevels;
import static org.apache.datasketches.kll.KllPreambleUtil.insertPreInts;
@@ -39,6 +39,7 @@
import static org.apache.datasketches.kll.KllSketch.Error.SRC_IS_NOT_DIRECT;
import static org.apache.datasketches.kll.KllSketch.Error.SRC_IS_NOT_DOUBLE;
import static org.apache.datasketches.kll.KllSketch.Error.TGT_IS_IMMUTABLE;
import static org.apache.datasketches.kll.KllSketch.Error.kllSketchThrow;

import org.apache.datasketches.Family;
import org.apache.datasketches.memory.MemoryRequestServer;
@@ -92,14 +93,14 @@ public static KllDirectDoublesSketch newInstance(final int k, final WritableMemo
/**
* Create a new instance of this sketch.
* @param k parameter that controls size of the sketch and accuracy of estimates
* @param m parameter that controls the minimum level width.
* @param m parameter that controls the minimum level width in items.
* @param dstMem the given destination WritableMemory object for use by the sketch
* @param memReqSvr the given MemoryRequestServer to request a larger WritableMemory
* @return a new instance of this sketch
*/
static KllDirectDoublesSketch newInstance(final int k, final int m, final WritableMemory dstMem,
final MemoryRequestServer memReqSvr) {
insertPreInts(dstMem, PREAMBLE_INTS_DOUBLE);
insertPreInts(dstMem, PREAMBLE_INTS_FULL);
insertSerVer(dstMem, SERIAL_VERSION_UPDATABLE);
insertFamilyID(dstMem, Family.KLL.getID());
insertFlags(dstMem, DOUBLES_SKETCH_BIT_MASK | UPDATABLE_BIT_MASK);
@@ -108,7 +109,7 @@ static KllDirectDoublesSketch newInstance(final int k, final int m, final Writab
insertN(dstMem, 0);
insertMinK(dstMem, k);
insertNumLevels(dstMem, 1);
int offset = DATA_START_ADR_DOUBLE;
int offset = DATA_START_ADR;
dstMem.putIntArray(offset, new int[] {k, k}, 0, 2);
offset += 2 * Integer.BYTES;
dstMem.putDoubleArray(offset, new double[] {Double.NaN, Double.NaN}, 0, 2);
@@ -359,6 +360,7 @@ void setDoubleItemsArray(final double[] doubleItems) {

@Override
void setDoubleItemsArrayAt(final int index, final double value) {
if (!updatable) { kllSketchThrow(TGT_IS_IMMUTABLE); }
itemsArrUpdatable.putDouble((long)index * Double.BYTES, value);
}

@@ -21,8 +21,8 @@

import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR_FLOAT;
import static org.apache.datasketches.kll.KllPreambleUtil.PREAMBLE_INTS_FLOAT;
import static org.apache.datasketches.kll.KllPreambleUtil.DATA_START_ADR;
import static org.apache.datasketches.kll.KllPreambleUtil.PREAMBLE_INTS_FULL;
import static org.apache.datasketches.kll.KllPreambleUtil.SERIAL_VERSION_UPDATABLE;
import static org.apache.datasketches.kll.KllPreambleUtil.UPDATABLE_BIT_MASK;
import static org.apache.datasketches.kll.KllPreambleUtil.insertMinK;
@@ -38,6 +38,7 @@
import static org.apache.datasketches.kll.KllSketch.Error.SRC_IS_NOT_DIRECT;
import static org.apache.datasketches.kll.KllSketch.Error.SRC_IS_NOT_FLOAT;
import static org.apache.datasketches.kll.KllSketch.Error.TGT_IS_IMMUTABLE;
import static org.apache.datasketches.kll.KllSketch.Error.kllSketchThrow;

import org.apache.datasketches.Family;
import org.apache.datasketches.memory.MemoryRequestServer;
@@ -92,14 +93,14 @@ public static KllDirectFloatsSketch newInstance(final int k, final WritableMemor
/**
* Create a new instance of this sketch.
* @param k parameter that controls size of the sketch and accuracy of estimates
* @param m parameter that controls the minimum level width.
* @param m parameter that controls the minimum level width in items.
* @param dstMem the given destination WritableMemory object for use by the sketch
* @param memReqSvr the given MemoryRequestServer to request a larger WritableMemory
* @return a new instance of this sketch
*/
static KllDirectFloatsSketch newInstance(final int k, final int m, final WritableMemory dstMem,
final MemoryRequestServer memReqSvr) {
insertPreInts(dstMem, PREAMBLE_INTS_FLOAT);
insertPreInts(dstMem, PREAMBLE_INTS_FULL);
insertSerVer(dstMem, SERIAL_VERSION_UPDATABLE);
insertFamilyID(dstMem, Family.KLL.getID());
insertFlags(dstMem, UPDATABLE_BIT_MASK);
@@ -108,7 +109,7 @@ static KllDirectFloatsSketch newInstance(final int k, final int m, final Writabl
insertN(dstMem, 0);
insertMinK(dstMem, k);
insertNumLevels(dstMem, 1);
int offset = DATA_START_ADR_FLOAT;
int offset = DATA_START_ADR;
dstMem.putIntArray(offset, new int[] {k, k}, 0, 2);
offset += 2 * Integer.BYTES;
dstMem.putFloatArray(offset, new float[] {Float.NaN, Float.NaN}, 0, 2);
@@ -365,6 +366,7 @@ void setFloatItemsArray(final float[] floatItems) {

@Override
void setFloatItemsArrayAt(final int index, final float value) {
if (!updatable) { kllSketchThrow(TGT_IS_IMMUTABLE); }
itemsArrUpdatable.putFloat((long)index * Float.BYTES, value);
}

@@ -30,6 +30,7 @@
import static org.apache.datasketches.kll.KllPreambleUtil.insertN;
import static org.apache.datasketches.kll.KllPreambleUtil.insertNumLevels;
import static org.apache.datasketches.kll.KllSketch.Error.TGT_IS_IMMUTABLE;
import static org.apache.datasketches.kll.KllSketch.Error.kllSketchThrow;

import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;
@@ -24,6 +24,7 @@
import static org.apache.datasketches.kll.KllSketch.Error.SRC_IS_NOT_DOUBLE;
import static org.apache.datasketches.kll.KllSketch.Error.SRC_CANNOT_BE_DIRECT;
import static org.apache.datasketches.kll.KllSketch.Error.MUST_NOT_CALL;
import static org.apache.datasketches.kll.KllSketch.Error.kllSketchThrow;

import org.apache.datasketches.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
@@ -78,7 +79,7 @@ public KllDoublesSketch(final int k) {
* Other values of <em>m</em> should be considered experimental as they have not been
* as well characterized.
* @param k parameter that controls size of the sketch and accuracy of estimates
* @param m parameter that controls the minimum level width.
* @param m parameter that controls the minimum level width in items.
*/
KllDoublesSketch(final int k, final int m) {
super(k, m, SketchType.DOUBLES_SKETCH);
@@ -24,6 +24,7 @@
import static org.apache.datasketches.kll.KllSketch.Error.SRC_IS_NOT_FLOAT;
import static org.apache.datasketches.kll.KllSketch.Error.SRC_CANNOT_BE_DIRECT;
import static org.apache.datasketches.kll.KllSketch.Error.MUST_NOT_CALL;
import static org.apache.datasketches.kll.KllSketch.Error.kllSketchThrow;

import org.apache.datasketches.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
@@ -78,7 +79,7 @@ public KllFloatsSketch(final int k) {
* Other values of <em>m</em> should be considered experimental as they have not been
* as well characterized.
* @param k parameter that controls size of the sketch and accuracy of estimates
* @param m parameter that controls the minimum level width.
* @param m parameter that controls the minimum level width in items.
*/
KllFloatsSketch(final int k, final int m) {
super(k, m, SketchType.FLOATS_SKETCH);
@@ -21,8 +21,7 @@

import static java.lang.Math.pow;
import static org.apache.datasketches.Util.floorPowerOf2;
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.DATA_START_ADR;
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.PMF_COEF;
@@ -144,18 +143,14 @@ public static GrowthStats getGrowthSchemeForGivenN(
}
int compactBytes;
int updatableBytes;
final int typeBytes = (sketchType == DOUBLES_SKETCH) ? Double.BYTES : Float.BYTES;
do {
numLevels++;
lvlStats = getFinalSketchStatsAtNumLevels(k, m, numLevels, false);
final int maxItems = lvlStats.items;
final long maxN = lvlStats.n;
if (sketchType == DOUBLES_SKETCH) {
compactBytes = maxItems * Double.BYTES + numLevels * Integer.BYTES + 2 * Double.BYTES + DATA_START_ADR_DOUBLE;
updatableBytes = compactBytes + Integer.BYTES;
} else {
compactBytes = maxItems * Float.BYTES + numLevels * Integer.BYTES + 2 * Float.BYTES + DATA_START_ADR_FLOAT;
updatableBytes = compactBytes + Integer.BYTES;
}
compactBytes = maxItems * typeBytes + numLevels * Integer.BYTES + 2 * typeBytes + DATA_START_ADR;
updatableBytes = compactBytes + Integer.BYTES;
if (printGrowthScheme) {
printf("%10d %,10d %,20d %,13d %,15d\n", numLevels, maxItems, maxN, compactBytes, updatableBytes);
}

0 comments on commit 091635b

Please sign in to comment.