Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small changes in the update single and update weighted methods. #489

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static org.apache.datasketches.common.Util.isOdd;
import static org.apache.datasketches.kll.KllHelper.findLevelToCompact;
import static org.apache.datasketches.kll.KllSketch.DEFAULT_M;
import static org.apache.datasketches.kll.KllSketch.SketchStructure.UPDATABLE;

import java.util.Arrays;
import java.util.Random;
Expand Down Expand Up @@ -317,6 +316,7 @@ private static void randomlyHalveUpDoubles(final double[] buf, final int start,

//Called from KllDoublesSketch::update and merge
static void updateDouble(final KllDoublesSketch dblSk, final double item) {
dblSk.updateMinMax(item);
int freeSpace = dblSk.levelsArr[0];
assert (freeSpace >= 0);
if (freeSpace == 0) {
Expand All @@ -331,10 +331,12 @@ static void updateDouble(final KllDoublesSketch dblSk, final double item) {
dblSk.setDoubleItemsArrayAt(nextPos, item);
}

//Called from KllDoublesSketch::update with weight
static void updateDouble(final KllDoublesSketch dblSk, final double item, final int weight) {
if (weight < dblSk.getLevelsArray(UPDATABLE)[0]) {
for (int i = 0; i < weight; i++) { dblSk.update(item); }
if (weight < dblSk.levelsArr[0]) {
for (int i = 0; i < weight; i++) { updateDouble(dblSk, item); }
} else {
dblSk.updateMinMax(item);
final KllHeapDoublesSketch tmpSk = new KllHeapDoublesSketch(dblSk.getK(), DEFAULT_M, item, weight);
dblSk.merge(tmpSk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ public String toString(final boolean withSummary, final boolean withDetail) {
public void update(final double item) {
if (Double.isNaN(item)) { return; } //ignore
if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
updateMinMax(item);
KllDoublesHelper.updateDouble(this, item);
kllDoublesSV = null;
}
Expand All @@ -335,8 +334,7 @@ public void update(final double item, final int weight) {
if (Double.isNaN(item)) { return; } //ignore
if (readOnly) { throw new SketchesArgumentException(TGT_IS_READ_ONLY_MSG); }
if (weight < 1) { throw new SketchesArgumentException("Weight is less than one."); }
if (Double.isNaN(item)) { return; } //ignore
updateMinMax(item);
if (weight == 1) { KllDoublesHelper.updateDouble(this, item); }
KllDoublesHelper.updateDouble(this, item, weight);
kllDoublesSV = null;
}
Expand Down Expand Up @@ -407,7 +405,7 @@ private final void refreshSortedView() {

abstract void setMinItem(double item);

private void updateMinMax(final double item) {
void updateMinMax(final double item) {
if (isEmpty()) {
setMinItem(item);
setMaxItem(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ public void printlnTest() {
printf("%s\n", s);
}

private final static boolean enablePrinting = true;
private final static boolean enablePrinting = false;

/**
* @param format the format
Expand Down
Loading