[Dive4elements-commits] [PATCH] A naive algorithm to figure out the "Umhuellende" of a set of WQKms

Wald Commits scm-commit at wald.intevation.org
Sun Jan 13 14:18:20 CET 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1358083084 -3600
# Node ID 43e69af28b3cdf1b25bcf620fa8bc9344c77b222
# Parent  729a5edb03139f9534d690a984d90fff81f33bf5
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.

diff -r 729a5edb0313 -r 43e69af28b3c flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Sat Jan 12 11:30:46 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Sun Jan 13 14:18:04 2013 +0100
@@ -101,8 +101,52 @@
                 return current.q;
             }
         }
+
+        public Node findNode(double pos) {
+            Node current = this;
+            while (current != null) {
+                if (pos < current.a) {
+                    current = current.left;
+                }
+                else if (pos > current.b) {
+                    current = current.right;
+                }
+                return current;
+            }
+            return null;
+        }
+
+        public boolean contains(double c) {
+            return c >= a && c <= b;
+        }
     } // class Node
 
+    /** Class to cache the last found tree leaf in a search for Q.
+     *  Its likely that a neighbored pos search
+     *  results in using the same leaf node. So
+     *  caching this leaf will minimize expensive
+     *  tree traversals.
+     *  Modeled as inner class because the QRangeTree
+     *  itself is a shared data structure.
+     *  Using this class omits interpolation between
+     *  leaves.
+     */
+    public final class QuickQFinder {
+
+        private Node last;
+
+        public QuickQFinder() {
+        }
+
+        public double findQ(double pos) {
+            if (last != null && last.contains(pos)) {
+                return last.q;
+            }
+            last = QRangeTree.this.findNode(pos);
+            return last != null ? last.q : Double.NaN;
+        }
+    } // class QuickQFinder
+
     protected Node root;
 
     public QRangeTree() {
@@ -212,6 +256,10 @@
         return root != null ? root.findQ(pos) : Double.NaN;
     }
 
+    public Node findNode(double pos) {
+        return root != null ? root.findNode(pos) : null;
+    }
+
     protected Node head() {
         Node head = root;
         while (head.left != null) {
diff -r 729a5edb0313 -r 43e69af28b3c flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Sat Jan 12 11:30:46 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Sun Jan 13 14:18:04 2013 +0100
@@ -59,7 +59,7 @@
             this.name = name;
         }
 
-    public QRangeTree getQRangeTree() {
+        public QRangeTree getQRangeTree() {
             return qRangeTree;
         }
 
@@ -540,6 +540,10 @@
         this.rows    = rows;
     }
 
+    public Column [] getColumns() {
+        return columns;
+    }
+
     /** Sort rows (by km). */
     public void sortRows() {
         Collections.sort(rows);


More information about the Dive4elements-commits mailing list