@Test public void testBinarySearch() { IntList list = new IntList(); for (int i = 0; i < 65; i++) { list.add(i); } list.add(76); list.add(974); list.add(1115); list.add(2094); Assert.assertEquals(-66, list.binarySearch(70)); Assert.assertEquals(65, list.binarySearch(76)); Assert.assertEquals(-67, list.binarySearch(950)); }
public int binarySearch(int v) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v); } int mid = (low + high - 1) >>> 1; long midVal = buffer[mid]; if (midVal < v) low = mid + 1; else if (midVal > v) high = mid; else return mid; } return -(low + 1); }
IntList implements Mutable { public int binarySearch(int v) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v); } int mid = (low + high - 1) >>> 1; long midVal = buffer[mid]; if (midVal < v) low = mid + 1; else if (midVal > v) high = mid; else return mid; } return -(low + 1); } }
IntList implements Mutable { public int binarySearch(int v) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v); } int mid = (low + high - 1) >>> 1; long midVal = buffer[mid]; if (midVal < v) low = mid + 1; else if (midVal > v) high = mid; else return mid; } return -(low + 1); } IntList();  IntList(int capacity); }
IntList implements Mutable { public int binarySearch(int v) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v); } int mid = (low + high - 1) >>> 1; long midVal = buffer[mid]; if (midVal < v) low = mid + 1; else if (midVal > v) high = mid; else return mid; } return -(low + 1); } IntList();  IntList(int capacity); void add(int value); void add(int index, int element); void addAll(IntList that); void arrayCopy(int srcPos, int dstPos, int length); int binarySearch(int v); void clear(); void clear(int capacity); void ensureCapacity(int capacity); void extendAndSet(int index, int value); int get(int index); int getLast(); int getQuick(int index); int getQuiet(int index); @Override int hashCode(); @Override boolean equals(Object that); @Override String toString(); void increment(int index); void remove(int key); void removeIndex(int index); void set(int index, int element); void setAll(int capacity, int value); void setQuick(int index, int value); int size(); void zero(int value); }
IntList implements Mutable { public int binarySearch(int v) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v); } int mid = (low + high - 1) >>> 1; long midVal = buffer[mid]; if (midVal < v) low = mid + 1; else if (midVal > v) high = mid; else return mid; } return -(low + 1); } IntList();  IntList(int capacity); void add(int value); void add(int index, int element); void addAll(IntList that); void arrayCopy(int srcPos, int dstPos, int length); int binarySearch(int v); void clear(); void clear(int capacity); void ensureCapacity(int capacity); void extendAndSet(int index, int value); int get(int index); int getLast(); int getQuick(int index); int getQuiet(int index); @Override int hashCode(); @Override boolean equals(Object that); @Override String toString(); void increment(int index); void remove(int key); void removeIndex(int index); void set(int index, int element); void setAll(int capacity, int value); void setQuick(int index, int value); int size(); void zero(int value);  }