Repository navigation
Implemented Inclusion of min/max for Floats, Doubles and Items Sorted Views. #547
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| package org.apache.datasketches.quantilescommon; | ||
|
|
||
| import static org.apache.datasketches.quantilescommon.IncludeMinMax.DoublesPair; | ||
| import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE; | ||
| import static org.apache.datasketches.quantilescommon.QuantilesAPI.EMPTY_MSG; | ||
| import static org.apache.datasketches.quantilescommon.QuantilesUtil.getNaturalRank; | ||
|
|
@@ -34,24 +35,36 @@ public final class DoublesSketchSortedView implements DoublesSortedView { | |
| private final double[] quantiles; | ||
| private final long[] cumWeights; //cumulative natural weights | ||
| private final long totalN; | ||
| private final double maxItem; | ||
| private final double minItem; | ||
|
|
||
| /** | ||
| * Construct from elements, also used in testing. | ||
| * @param quantiles sorted array of quantiles | ||
| * @param cumWeights sorted, monotonically increasing cumulative weights. | ||
| * @param totalN the total number of items presented to the sketch. | ||
| * @param maxItem of type double | ||
| * @param minItem of type double | ||
| * @param sk the underlying quantile sketch. | ||
| */ | ||
| public DoublesSketchSortedView(final double[] quantiles, final long[] cumWeights, final long totalN, | ||
| final double maxItem, final double minItem) { | ||
| this.quantiles = quantiles; | ||
| this.cumWeights = cumWeights; | ||
| public DoublesSketchSortedView( | ||
| final double[] quantiles, | ||
| final long[] cumWeights, | ||
| final QuantilesDoublesAPI sk) { | ||
| final DoublesPair dPair = | ||
| IncludeMinMax.includeDoublesMinMax(quantiles, cumWeights, sk.getMaxItem(), sk.getMinItem()); | ||
| this.quantiles = dPair.quantiles; | ||
| this.cumWeights = dPair.cumWeights; | ||
| this.totalN = sk.getN(); | ||
| } | ||
|
|
||
| //Used for testing | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constructors like this are ... not great. We should really be trying to find ways to test w/o special constructors like this. Not gonna "require changes" because of it, but just noting it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the tests would be very difficult to reproduce without this. |
||
| DoublesSketchSortedView( | ||
| final double[] quantiles, | ||
| final long[] cumWeights, | ||
| final long totalN, | ||
| final double maxItem, | ||
| final double minItem) { | ||
| final DoublesPair dPair = | ||
| IncludeMinMax.includeDoublesMinMax(quantiles, cumWeights, maxItem, minItem); | ||
| this.quantiles = dPair.quantiles; | ||
| this.cumWeights = dPair.cumWeights; | ||
| this.totalN = totalN; | ||
| this.maxItem = maxItem; | ||
| this.minItem = minItem; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -61,12 +74,13 @@ public long[] getCumulativeWeights() { | |
|
|
||
| @Override | ||
| public double getMaxItem() { | ||
| return maxItem; | ||
| final int top = quantiles.length - 1; | ||
| return quantiles[top]; | ||
| } | ||
|
|
||
| @Override | ||
| public double getMinItem() { | ||
| return minItem; | ||
| return quantiles[0]; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unclear why using this instead of srcNumLevels+1 as before, but gonna trust it's fine either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without studying closely, the
srcNumLevels + 1makes it seem like we are increasing the size of the levelsArr, when we are not. It is the same size as the original, but with different offsets.