IndexV2 implements Index { @Override public int findEntry(long msb, long lsb) { int lowIndex = 0; int highIndex = entries.remaining() / IndexEntryV2.SIZE - 1; float lowValue = Long.MIN_VALUE; float highValue = Long.MAX_VALUE; float targetValue = msb; while (lowIndex <= highIndex) { int guessIndex = lowIndex + Math.round( (highIndex - lowIndex) * (targetValue - lowValue) / (highValue - lowValue)); int position = entries.position() + guessIndex * IndexEntryV2.SIZE; long m = entries.getLong(position); if (msb < m) { highIndex = guessIndex - 1; highValue = m; } else if (msb > m) { lowIndex = guessIndex + 1; lowValue = m; } else { long l = entries.getLong(position + 8); if (lsb < l) { highIndex = guessIndex - 1; highValue = m; } else if (lsb > l) { lowIndex = guessIndex + 1; lowValue = m; } else { return position / IndexEntryV2.SIZE; } } } return -1; } IndexV2(Buffer entries); @Override Set<UUID> getUUIDs(); @Override int findEntry(long msb, long lsb); @Override int size(); @Override int count(); @Override IndexEntryV2 entry(int i);  }
@Test public void testFindEntry() throws Exception { Buffer buffer = Buffer.allocate(4 * IndexEntryV2.SIZE); buffer.duplicate() .putLong(1).putLong(1).putInt(0).putInt(0).putInt(0).putInt(0).put((byte) 0) .putLong(1).putLong(3).putInt(0).putInt(0).putInt(0).putInt(0).put((byte) 0) .putLong(3).putLong(1).putInt(0).putInt(0).putInt(0).putInt(0).put((byte) 0) .putLong(3).putLong(3).putInt(0).putInt(0).putInt(0).putInt(0).put((byte) 0); IndexV2 index = new IndexV2(buffer); assertEquals(-1, index.findEntry(1, 0)); assertEquals(0, index.findEntry(1, 1)); assertEquals(-1, index.findEntry(1, 2)); assertEquals(1, index.findEntry(1, 3)); assertEquals(-1, index.findEntry(3, 0)); assertEquals(2, index.findEntry(3, 1)); assertEquals(-1, index.findEntry(3, 2)); assertEquals(3, index.findEntry(3, 3)); }