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

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit ed83e6a4cb8c16bcf4e0ecfc1dfe53e2235b9c5e
Author: Alex Herbert <aherb...@apache.org>
AuthorDate: Tue Mar 25 14:40:44 2025 +0000

    Remove unused range arguments when creating the updating interval.
    
    Note that the range is implied from the min and max index in the
    indices.
    
    The index out of bounds (IOOB) exceptions are not explicitly raised by
    the internal methods. The public API will validate indices and array
    ranges before calling the internal methods. The documentation of IOOB
    exceptions by internal methods has been removed.
---
 .../commons/numbers/arrays/IndexSupport.java       |  6 +---
 .../apache/commons/numbers/arrays/QuickSelect.java |  8 ++---
 .../commons/numbers/arrays/SelectionTest.java      |  4 +--
 .../numbers/arrays/UpdatingIntervalTest.java       | 38 ++++++++++------------
 4 files changed, 22 insertions(+), 34 deletions(-)

diff --git 
a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/IndexSupport.java
 
b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/IndexSupport.java
index da6fce4b..6449d8c8 100644
--- 
a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/IndexSupport.java
+++ 
b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/IndexSupport.java
@@ -31,15 +31,11 @@ final class IndexSupport {
     /**
      * Returns an interval that covers the specified indices {@code k}.
      *
-     * @param left Lower bound of data (inclusive).
-     * @param right Upper bound of data (inclusive).
      * @param k Indices.
      * @param n Count of indices (must be strictly positive).
-     * @throws IndexOutOfBoundsException if any index {@code k} is not within 
the
-     * sub-range {@code [left, right]}
      * @return the interval
      */
-    static UpdatingInterval createUpdatingInterval(int left, int right, int[] 
k, int n) {
+    static UpdatingInterval createUpdatingInterval(int[] k, int n) {
         // Note: A typical use case is to have a few indices. Thus the 
heuristics
         // in this method should be very fast when n is small.
         // We have a choice between a KeyUpdatingInterval which requires
diff --git 
a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/QuickSelect.java
 
b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/QuickSelect.java
index f049608a..791f8b96 100644
--- 
a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/QuickSelect.java
+++ 
b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/QuickSelect.java
@@ -526,8 +526,6 @@ final class QuickSelect {
      * @param k Indices (may be destructively modified).
      * @param n Count of indices.
      * @return the count of used indices
-     * @throws IndexOutOfBoundsException if any index {@code k} is not within 
the
-     * sub-range {@code [left, right]}
      */
     static int select(double[] a, int left, int right, int[] k, int n) {
         if (n < 1) {
@@ -539,7 +537,7 @@ final class QuickSelect {
         }
 
         // Interval creation validates the indices are in [left, right]
-        final UpdatingInterval keys = 
IndexSupport.createUpdatingInterval(left, right, k, n);
+        final UpdatingInterval keys = IndexSupport.createUpdatingInterval(k, 
n);
 
         // Save number of used indices
         final int count = IndexSupport.countIndices(keys, n);
@@ -1794,8 +1792,6 @@ final class QuickSelect {
      * @param right Upper bound of data (inclusive).
      * @param k Indices (may be destructively modified).
      * @param n Count of indices.
-     * @throws IndexOutOfBoundsException if any index {@code k} is not within 
the
-     * sub-range {@code [left, right]}
      */
     static void select(int[] a, int left, int right, int[] k, int n) {
         if (n == 1) {
@@ -1804,7 +1800,7 @@ final class QuickSelect {
         }
 
         // Interval creation validates the indices are in [left, right]
-        final UpdatingInterval keys = 
IndexSupport.createUpdatingInterval(left, right, k, n);
+        final UpdatingInterval keys = IndexSupport.createUpdatingInterval(k, 
n);
 
         // Note: If the keys are not separated then they are effectively a 
single key.
         // Any split of keys separated by the sort select size
diff --git 
a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SelectionTest.java
 
b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SelectionTest.java
index e67a8815..3244922c 100644
--- 
a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SelectionTest.java
+++ 
b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SelectionTest.java
@@ -523,7 +523,7 @@ class SelectionTest {
             }
             replaceNegativeZeros(a, 0, right);
             QuickSelect.dualPivotQuickSelect(a, 0, right,
-                IndexSupport.createUpdatingInterval(0, right, k, k.length),
+                IndexSupport.createUpdatingInterval(k, k.length),
                 QuickSelect.dualPivotFlags(2, 5));
             restoreNegativeZeros(a, 0, right);
         }, false);
@@ -1325,7 +1325,7 @@ class SelectionTest {
                 return;
             }
             QuickSelect.dualPivotQuickSelect(a, 0, right,
-                IndexSupport.createUpdatingInterval(0, right, k, k.length),
+                IndexSupport.createUpdatingInterval(k, k.length),
                 QuickSelect.dualPivotFlags(2, 5));
         }, false);
     }
diff --git 
a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/UpdatingIntervalTest.java
 
b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/UpdatingIntervalTest.java
index 4d9ba348..4329c7a7 100644
--- 
a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/UpdatingIntervalTest.java
+++ 
b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/UpdatingIntervalTest.java
@@ -99,9 +99,7 @@ class UpdatingIntervalTest {
     @ParameterizedTest
     @MethodSource(value = {"testIndices"})
     void testUpdateIndexSupport(int[] indices, int[] k) {
-        final int l = k[0];
-        final int r = k[k.length - 1];
-        assertUpdate((x, n) -> IndexSupport.createUpdatingInterval(l, r, x, 
n), indices, k);
+        assertUpdate((x, n) -> IndexSupport.createUpdatingInterval(x, n), 
indices, k);
     }
 
     @ParameterizedTest
@@ -121,9 +119,7 @@ class UpdatingIntervalTest {
     @ParameterizedTest
     @MethodSource(value = {"testIndices"})
     void testSplitIndexSupport(int[] indices, int[] k) {
-        final int l = k[0];
-        final int r = k[k.length - 1];
-        assertSplit((x, n) -> IndexSupport.createUpdatingInterval(l, r, x, n), 
indices, k);
+        assertSplit((x, n) -> IndexSupport.createUpdatingInterval(x, n), 
indices, k);
     }
 
     /**
@@ -299,59 +295,59 @@ class UpdatingIntervalTest {
 
         // 1 key
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 2, new int[] {1}, 
1).getClass());
+            IndexSupport.createUpdatingInterval(new int[] {1}, 1).getClass());
 
         // 2 close keys
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 2, new int[] {2, 1}, 
2).getClass());
+            IndexSupport.createUpdatingInterval(new int[] {2, 1}, 
2).getClass());
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 2, new int[] {1, 2}, 
2).getClass());
+            IndexSupport.createUpdatingInterval(new int[] {1, 2}, 
2).getClass());
 
         // 2 unsorted keys
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 1000, new int[] {200, 1}, 
2).getClass());
+            IndexSupport.createUpdatingInterval(new int[] {200, 1}, 
2).getClass());
 
         // Sorted number of keys saturating the range
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 20, new int[] {1, 2, 3, 4, 
5, 6, 7, 8, 9, 10, 11}, 11).getClass());
+            IndexSupport.createUpdatingInterval(new int[] {1, 2, 3, 4, 5, 6, 
7, 8, 9, 10, 11}, 11).getClass());
         // Sorted keys with duplicates
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 10, new int[] {1, 1, 2, 2, 
3, 3, 4, 4, 5, 5}, 10).getClass());
+            IndexSupport.createUpdatingInterval(new int[] {1, 1, 2, 2, 3, 3, 
4, 4, 5, 5}, 10).getClass());
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 1000, new int[] {100, 100, 
200, 200, 300, 300, 400, 400, 500, 500}, 10).getClass());
+            IndexSupport.createUpdatingInterval(new int[] {100, 100, 200, 200, 
300, 300, 400, 400, 500, 500}, 10).getClass());
         // Small number of keys saturating the range
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 20, new int[] {11, 2, 3, 4, 
5, 6, 7, 8, 9, 10, 1}, 11).getClass());
+            IndexSupport.createUpdatingInterval(new int[] {11, 2, 3, 4, 5, 6, 
7, 8, 9, 10, 1}, 11).getClass());
         // Keys over a huge range
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, Integer.MAX_VALUE - 1,
+            IndexSupport.createUpdatingInterval(
                 new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, Integer.MAX_VALUE - 
1}, 11).getClass());
 
         // Small number of sorted keys over a moderate range
         int[] k = IntStream.range(0, 30).map(i -> i * 64) .toArray();
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 30 * 64, k.clone(), 
k.length).getClass());
+            IndexSupport.createUpdatingInterval(k.clone(), 
k.length).getClass());
         // Same keys not sorted
         reverse(k, 0, k.length);
         Assertions.assertEquals(BitIndexUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 30 * 64, k.clone(), 
k.length).getClass());
+            IndexSupport.createUpdatingInterval(k.clone(), 
k.length).getClass());
         // Same keys over a huge range
         k[k.length - 1] = Integer.MAX_VALUE - 1;
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, Integer.MAX_VALUE - 1, k, 
k.length).getClass());
+            IndexSupport.createUpdatingInterval(k, k.length).getClass());
 
         // Moderate number of sorted keys over a moderate range
         k = IntStream.range(0, 3000).map(i -> i * 64) .toArray();
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 3000 * 64, k.clone(), 
k.length).getClass());
+            IndexSupport.createUpdatingInterval(k.clone(), 
k.length).getClass());
         // Same keys not sorted
         reverse(k, 0, k.length);
         Assertions.assertEquals(BitIndexUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, 3000 * 64, k.clone(), 
k.length).getClass());
+            IndexSupport.createUpdatingInterval(k.clone(), 
k.length).getClass());
         // Same keys over a huge range
         k[k.length - 1] = Integer.MAX_VALUE - 1;
         Assertions.assertEquals(KeyUpdatingInterval.class,
-            IndexSupport.createUpdatingInterval(0, Integer.MAX_VALUE - 1, 
k.clone(), k.length).getClass());
+            IndexSupport.createUpdatingInterval(k.clone(), 
k.length).getClass());
     }
 
     /**

Reply via email to