@Test public void testBinarySearch() { LongMatrix<String> m = new LongMatrix<>(2); for (int i = 0; i < 1000; i++) { int r = m.addRow(); m.set(r, 0, i); m.set(r, 1, i); m.set(r, "s" + i); } int r = m.binarySearch(631, 0); Assert.assertEquals(631, m.get(r, 0)); }
public int binarySearch(long v, int index) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v, index); } int mid = (low + high - 1) >>> 1; long midVal = get(mid, index); if (midVal < v) low = mid + 1; else if (midVal > v) high = mid - 1; else return mid; } return -(low + 1); }
LongMatrix { public int binarySearch(long v, int index) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v, index); } int mid = (low + high - 1) >>> 1; long midVal = get(mid, index); if (midVal < v) low = mid + 1; else if (midVal > v) high = mid - 1; else return mid; } return -(low + 1); } }
LongMatrix { public int binarySearch(long v, int index) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v, index); } int mid = (low + high - 1) >>> 1; long midVal = get(mid, index); if (midVal < v) low = mid + 1; else if (midVal > v) high = mid - 1; else return mid; } return -(low + 1); } @SuppressWarnings("unchecked")  LongMatrix(int columnCount); }
LongMatrix { public int binarySearch(long v, int index) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v, index); } int mid = (low + high - 1) >>> 1; long midVal = get(mid, index); if (midVal < v) low = mid + 1; else if (midVal > v) high = mid - 1; else return mid; } return -(low + 1); } @SuppressWarnings("unchecked")  LongMatrix(int columnCount); int addRow(); int binarySearch(long v, int index); void deleteRow(int r); long get(int r, int c); T get(int r); void set(int r, T obj); void set(int r, int c, long value); int size(); void zapTop(int count); }
LongMatrix { public int binarySearch(long v, int index) { int low = 0; int high = pos; while (low < high) { if (high - low < 65) { return scanSearch(v, index); } int mid = (low + high - 1) >>> 1; long midVal = get(mid, index); if (midVal < v) low = mid + 1; else if (midVal > v) high = mid - 1; else return mid; } return -(low + 1); } @SuppressWarnings("unchecked")  LongMatrix(int columnCount); int addRow(); int binarySearch(long v, int index); void deleteRow(int r); long get(int r, int c); T get(int r); void set(int r, T obj); void set(int r, int c, long value); int size(); void zapTop(int count);  }