JAL-98 use Profile to store consensus, ResidueCount for fast compact
[jalview.git] / src / jalview / ext / android / ContainerHelpers.java
index cae77b5..f536819 100644 (file)
@@ -74,4 +74,29 @@ class ContainerHelpers
     }
     return ~lo; // value not present
   }
+
+  // This is Arrays.binarySearch(), but doesn't do any argument validation.
+  static int binarySearch(short[] array, int size, short value)
+  {
+    int lo = 0;
+    int hi = size - 1;
+    while (lo <= hi)
+    {
+      final int mid = (lo + hi) >>> 1;
+      final int midVal = array[mid];
+      if (midVal < value)
+      {
+        lo = mid + 1;
+      }
+      else if (midVal > value)
+      {
+        hi = mid - 1;
+      }
+      else
+      {
+        return mid; // value found
+      }
+    }
+    return ~lo; // value not present
+  }
 }