SearchableByteBufferUtil { public int binarySearch(int col, short value) { final int rows = mmappedDataFile.getNumberOfRows(); if (rows == 0) { return -1; } int low = 0; int high = rows - 1; while (low <= high) { final int middle = (low + high) / 2; final short midValue = mmappedDataFile.getShort(middle, col); if (value > midValue) { low = middle + 1; } else if (value < midValue) { high = middle - 1; } else { return middle; } } return -(low + 1); } SearchableByteBufferUtil(GenericRowColumnDataFileReader mmappedDataFile); int binarySearch(int col, short value); int binarySearch(int col, double value, int from, int to); int binarySearch(int col, double value); int binarySearch(int col, int value, int from, int to); int binarySearch(int col, int value); int binarySearch(int col, long value, int from, int to); int binarySearch(int col, long value); int binarySearch(int col, float value, int from, int to); int binarySearch(int col, float value); int binarySearch(int col, String value, int padLength, char padChar); int binarySearch(int col, String value);  }
@Test public void testBinarySearch() { for(int i = 0; i < DISTINCT_VALUES; ++i) { Assert.assertEquals(_searchableByteBufferUtil.binarySearch(0, _shorts[i]), i); Assert.assertEquals(_searchableByteBufferUtil.binarySearch(1, _ints[i]), i); Assert.assertEquals(_searchableByteBufferUtil.binarySearch(2, _longs[i]), i); Assert.assertEquals(_searchableByteBufferUtil.binarySearch(3, _floats[i]), i); Assert.assertEquals(_searchableByteBufferUtil.binarySearch(4, _doubles[i]), i); } }