internal ChunkIterator(CompressingStoredFieldsReader outerInstance, int startDocId) { this.outerInstance = outerInstance; this.docBase = -1; bytes = new BytesRef(); spare = new BytesRef(); numStoredFields = new int[1]; lengths = new int[1]; IndexInput @in = outerInstance.fieldsStream; @in.Seek(0); fieldsStream = new BufferedChecksumIndexInput(@in); fieldsStream.Seek(outerInstance.indexReader.GetStartPointer(startDocId)); }
/// <summary> /// Go to the chunk containing the provided <paramref name="doc"/> ID. /// </summary> internal void Next(int doc) { if (Debugging.AssertsEnabled) { Debugging.Assert(doc >= this.docBase + this.chunkDocs, "{0} {1} {2}", doc, this.docBase, this.chunkDocs); } fieldsStream.Seek(outerInstance.indexReader.GetStartPointer(doc)); int docBase = fieldsStream.ReadVInt32(); int chunkDocs = fieldsStream.ReadVInt32(); if (docBase < this.docBase + this.chunkDocs || docBase + chunkDocs > outerInstance.numDocs) { throw new CorruptIndexException($"Corrupted: current docBase={this.docBase}, current numDocs={this.chunkDocs}, new docBase={docBase}, new numDocs={chunkDocs} (resource={fieldsStream})"); } this.docBase = docBase; this.chunkDocs = chunkDocs; if (chunkDocs > numStoredFields.Length) { int newLength = ArrayUtil.Oversize(chunkDocs, 4); numStoredFields = new int[newLength]; lengths = new int[newLength]; } if (chunkDocs == 1) { numStoredFields[0] = fieldsStream.ReadVInt32(); lengths[0] = fieldsStream.ReadVInt32(); } else { int bitsPerStoredFields = fieldsStream.ReadVInt32(); if (bitsPerStoredFields == 0) { Arrays.Fill(numStoredFields, 0, chunkDocs, fieldsStream.ReadVInt32()); } else if (bitsPerStoredFields > 31) { throw new CorruptIndexException("bitsPerStoredFields=" + bitsPerStoredFields + " (resource=" + fieldsStream + ")"); } else { PackedInt32s.IReaderIterator it = PackedInt32s.GetReaderIteratorNoHeader(fieldsStream, PackedInt32s.Format.PACKED, outerInstance.packedIntsVersion, chunkDocs, bitsPerStoredFields, 1); for (int i = 0; i < chunkDocs; ++i) { numStoredFields[i] = (int)it.Next(); } } int bitsPerLength = fieldsStream.ReadVInt32(); if (bitsPerLength == 0) { Arrays.Fill(lengths, 0, chunkDocs, fieldsStream.ReadVInt32()); } else if (bitsPerLength > 31) { throw new CorruptIndexException($"bitsPerLength={bitsPerLength}"); } else { PackedInt32s.IReaderIterator it = PackedInt32s.GetReaderIteratorNoHeader(fieldsStream, PackedInt32s.Format.PACKED, outerInstance.packedIntsVersion, chunkDocs, bitsPerLength, 1); for (int i = 0; i < chunkDocs; ++i) { lengths[i] = (int)it.Next(); } } } }
/// <summary> /// Go to the chunk containing the provided doc ID. /// </summary> internal void Next(int doc) { Debug.Assert(doc >= DocBase + ChunkDocs, doc + " " + DocBase + " " + ChunkDocs); FieldsStream.Seek(OuterInstance.IndexReader.GetStartPointer(doc)); int docBase = FieldsStream.ReadVInt(); int chunkDocs = FieldsStream.ReadVInt(); if (docBase < this.DocBase + this.ChunkDocs || docBase + chunkDocs > OuterInstance.NumDocs) { throw new CorruptIndexException("Corrupted: current docBase=" + this.DocBase + ", current numDocs=" + this.ChunkDocs + ", new docBase=" + docBase + ", new numDocs=" + chunkDocs + " (resource=" + FieldsStream + ")"); } this.DocBase = docBase; this.ChunkDocs = chunkDocs; if (chunkDocs > NumStoredFields.Length) { int newLength = ArrayUtil.Oversize(chunkDocs, 4); NumStoredFields = new int[newLength]; Lengths = new int[newLength]; } if (chunkDocs == 1) { NumStoredFields[0] = FieldsStream.ReadVInt(); Lengths[0] = FieldsStream.ReadVInt(); } else { int bitsPerStoredFields = FieldsStream.ReadVInt(); if (bitsPerStoredFields == 0) { CollectionsHelper.Fill(NumStoredFields, 0, chunkDocs, FieldsStream.ReadVInt()); } else if (bitsPerStoredFields > 31) { throw new CorruptIndexException("bitsPerStoredFields=" + bitsPerStoredFields + " (resource=" + FieldsStream + ")"); } else { PackedInts.ReaderIterator it = PackedInts.GetReaderIteratorNoHeader(FieldsStream, PackedInts.Format.PACKED, OuterInstance.PackedIntsVersion, chunkDocs, bitsPerStoredFields, 1); for (int i = 0; i < chunkDocs; ++i) { NumStoredFields[i] = (int)it.Next(); } } int bitsPerLength = FieldsStream.ReadVInt(); if (bitsPerLength == 0) { CollectionsHelper.Fill(Lengths, 0, chunkDocs, FieldsStream.ReadVInt()); } else if (bitsPerLength > 31) { throw new CorruptIndexException("bitsPerLength=" + bitsPerLength); } else { PackedInts.ReaderIterator it = PackedInts.GetReaderIteratorNoHeader(FieldsStream, PackedInts.Format.PACKED, OuterInstance.PackedIntsVersion, chunkDocs, bitsPerLength, 1); for (int i = 0; i < chunkDocs; ++i) { Lengths[i] = (int)it.Next(); } } } }
internal ChunkIterator(CompressingStoredFieldsReader outerInstance, int startDocId) { this.OuterInstance = outerInstance; this.DocBase = -1; Bytes = new BytesRef(); Spare = new BytesRef(); NumStoredFields = new int[1]; Lengths = new int[1]; IndexInput @in = outerInstance.FieldsStream; @in.Seek(0); FieldsStream = new BufferedChecksumIndexInput(@in); FieldsStream.Seek(outerInstance.IndexReader.GetStartPointer(startDocId)); }