JAL-3383 JAL-3253-applet shortcut binary search when position is out of
[jalview.git] / src / jalview / datamodel / features / FeatureStoreJS.java
index b119aef..37f81a0 100644 (file)
@@ -37,6 +37,7 @@ public class FeatureStoreJS extends FeatureStore
 {
   boolean contactsTainted = true;
 
+
   /**
    * internal reference to features as an ArrayList
    */
@@ -154,12 +155,33 @@ public class FeatureStoreJS extends FeatureStore
     getContactEndOverlaps(from, to, result);
   }
 
+  /**
+   * Locate the first feature start that is at or after this position.
+   * 
+   */
+
+  static int ntotal = 0, ncaught = 0;
+
   @Override
   protected int findFirstBegin(List<SequenceFeature> list, long pos)
   {
-    int start = 0;
-    int end = list.size() - 1;
     int matched = list.size();
+    int end = matched - 1;
+    int start = (end < 0 || list.get(end).begin < pos ? matched : 0);
+    // if (end < 0)
+    // {
+    //
+    // }
+    // else if (start > end)
+    // {
+    // ncaught++;
+    // }
+    // ntotal++;
+    //
+    // System.out.println(
+    // "FSJS " + ncaught + "/" + ntotal + " " + pos + "/"
+    // + (end < 0 ? -1 : list.get(end).begin) + " "
+    // + start + "/" + matched);
 
     while (start <= end)
     {
@@ -177,6 +199,11 @@ public class FeatureStoreJS extends FeatureStore
     return matched;
   }
 
+  /**
+   * Locate the feature start that is after or at this position.
+   * 
+   */
+
   @Override
   protected int findFirstEnd(List<SequenceFeature> list, long pos)
   {
@@ -407,7 +434,7 @@ public class FeatureStoreJS extends FeatureStore
     {
       if (begin <= sf.end)
       {
-        System.out.println("\nFS found " + sf0 + "\nFS in " + sf);
+        // System.out.println("\nFSJS found " + sf0 + "\nFS in " + sf);
         return sf;
       }
       sf = sf.containedBy;