Skip to content
Permalink
Browse files
Interim 13
  • Loading branch information
leerho committed Apr 6, 2022
1 parent e93e8cd commit 5a67bc7214690228754f15c5d35117799c876525
Showing 14 changed files with 1,728 additions and 1,640 deletions.
@@ -36,12 +36,12 @@
import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryPreInts;
import static org.apache.datasketches.kll.KllPreambleUtil.setMemorySerVer;
import static org.apache.datasketches.kll.KllSketch.Error.MUST_NOT_CALL;
import static org.apache.datasketches.kll.KllSketch.Error.SRC_MUST_BE_DIRECT;
import static org.apache.datasketches.kll.KllSketch.Error.SRC_MUST_BE_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.Memory;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;

@@ -67,15 +67,12 @@ private KllDirectDoublesSketch(final WritableMemory wmem, final MemoryRequestSer
}

/**
* Wrap a sketch around the given source Memory containing sketch data that originated from
* this sketch.
* @param srcMem a WritableMemory that contains data.
* @param memReqSvr the given MemoryRequestServer to request a larger WritableMemory
* @return instance of this sketch
* Heapifies the given Memory object and returns a KllDoublesSketch
* @param mem the given Memory object.
* @return a KllDoublesSketch
*/
public static KllDirectDoublesSketch writableWrap(final WritableMemory srcMem, final MemoryRequestServer memReqSvr) {
final KllMemoryValidate memVal = new KllMemoryValidate(srcMem);
return new KllDirectDoublesSketch(srcMem, memReqSvr, memVal);
public static KllDoublesSketch heapify(final Memory mem) {
return KllDoublesSketch.heapify(mem);
}

/**
@@ -119,6 +116,18 @@ static KllDirectDoublesSketch newInstance(final int k, final int m, final Writab
return new KllDirectDoublesSketch(dstMem, memReqSvr, memVal);
}

/**
* Wrap a sketch around the given source Memory containing sketch data that originated from
* this sketch.
* @param srcMem a WritableMemory that contains data.
* @param memReqSvr the given MemoryRequestServer to request a larger WritableMemory
* @return instance of this sketch
*/
public static KllDirectDoublesSketch writableWrap(final WritableMemory srcMem, final MemoryRequestServer memReqSvr) {
final KllMemoryValidate memVal = new KllMemoryValidate(srcMem);
return new KllDirectDoublesSketch(srcMem, memReqSvr, memVal);
}

/**
* Returns an approximation to the Cumulative Distribution Function (CDF), which is the
* cumulative analog of the PMF, of the input stream given a set of splitPoint (values).
@@ -141,7 +150,7 @@ static KllDirectDoublesSketch newInstance(final int k, final int m, final Writab
* in positions 0 through j of the returned PMF array.
*/
public double[] getCDF(final double[] splitPoints) {
return getDoublesPmfOrCdf(splitPoints, true);
return KllDoublesHelper.getDoublesPmfOrCdf(this, splitPoints, true);
}

/**
@@ -183,7 +192,7 @@ public double[] getCDF(final double[] splitPoints) {
* splitPoint, with the exception that the last interval will include maximum value.
*/
public double[] getPMF(final double[] splitPoints) {
return getDoublesPmfOrCdf(splitPoints, false);
return KllDoublesHelper.getDoublesPmfOrCdf(this, splitPoints, false);
}

/**
@@ -205,7 +214,7 @@ public double[] getPMF(final double[] splitPoints) {
* @return the approximation to the value at the given fraction
*/
public double getQuantile(final double fraction) {
return getDoublesQuantile(fraction);
return KllDoublesHelper.getDoublesQuantile(this, fraction);
}

/**
@@ -238,7 +247,7 @@ public double getQuantileLowerBound(final double fraction) {
* array.
*/
public double[] getQuantiles(final double[] fractions) {
return getDoublesQuantiles(fractions);
return KllDoublesHelper.getDoublesQuantiles(this, fractions);
}

/**
@@ -284,7 +293,7 @@ public double getQuantileUpperBound(final double fraction) {
* @return an approximate rank of the given value
*/
public double getRank(final double value) {
return getDoubleRank(value);
return KllDoublesHelper.getDoubleRank(this, value);
}

/**
@@ -299,9 +308,8 @@ public KllDoublesSketchIterator iterator() {
* @param other sketch to merge into this one
*/
public void merge(final KllSketch other) {
if (!other.isDirect()) { kllSketchThrow(SRC_MUST_BE_DIRECT); }
if (!other.isDoublesSketch()) { kllSketchThrow(SRC_MUST_BE_DOUBLE); }
mergeDoubleImpl(other);
KllDoublesHelper.mergeDoubleImpl(this, other);
}

/**
@@ -310,7 +318,7 @@ public void merge(final KllSketch other) {
* @param value an item from a stream of items. NaNs are ignored.
*/
public void update(final double value) {
updateDouble(value);
KllDoublesHelper.updateDouble(this, value);
}

@Override
@@ -350,13 +358,13 @@ public void update(final double value) {

@Override
void setDoubleItemsArray(final double[] doubleItems) {
if (!updatable) { kllSketchThrow(TGT_IS_IMMUTABLE); }
if (!updatableMemory) { kllSketchThrow(TGT_IS_IMMUTABLE); }
itemsArrUpdatable.putDoubleArray(0, doubleItems, 0, doubleItems.length);
}

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

@@ -368,7 +376,7 @@ void setDoubleItemsArrayAt(final int index, final double value) {

@Override
void setMaxDoubleValue(final double value) {
if (!updatable) { kllSketchThrow(TGT_IS_IMMUTABLE); }
if (!updatableMemory) { kllSketchThrow(TGT_IS_IMMUTABLE); }
minMaxArrUpdatable.putDouble(Double.BYTES, value);
}

@@ -377,7 +385,7 @@ void setMaxDoubleValue(final double value) {

@Override
void setMinDoubleValue(final double value) {
if (!updatable) { kllSketchThrow(TGT_IS_IMMUTABLE); }
if (!updatableMemory) { kllSketchThrow(TGT_IS_IMMUTABLE); }
minMaxArrUpdatable.putDouble(0, value);
}

@@ -35,12 +35,12 @@
import static org.apache.datasketches.kll.KllPreambleUtil.setMemoryPreInts;
import static org.apache.datasketches.kll.KllPreambleUtil.setMemorySerVer;
import static org.apache.datasketches.kll.KllSketch.Error.MUST_NOT_CALL;
import static org.apache.datasketches.kll.KllSketch.Error.SRC_MUST_BE_DIRECT;
import static org.apache.datasketches.kll.KllSketch.Error.SRC_MUST_BE_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.Memory;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;

@@ -67,15 +67,12 @@ private KllDirectFloatsSketch(final WritableMemory wmem, final MemoryRequestServ
}

/**
* Wrap a sketch around the given source Memory containing sketch data that originated from
* this sketch.
* @param srcMem a WritableMemory that contains data.
* @param memReqSvr the given MemoryRequestServer to request a larger WritableMemory
* @return instance of this sketch
* Heapifies the given Memory object and returns a KllFloatsSketch
* @param mem the given Memory object.
* @return a KllFloatsSketch
*/
public static KllDirectFloatsSketch writableWrap(final WritableMemory srcMem, final MemoryRequestServer memReqSvr) {
final KllMemoryValidate memVal = new KllMemoryValidate(srcMem);
return new KllDirectFloatsSketch(srcMem, memReqSvr, memVal);
public static KllFloatsSketch heapify(final Memory mem) {
return KllFloatsSketch.heapify(mem);
}

/**
@@ -119,6 +116,18 @@ static KllDirectFloatsSketch newInstance(final int k, final int m, final Writabl
return new KllDirectFloatsSketch(dstMem, memReqSvr, memVal);
}

/**
* Wrap a sketch around the given source Memory containing sketch data that originated from
* this sketch.
* @param srcMem a WritableMemory that contains data.
* @param memReqSvr the given MemoryRequestServer to request a larger WritableMemory
* @return instance of this sketch
*/
public static KllDirectFloatsSketch writableWrap(final WritableMemory srcMem, final MemoryRequestServer memReqSvr) {
final KllMemoryValidate memVal = new KllMemoryValidate(srcMem);
return new KllDirectFloatsSketch(srcMem, memReqSvr, memVal);
}

/**
* Returns an approximation to the Cumulative Distribution Function (CDF), which is the
* cumulative analog of the PMF, of the input stream given a set of splitPoint (values).
@@ -141,7 +150,7 @@ static KllDirectFloatsSketch newInstance(final int k, final int m, final Writabl
* in positions 0 through j of the returned PMF array.
*/
public double[] getCDF(final float[] splitPoints) {
return getFloatsPmfOrCdf(splitPoints, true);
return KllFloatsHelper.getFloatsPmfOrCdf(this, splitPoints, true);
}

/**
@@ -183,7 +192,7 @@ public double[] getCDF(final float[] splitPoints) {
* splitPoint, with the exception that the last interval will include maximum value.
*/
public double[] getPMF(final float[] splitPoints) {
return getFloatsPmfOrCdf(splitPoints, false);
return KllFloatsHelper.getFloatsPmfOrCdf(this, splitPoints, false);
}

/**
@@ -205,7 +214,7 @@ public double[] getPMF(final float[] splitPoints) {
* @return the approximation to the value at the given fraction
*/
public float getQuantile(final double fraction) {
return getFloatsQuantile(fraction);
return KllFloatsHelper.getFloatsQuantile(this, fraction);
}

/**
@@ -238,7 +247,7 @@ public float getQuantileLowerBound(final double fraction) {
* array.
*/
public float[] getQuantiles(final double[] fractions) {
return getFloatsQuantiles(fractions);
return KllFloatsHelper.getFloatsQuantiles(this, fractions);
}

/**
@@ -284,7 +293,7 @@ public float getQuantileUpperBound(final double fraction) {
* @return an approximate rank of the given value
*/
public double getRank(final float value) {
return getFloatRank(value);
return KllFloatsHelper.getFloatRank(this, value);
}

/**
@@ -299,9 +308,8 @@ public KllFloatsSketchIterator iterator() {
* @param other sketch to merge into this one
*/
public void merge(final KllSketch other) {
if (!other.isDirect()) { kllSketchThrow(SRC_MUST_BE_DIRECT); }
if (!other.isFloatsSketch()) { kllSketchThrow(SRC_MUST_BE_FLOAT); }
mergeFloatImpl(other);
KllFloatsHelper.mergeFloatImpl(this, other);
}

/**
@@ -310,7 +318,7 @@ public void merge(final KllSketch other) {
* @param value an item from a stream of items. NaNs are ignored.
*/
public void update(final float value) {
updateFloat(value);
KllFloatsHelper.updateFloat(this, value);
}

@Override
@@ -356,13 +364,13 @@ float getMinFloatValue() {

@Override
void setFloatItemsArray(final float[] floatItems) {
if (!updatable) { kllSketchThrow(TGT_IS_IMMUTABLE); }
if (!updatableMemory) { kllSketchThrow(TGT_IS_IMMUTABLE); }
itemsArrUpdatable.putFloatArray(0, floatItems, 0, floatItems.length);
}

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

@@ -371,7 +379,7 @@ void setFloatItemsArrayAt(final int index, final float value) {

@Override
void setMaxFloatValue(final float value) {
if (!updatable) { kllSketchThrow(TGT_IS_IMMUTABLE); }
if (!updatableMemory) { kllSketchThrow(TGT_IS_IMMUTABLE); }
minMaxArrUpdatable.putFloat(Float.BYTES, value);
}

@@ -380,7 +388,7 @@ void setMaxFloatValue(final float value) {

@Override
void setMinFloatValue(final float value) {
if (!updatable) { kllSketchThrow(TGT_IS_IMMUTABLE); }
if (!updatableMemory) { kllSketchThrow(TGT_IS_IMMUTABLE); }
minMaxArrUpdatable.putFloat(0, value);
}

0 comments on commit 5a67bc7

Please sign in to comment.