@Override public SeekStatus seekCeil(BytesRef text) throws IOException { // locate block: narrow to block range with index, then search blocks final long block; long indexPos = binarySearchIndex(text); if (indexPos < 0) { block = 0; } else { long low = indexPos << BLOCK_INTERVAL_SHIFT; long high = Math.min(numIndexValues - 1, low + BLOCK_INTERVAL_MASK); block = Math.max(low, binarySearchBlock(text, low, high)); } // position before block, then scan to term. input.seek(addresses.get(block)); currentOrd = (block << INTERVAL_SHIFT) - 1; while (next() != null) { int cmp = term.compareTo(text); if (cmp == 0) { return SeekStatus.FOUND; } else if (cmp > 0) { return SeekStatus.NOT_FOUND; } } return SeekStatus.END; }
@Override public void seekExact(long ord) throws IOException { long block = ord >>> INTERVAL_SHIFT; if (block != currentOrd >>> INTERVAL_SHIFT) { // switch to different block input.seek(addresses.get(block)); readHeader(); } currentOrd = ord; int offset = (int) (ord & INTERVAL_MASK); if (offset == 0) { readFirstTerm(); } else { input.seek(currentBlockStart + offsets[offset-1]); readTerm(offset); } }
@Override public BytesRef next() throws IOException { currentOrd++; if (currentOrd >= numValues) { return null; } else { int offset = (int) (currentOrd & INTERVAL_MASK); if (offset == 0) { // switch to next block readHeader(); readFirstTerm(); } else { readTerm(offset); } return term; } }
private CompressedBinaryTermsEnum getTermsEnum(IndexInput input) throws IOException { return new CompressedBinaryTermsEnum(input); }
private void readHeader() throws IOException { firstTerm.length = input.readVInt(); input.readBytes(firstTerm.bytes, 0, firstTerm.length); input.readBytes(buffer, 0, INTERVAL_COUNT-1); if (buffer[0] == -1) { readShortAddresses(); } else { readByteAddresses(); } currentBlockStart = input.getFilePointer(); }