changeset 8139:1e8812b996bc

Sediment load: Remove simple tail recursive calls from SedimentLoadData.recursiveFindStations(). More carefully this time.
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 26 Aug 2014 11:28:03 +0200
parents 8eb25cbfe242
children 369fbb28f5d0
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java
diffstat 1 files changed, 13 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Tue Aug 26 11:18:03 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Tue Aug 26 11:28:03 2014 +0200
@@ -393,20 +393,19 @@
         int lo, int hi,
         Visitor visitor
     ) {
-        if (lo > hi) {
-            return;
-        }
-        int mid = (lo+hi)/2;
-        Station st = stations[mid];
-        double station = st.getStation();
-        if (station < a) {
-            recursiveFindStations(a, b, mid+1, hi, visitor);
-        } else if (station > b) {
-            recursiveFindStations(a, b, lo, mid-1, visitor);
-        } else {
-            recursiveFindStations(a, b, lo, mid-1, visitor);
-            visitor.visit(st);
-            recursiveFindStations(a, b, mid+1, hi, visitor);
+        while (lo <= hi) {
+            int mid = (lo+hi)/2;
+            Station st = stations[mid];
+            double station = st.getStation();
+            if (station < a) {
+                lo = mid+1;
+            } else if (station > b) {
+                hi = mid-1;
+            } else {
+                recursiveFindStations(a, b, lo, mid-1, visitor);
+                visitor.visit(st);
+                lo = mid+1;
+            }
         }
     }
 

http://dive4elements.wald.intevation.org