replaced implementation with java.util.Arrays.binarySearch
@@ -60,7 +60,7 @@ class SortedIntList extends AbstractList<Integer> {
* That is, -1 means the probe would be inserted at the very beginning.
*/
public int find(int probe) {
- return binarySearch(data, 0, size, probe);
+ return Arrays.binarySearch(data, 0, size, probe);
}
@Override
@@ -152,25 +152,4 @@ class SortedIntList extends AbstractList<Integer> {
System.arraycopy(data,idx+1,data,idx,size-(idx+1));
size--;
}
-
- /**
- * Switch to {@code java.util.Arrays.binarySearch} when we depend on Java6.
- */
- private static int binarySearch(int[] a, int start, int end, int key) {
- int lo = start, hi = end-1; // search range is [lo,hi]
-
- // invariant lo<=hi
- while (lo <= hi) {
- int pivot = (lo + hi)/2;
- int v = a[pivot];
-
- if (v < key) // needs to search upper half
- lo = pivot+1;
- else if (v > key) // needs to search lower half
- hi = pivot-1;
- else // eureka!
- return pivot;
- }
- return -(lo + 1); // insertion point
- }
}
