@Override public final long readLong() throws IOException { if (8 <= (bufferLength-bufferPosition)) { final int i1 = ((buffer[bufferPosition++] & 0xff) << 24) | ((buffer[bufferPosition++] & 0xff) << 16) | ((buffer[bufferPosition++] & 0xff) << 8) | (buffer[bufferPosition++] & 0xff); final int i2 = ((buffer[bufferPosition++] & 0xff) << 24) | ((buffer[bufferPosition++] & 0xff) << 16) | ((buffer[bufferPosition++] & 0xff) << 8) | (buffer[bufferPosition++] & 0xff); return (((long)i1) << 32) | (i2 & 0xFFFFFFFFL); } else { return super.readLong(); } }
@Override boolean advanceExactWithinBlock(IndexedDISI disi, int target) throws IOException { final int targetInBlock = target & 0xFFFF; final int targetWordIndex = targetInBlock >>> 6; for (int i = disi.wordIndex + 1; i <= targetWordIndex; ++i) { disi.word = disi.slice.readLong(); disi.numberOfOnes += Long.bitCount(disi.word); } disi.wordIndex = targetWordIndex; long leftBits = disi.word >>> target; disi.index = disi.numberOfOnes - Long.bitCount(leftBits); return (leftBits & 1L) != 0; } },
@Override public long readLong(long pos) throws IOException { slice.seek(pos); return slice.readLong(); }
/** * Reads CRC32 value as a 64-bit long from the input. * @throws CorruptIndexException if CRC is formatted incorrectly (wrong bits set) * @throws IOException if an i/o error occurs */ static long readCRC(IndexInput input) throws IOException { long value = input.readLong(); if ((value & 0xFFFFFFFF00000000L) != 0) { throw new CorruptIndexException("Illegal CRC-32 checksum: " + value, input); } return value; }
@Override boolean advanceWithinBlock(IndexedDISI disi, int target) throws IOException { final int targetInBlock = target & 0xFFFF; final int targetWordIndex = targetInBlock >>> 6; for (int i = disi.wordIndex + 1; i <= targetWordIndex; ++i) { disi.word = disi.slice.readLong(); disi.numberOfOnes += Long.bitCount(disi.word); } disi.wordIndex = targetWordIndex; long leftBits = disi.word >>> target; if (leftBits != 0L) { disi.doc = target + Long.numberOfTrailingZeros(leftBits); disi.index = disi.numberOfOnes - Long.bitCount(leftBits); return true; } while (++disi.wordIndex < 1024) { disi.word = disi.slice.readLong(); if (disi.word != 0) { disi.index = disi.numberOfOnes; disi.numberOfOnes += Long.bitCount(disi.word); disi.doc = disi.block | (disi.wordIndex << 6) | Long.numberOfTrailingZeros(disi.word); return true; } } return false; } @Override
@Override public long get(int index) { final int blockOffset = index / valuesPerBlock; final long skip = ((long) blockOffset) << 3; try { in.seek(startPointer + skip); long block = in.readLong(); final int offsetInBlock = index % valuesPerBlock; return (block >>> (offsetInBlock * bitsPerValue)) & mask; } catch (IOException e) { throw new IllegalStateException("failed", e); } }
/** Load metadata from the given {@link IndexInput}. * @see DirectMonotonicReader#getInstance(Meta, RandomAccessInput) */ public static Meta loadMeta(IndexInput metaIn, long numValues, int blockShift) throws IOException { Meta meta = new Meta(numValues, blockShift); for (int i = 0; i < meta.numBlocks; ++i) { meta.mins[i] = metaIn.readLong(); meta.avgs[i] = Float.intBitsToFloat(metaIn.readInt()); meta.offsets[i] = metaIn.readLong(); meta.bpvs[i] = metaIn.readByte(); } return meta; }
private static void readInts24(IndexInput in, int count, int[] docIDs) throws IOException { int i; for (i = 0; i < count - 7; i += 8) { long l1 = in.readLong(); long l2 = in.readLong(); long l3 = in.readLong(); docIDs[i] = (int) (l1 >>> 40); docIDs[i+1] = (int) (l1 >>> 16) & 0xffffff; docIDs[i+2] = (int) (((l1 & 0xffff) << 8) | (l2 >>> 56)); docIDs[i+3] = (int) (l2 >>> 32) & 0xffffff; docIDs[i+4] = (int) (l2 >>> 8) & 0xffffff; docIDs[i+5] = (int) (((l2 & 0xff) << 16) | (l3 >>> 48)); docIDs[i+6] = (int) (l3 >>> 24) & 0xffffff; docIDs[i+7] = (int) l3 & 0xffffff; } for (; i < count; ++i) { docIDs[i] = (Short.toUnsignedInt(in.readShort()) << 8) | Byte.toUnsignedInt(in.readByte()); } }
@Override public final long readLong() throws IOException { try { return guard.getLong(curBuf); } catch (BufferUnderflowException e) { return super.readLong(); } catch (NullPointerException npe) { throw new AlreadyClosedException("Already closed: " + this); } }
/** Seek {@code input} to the directory offset. */ private static void seekDir(IndexInput input) throws IOException { input.seek(input.length() - CodecUtil.footerLength() - 8); long offset = input.readLong(); input.seek(offset); }
@Override public boolean next() throws IOException { if (countLeft >= 0) { if (countLeft == 0) { return false; } countLeft--; } try { in.readBytes(packedValue, 0, packedValue.length); } catch (EOFException eofe) { assert countLeft == -1; return false; } docID = in.readInt(); if (singleValuePerDoc == false) { if (longOrds) { ord = in.readLong(); } else { ord = in.readInt(); } } else { ord = docID; } return true; }
private void readFields(IndexInput meta, FieldInfos infos) throws IOException { for (int fieldNumber = meta.readInt(); fieldNumber != -1; fieldNumber = meta.readInt()) { FieldInfo info = infos.fieldInfo(fieldNumber); if (info == null) { throw new CorruptIndexException("Invalid field number: " + fieldNumber, meta); } else if (!info.hasNorms()) { throw new CorruptIndexException("Invalid field: " + info.name, meta); } NormsEntry entry = new NormsEntry(); entry.docsWithFieldOffset = meta.readLong(); entry.docsWithFieldLength = meta.readLong(); entry.numDocsWithField = meta.readInt(); entry.bytesPerNorm = meta.readByte(); switch (entry.bytesPerNorm) { case 0: case 1: case 2: case 4: case 8: break; default: throw new CorruptIndexException("Invalid bytesPerValue: " + entry.bytesPerNorm + ", field: " + info.name, meta); } entry.normsOffset = meta.readLong(); norms.put(info.number, entry); } }
@Override public void markOrds(long count, LongBitSet ordBitSet) throws IOException { if (countLeft < count) { throw new IllegalStateException("only " + countLeft + " points remain, but " + count + " were requested"); } long fp = in.getFilePointer() + packedValue.length; if (singleValuePerDoc == false) { fp += Integer.BYTES; } for(long i=0;i<count;i++) { in.seek(fp); long ord; if (longOrds) { ord = in.readLong(); } else { ord = in.readInt(); } assert ordBitSet.get(ord) == false: "ord=" + ord + " i=" + i + " was seen twice from " + this; ordBitSet.set(ord); fp += bytesPerDoc; } }
private static void readInts24(IndexInput in, int count, IntersectVisitor visitor) throws IOException { int i; for (i = 0; i < count - 7; i += 8) { long l1 = in.readLong(); long l2 = in.readLong(); long l3 = in.readLong(); visitor.visit((int) (l1 >>> 40)); visitor.visit((int) (l1 >>> 16) & 0xffffff); visitor.visit((int) (((l1 & 0xffff) << 8) | (l2 >>> 56))); visitor.visit((int) (l2 >>> 32) & 0xffffff); visitor.visit((int) (l2 >>> 8) & 0xffffff); visitor.visit((int) (((l2 & 0xff) << 16) | (l3 >>> 48))); visitor.visit((int) (l3 >>> 24) & 0xffffff); visitor.visit((int) l3 & 0xffffff); } for (; i < count; ++i) { visitor.visit((Short.toUnsignedInt(in.readShort()) << 8) | Byte.toUnsignedInt(in.readByte())); } } }
@Override public final long readLong() throws IOException { try { return curBuf.getLong(); } catch (BufferUnderflowException e) { return super.readLong(); } catch (NullPointerException npe) { throw new AlreadyClosedException("Already closed: " + this); } }
/** Load metadata from the given {@link IndexInput}. * @see DirectMonotonicReader#getInstance(Meta, RandomAccessInput) */ public static Meta loadMeta(IndexInput metaIn, long numValues, int blockShift) throws IOException { Meta meta = new Meta(numValues, blockShift); for (int i = 0; i < meta.numBlocks; ++i) { meta.mins[i] = metaIn.readLong(); meta.avgs[i] = Float.intBitsToFloat(metaIn.readInt()); meta.offsets[i] = metaIn.readLong(); meta.bpvs[i] = metaIn.readByte(); } return meta; }
private void seekDir(IndexInput input) throws IOException { input.seek(input.length() - CodecUtil.footerLength() - 8); long dirOffset = input.readLong(); input.seek(dirOffset); }
private void seekDir(IndexInput in) throws IOException { in.seek(in.length() - CodecUtil.footerLength() - 8); in.seek(in.readLong()); } private void checkFieldSummary(SegmentInfo info, IndexInput in, TermsReader field, TermsReader previous) throws IOException {
/** Seek {@code input} to the directory offset. */ private void seekDir(IndexInput input, long dirOffset) throws IOException { input.seek(input.length() - CodecUtil.footerLength() - 8); dirOffset = input.readLong(); input.seek(dirOffset); }