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/02/04 19:33:19 UTC

(datasketches-java) 01/01: Minor changes to BoundsRule

This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch minor_changes_to_boundsRule
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git

commit bae6ab5b567fecb0316f3808d0d82da4111e9fb9
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sun Feb 4 11:33:04 2024 -0800

    Minor changes to BoundsRule
---
 .../apache/datasketches/partitions/BoundsRule.java |  7 ++++++-
 .../datasketches/partitions/Partitioner.java       | 22 ++++++++++++++--------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/partitions/BoundsRule.java b/src/main/java/org/apache/datasketches/partitions/BoundsRule.java
index 68dc87bc..ecda05e1 100644
--- a/src/main/java/org/apache/datasketches/partitions/BoundsRule.java
+++ b/src/main/java/org/apache/datasketches/partitions/BoundsRule.java
@@ -33,5 +33,10 @@ public enum BoundsRule {
   /**
    * Include only the lower bound but not the upper bound
    */
-  INCLUDE_LOWER
+  INCLUDE_LOWER,
+  /**
+   * Include none
+   */
+  INCLUDE_NEITHER;
+
 }
diff --git a/src/main/java/org/apache/datasketches/partitions/Partitioner.java b/src/main/java/org/apache/datasketches/partitions/Partitioner.java
index 9bc3eeec..be1247ca 100644
--- a/src/main/java/org/apache/datasketches/partitions/Partitioner.java
+++ b/src/main/java/org/apache/datasketches/partitions/Partitioner.java
@@ -26,6 +26,10 @@ import static java.lang.Math.min;
 import static java.lang.Math.pow;
 import static java.lang.Math.round;
 import static java.util.Collections.unmodifiableList;
+import static org.apache.datasketches.partitions.BoundsRule.INCLUDE_BOTH;
+import static org.apache.datasketches.partitions.BoundsRule.INCLUDE_LOWER;
+import static org.apache.datasketches.partitions.BoundsRule.INCLUDE_NEITHER;
+import static org.apache.datasketches.partitions.BoundsRule.INCLUDE_UPPER;
 import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
 import static org.apache.datasketches.quantilescommon.QuantilesAPI.EMPTY_MSG;
 
@@ -184,33 +188,35 @@ public class Partitioner<T, S extends QuantilesGenericAPI<T> & PartitioningFeatu
 
     public PartitionBoundsRow(final StackElement<T> se) {
       final GenericPartitionBoundaries<T> gpb = se.gpb;
-      this.part = se.part;
-      this.levelPartId = se.levelPartId + "." + part;
       final QuantileSearchCriteria searchCrit = gpb.getSearchCriteria();
       final T[] boundaries = gpb.getBoundaries();
       final int numParts = gpb.getNumPartitions();
+      this.part = se.part;
+      this.levelPartId = se.levelPartId + "." + part;
+      final long num;
+      this.approxNumDeltaItems = num = gpb.getNumDeltaItems()[part];
       if (searchCrit == INCLUSIVE) {
         if (part == 1) {
           lowerBound = gpb.getMinItem();
           upperBound = boundaries[part];
-          rule = BoundsRule.INCLUDE_BOTH;
+          rule = (num == 0) ? INCLUDE_NEITHER : (lowerBound == upperBound) ? INCLUDE_UPPER : INCLUDE_BOTH;
         } else {
           lowerBound = boundaries[part - 1];
           upperBound = boundaries[part];
-          rule = BoundsRule.INCLUDE_UPPER;
+          rule = (num == 0) ? INCLUDE_NEITHER : INCLUDE_UPPER;
         }
-      } else { //EXCLUSIVE
+      }
+      else { //EXCLUSIVE
         if (part == numParts) {
           lowerBound = boundaries[part - 1];
           upperBound = gpb.getMaxItem();
-          rule = BoundsRule.INCLUDE_BOTH;
+          rule = (num == 0) ? INCLUDE_NEITHER : (lowerBound == upperBound) ? INCLUDE_LOWER : INCLUDE_BOTH;
         } else {
           lowerBound = boundaries[part - 1];
           upperBound = boundaries[part];
-          rule = BoundsRule.INCLUDE_LOWER;
+          rule = (num == 0) ? INCLUDE_NEITHER : INCLUDE_LOWER;
         }
       }
-      approxNumDeltaItems = gpb.getNumDeltaItems()[part];
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org