You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2024/03/26 22:13:10 UTC
(datasketches-java) 01/01: Add getNumRetained to SortedView.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch add_getNumRetained_to_SortedView
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit aad1c7c0665a22ed02ff53e46a4d24378ef62784
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Tue Mar 26 15:12:56 2024 -0700
Add getNumRetained to SortedView.
This is easy to add and is useful for doing analysis from the sorted
view.
---
.../org/apache/datasketches/kll/KllFloatsSketchSortedView.java | 5 +++++
.../datasketches/quantilescommon/DoublesSketchSortedView.java | 5 +++++
.../apache/datasketches/quantilescommon/ItemsSketchSortedView.java | 7 ++++++-
.../java/org/apache/datasketches/quantilescommon/SortedView.java | 6 ++++++
src/main/java/org/apache/datasketches/req/ReqSketchSortedView.java | 5 +++++
5 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/datasketches/kll/KllFloatsSketchSortedView.java b/src/main/java/org/apache/datasketches/kll/KllFloatsSketchSortedView.java
index fc64c0d1..52320dd0 100644
--- a/src/main/java/org/apache/datasketches/kll/KllFloatsSketchSortedView.java
+++ b/src/main/java/org/apache/datasketches/kll/KllFloatsSketchSortedView.java
@@ -103,6 +103,11 @@ public final class KllFloatsSketchSortedView implements FloatsSortedView {
return totalN;
}
+ @Override
+ public int getNumRetained() {
+ return quantiles.length;
+ }
+
@Override
public float getQuantile(final double rank, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
diff --git a/src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java b/src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java
index b0332369..89300851 100644
--- a/src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java
+++ b/src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java
@@ -74,6 +74,11 @@ public final class DoublesSketchSortedView implements DoublesSortedView {
return totalN;
}
+ @Override
+ public int getNumRetained() {
+ return quantiles.length;
+ }
+
@Override
public double getQuantile(final double rank, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
diff --git a/src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java b/src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java
index e3228e3e..db0a612b 100644
--- a/src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java
+++ b/src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java
@@ -46,7 +46,7 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T> {
private final T maxItem;
private final T minItem;
private final Class<T> clazz;
- private final double normRankErr;
+ private final double normRankErr;//assumes PMF type error
/**
* Construct from elements, also used in testing.
@@ -112,6 +112,11 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T> {
return totalN;
}
+ @Override
+ public int getNumRetained() {
+ return quantiles.length;
+ }
+
@Override
@SuppressWarnings("unchecked")
public GenericPartitionBoundaries<T> getPartitionBoundaries(final int numEquallySized,
diff --git a/src/main/java/org/apache/datasketches/quantilescommon/SortedView.java b/src/main/java/org/apache/datasketches/quantilescommon/SortedView.java
index 5fb50291..93803552 100644
--- a/src/main/java/org/apache/datasketches/quantilescommon/SortedView.java
+++ b/src/main/java/org/apache/datasketches/quantilescommon/SortedView.java
@@ -48,6 +48,12 @@ public interface SortedView {
*/
long getN();
+ /**
+ * Gets the number of quantiles retained by the sketch.
+ * @return the number of quantiles retained by the sketch
+ */
+ int getNumRetained();
+
/**
* Returns true if this sorted view is empty.
* @return true if this sorted view is empty.
diff --git a/src/main/java/org/apache/datasketches/req/ReqSketchSortedView.java b/src/main/java/org/apache/datasketches/req/ReqSketchSortedView.java
index 40842221..7f97a431 100644
--- a/src/main/java/org/apache/datasketches/req/ReqSketchSortedView.java
+++ b/src/main/java/org/apache/datasketches/req/ReqSketchSortedView.java
@@ -94,6 +94,11 @@ public final class ReqSketchSortedView implements FloatsSortedView {
return totalN;
}
+ @Override
+ public int getNumRetained() {
+ return quantiles.length;
+ }
+
@Override
public float getQuantile(final double rank, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org