@Test public void testGetIndex() { Entry[] entries = new Entry[] { makeEntry(COL_START, "valStart"), makeEntry("01col1", "val1"), makeEntry("02col2", "val2"), makeEntry("03col3", "val3"), makeEntry("04emptycol", ""), makeEntry(COL_END, "valEnd"), }; BufferPage bp = buildFromEntryArray(entries, entries.length); for(int i=0; i<entries.length; i++) { assertEquals(i, bp.getIndex(entries[i].getColumn())); } assertEquals(-1, bp.getIndex(StaticArrayBuffer.of(COL_START.substring(0, 1).getBytes()))); assertEquals(-entries.length - 1, bp.getIndex(StaticArrayBuffer.of(VERY_END.getBytes()))); }
public int getIndex(final StaticBuffer column) { int low = 0; int high = offsetIndex.length - 1; int compare; int mid; while (low <= high) { mid = (low + high) >>> 1; Preconditions.checkArgument(column instanceof StaticArrayBuffer); compare = -((StaticArrayBuffer) column).compareTo(rawData, offsetIndex[mid] + 1, offsetIndex[mid] + 1 + rawData[offsetIndex[mid]]); if (compare < 0) { low = mid + 1; } else if (compare > 0) { high = mid - 1; } else { return mid; } } return -(low + 1); }
BufferPage { public int getIndex(final StaticBuffer column) { int low = 0; int high = offsetIndex.length - 1; int compare; int mid; while (low <= high) { mid = (low + high) >>> 1; Preconditions.checkArgument(column instanceof StaticArrayBuffer); compare = -((StaticArrayBuffer) column).compareTo(rawData, offsetIndex[mid] + 1, offsetIndex[mid] + 1 + rawData[offsetIndex[mid]]); if (compare < 0) { low = mid + 1; } else if (compare > 0) { high = mid - 1; } else { return mid; } } return -(low + 1); } }
BufferPage { public int getIndex(final StaticBuffer column) { int low = 0; int high = offsetIndex.length - 1; int compare; int mid; while (low <= high) { mid = (low + high) >>> 1; Preconditions.checkArgument(column instanceof StaticArrayBuffer); compare = -((StaticArrayBuffer) column).compareTo(rawData, offsetIndex[mid] + 1, offsetIndex[mid] + 1 + rawData[offsetIndex[mid]]); if (compare < 0) { low = mid + 1; } else if (compare > 0) { high = mid - 1; } else { return mid; } } return -(low + 1); } BufferPage(final int[] indices, final byte[] data); }
BufferPage { public int getIndex(final StaticBuffer column) { int low = 0; int high = offsetIndex.length - 1; int compare; int mid; while (low <= high) { mid = (low + high) >>> 1; Preconditions.checkArgument(column instanceof StaticArrayBuffer); compare = -((StaticArrayBuffer) column).compareTo(rawData, offsetIndex[mid] + 1, offsetIndex[mid] + 1 + rawData[offsetIndex[mid]]); if (compare < 0) { low = mid + 1; } else if (compare > 0) { high = mid - 1; } else { return mid; } } return -(low + 1); } BufferPage(final int[] indices, final byte[] data); boolean isEmpty(); int getIndex(final StaticBuffer column); Entry get(final int index); Entry getNoCopy(final int index); int numEntries(); int byteSize(); static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize); List<BufferPage> merge(Entry[] add, int iaddp, int addLimit, Entry[] del, int idelp, int delLimit, int maxPageSize); }
BufferPage { public int getIndex(final StaticBuffer column) { int low = 0; int high = offsetIndex.length - 1; int compare; int mid; while (low <= high) { mid = (low + high) >>> 1; Preconditions.checkArgument(column instanceof StaticArrayBuffer); compare = -((StaticArrayBuffer) column).compareTo(rawData, offsetIndex[mid] + 1, offsetIndex[mid] + 1 + rawData[offsetIndex[mid]]); if (compare < 0) { low = mid + 1; } else if (compare > 0) { high = mid - 1; } else { return mid; } } return -(low + 1); } BufferPage(final int[] indices, final byte[] data); boolean isEmpty(); int getIndex(final StaticBuffer column); Entry get(final int index); Entry getNoCopy(final int index); int numEntries(); int byteSize(); static List<BufferPage> merge(List<BufferPage> pagesToMerge, int maxPageSize); List<BufferPage> merge(Entry[] add, int iaddp, int addLimit, Entry[] del, int idelp, int delLimit, int maxPageSize); static final int[] EMPTY_INDEX; static final byte[] EMPTY_DATA; }