Skip to content

Commit

Permalink
Merge pull request #519 from apache/copy_changes_from_Kll_Doubles_to_…
Browse files Browse the repository at this point in the history
…Floats_Items

Copy changes from kll doubles to floats items
  • Loading branch information
leerho authored Mar 7, 2024
2 parents 53e967b + 05924fb commit 077ac98
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,15 @@ private static void compressWhileUpdatingSketch(final KllFloatsSketch fltSk) {
}

//assumes readOnly = false and UPDATABLE, called from KllFloatsSketch::merge
static void mergeFloatImpl(final KllFloatsSketch mySketch,
final KllFloatsSketch otherFltSk) {
static void mergeFloatImpl(final KllFloatsSketch mySketch, final KllFloatsSketch otherFltSk) {
if (otherFltSk.isEmpty()) { return; }

//capture my key mutable fields before doing any merging
final boolean myEmpty = mySketch.isEmpty();
final float myMin = myEmpty ? Float.NaN : mySketch.getMinItem();
final float myMax = myEmpty ? Float.NaN : mySketch.getMaxItem();
final int myMinK = mySketch.getMinK();
final long finalN = mySketch.getN() + otherFltSk.getN();
final long finalN = Math.addExact(mySketch.getN(), otherFltSk.getN());

//buffers that are referenced multiple times
final int otherNumLevels = otherFltSk.getNumLevels();
Expand Down Expand Up @@ -398,7 +397,7 @@ private static int[] generalFloatsCompress(
curLevel++; // start out at level 0

// If we are at the current top level, add an empty level above it for convenience,
// but do not increment numLevels until later
// but do not actually increment numLevels until later
if (curLevel == (numLevels - 1)) {
inLevels[curLevel + 2] = inLevels[curLevel + 1];
}
Expand Down Expand Up @@ -465,7 +464,7 @@ private static int[] generalFloatsCompress(
return new int[] {numLevels, targetItemCount, currentItemCount};
}

private static void populateFloatWorkArrays(
private static void populateFloatWorkArrays( //workBuf and workLevels are modified
final float[] workbuf, final int[] worklevels, final int provisionalNumLevels,
final int myCurNumLevels, final int[] myCurLevelsArr, final float[] myCurFloatItemsArr,
final int otherNumLevels, final int[] otherLevelsArr, final float[] otherFloatItemsArr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public QuantilesFloatsSketchIterator iterator() {
@Override
public final void merge(final KllSketch other) {
if (readOnly || sketchStructure != UPDATABLE) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
if (this == other) { throw new SketchesArgumentException(SELF_MERGE_MSG); }
final KllFloatsSketch othFltSk = (KllFloatsSketch)other;
if (othFltSk.isEmpty()) { return; }
KllFloatsHelper.mergeFloatImpl(this, othFltSk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void incNumLevels() {

@Override
void setNumLevels(final int numLevels) {
//the heap sketch computes num levels from the array itself, so this is not used on-heap
//the heap sketch computes num levels from the array itself, so this is not used on-heap
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/datasketches/kll/KllItemsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static <T> void mergeItemImpl(final KllItemsSketch<T> mySketch,
final Object myMin = myEmpty ? null : mySketch.getMinItem();
final Object myMax = myEmpty ? null : mySketch.getMaxItem();
final int myMinK = mySketch.getMinK();
final long finalN = mySketch.getN() + otherItmSk.getN();
final long finalN = Math.addExact(mySketch.getN(), otherItmSk.getN());

//buffers that are referenced multiple times
final int otherNumLevels = otherItmSk.getNumLevels();
Expand Down Expand Up @@ -399,7 +399,7 @@ private static <T> int[] generalItemsCompress(
curLevel++; // start out at level 0

// If we are at the current top level, add an empty level above it for convenience,
// but do not increment numLevels until later
// but do not actually increment numLevels until later
if (curLevel == (numLevels - 1)) {
inLevels[curLevel + 2] = inLevels[curLevel + 1];
}
Expand Down Expand Up @@ -466,7 +466,7 @@ private static <T> int[] generalItemsCompress(
return new int[] {numLevels, targetItemCount, currentItemCount};
}

private static <T> void populateItemWorkArrays(
private static <T> void populateItemWorkArrays( //workBuf and workLevels are modified
final Object[] workbuf, final int[] worklevels, final int provisionalNumLevels,
final int myCurNumLevels, final int[] myCurLevelsArr, final Object[] myCurItemsArr,
final int otherNumLevels, final int[] otherLevelsArr, final Object[] otherItemsArr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public QuantilesGenericSketchIterator<T> iterator() {
@Override
public final void merge(final KllSketch other) {
if (readOnly || sketchStructure != UPDATABLE) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
if (this == other) { throw new SketchesArgumentException(SELF_MERGE_MSG); }
final KllItemsSketch<T> othItmSk = (KllItemsSketch<T>)other;
if (othItmSk.isEmpty()) { return; }
KllItemsHelper.mergeItemImpl(this, othItmSk, comparator);
Expand Down

0 comments on commit 077ac98

Please sign in to comment.