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

leirui pushed a commit to branch research/M4-visualization
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/research/M4-visualization by 
this push:
     new 568b07d9ea polish
568b07d9ea is described below

commit 568b07d9ea7a4009c2191a2064dd41a855a47dd6
Author: Lei Rui <[email protected]>
AuthorDate: Wed Apr 12 20:43:42 2023 +0800

    polish
---
 .../file/metadata/statistics/StepRegress.java      | 31 +++++++++++++++++-----
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/StepRegress.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/StepRegress.java
index 918f2ddf2e..ed9ead7a1f 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/StepRegress.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/StepRegress.java
@@ -416,12 +416,7 @@ public class StepRegress {
           String.format(
               "t out of range. input within [%s,%s]", segmentKeys.get(0), 
segmentKeys.getLast()));
     }
-    int seg = 0;
-    for (; seg < segmentKeys.size() - 1; seg++) {
-      if (t <= segmentKeys.get(seg + 1)) { // t < the right end of the segment 
interval
-        break;
-      }
-    }
+    int seg = binarySearch(segmentKeys, t);
     // we have fixed that the first status is always tilt,
     // so for indexes starting from 0, even id is tilt, odd id is level.
     if (seg % 2 == 0) { // tilt
@@ -430,4 +425,28 @@ public class StepRegress {
       return segmentIntercepts.get(seg);
     }
   }
+
+  // find firstly strictly greater than or equal to the element in a sorted 
array
+  public int binarySearch(DoubleArrayList segmentKeys, double targetT) {
+    int start = 0;
+    int end = segmentKeys.size() - 1;
+    int ans = -1;
+    while (start <= end) {
+      int mid = (start + end) / 2;
+      // Move to right side if target is greater.
+      if (segmentKeys.get(mid) < targetT) {
+        start = mid + 1;
+      } else // Move left side.
+      {
+        ans = mid;
+        end = mid - 1;
+      }
+    }
+    if (ans == 0) {
+      return ans; // means that targetT equals the first segment keys, 
therefore ans is not the
+      // right point of the segment
+    } else {
+      return ans - 1; // the id of the segment
+    }
+  }
 }

Reply via email to