ReadVInt() public method

Reads an int stored in variable-length format. Reads between one and five bytes. Smaller values take fewer bytes. Negative numbers are not supported.

The format is described further in DataOutput#writeVInt(int).

public ReadVInt ( ) : int
return int
Esempio n. 1
0
        /// <summary>
        /// Restore a <seealso cref="ForUtil"/> from a <seealso cref="DataInput"/>.
        /// </summary>
        public ForUtil(DataInput @in)
        {
            int packedIntsVersion = @in.ReadVInt();
            PackedInts.CheckVersion(packedIntsVersion);
            EncodedSizes = new int[33];
            Encoders = new PackedInts.Encoder[33];
            Decoders = new PackedInts.Decoder[33];
            Iterations = new int[33];

            for (int bpv = 1; bpv <= 32; ++bpv)
            {
                int code = @in.ReadVInt();
                int formatId = (int)((uint)code >> 5);
                int bitsPerValue = (code & 31) + 1;

                PackedInts.Format format = PackedInts.Format.ById(formatId);
                Debug.Assert(format.IsSupported(bitsPerValue));
                EncodedSizes[bpv] = EncodedSize(format, packedIntsVersion, bitsPerValue);
                Encoders[bpv] = PackedInts.GetEncoder(format, packedIntsVersion, bitsPerValue);
                Decoders[bpv] = PackedInts.GetDecoder(format, packedIntsVersion, bitsPerValue);
                Iterations[bpv] = ComputeIterations(Decoders[bpv]);
            }
        }
 public override void Read(DataInput indexIn, bool absolute)
 {
     if (absolute)
     {
         upto = indexIn.ReadVInt();
         fp = indexIn.ReadVLong();
     }
     else
     {
         int uptoDelta = indexIn.ReadVInt();
         if ((uptoDelta & 1) == 1)
         {
             // same block
             upto += (int)((uint)uptoDelta >> 1);
         }
         else
         {
             // new block
             upto = (int)((uint)uptoDelta >> 1);
             fp += indexIn.ReadVLong();
         }
     }
     // TODO: we can't do this assert because non-causal
     // int encoders can have upto over the buffer size
     //assert upto < maxBlockSize: "upto=" + upto + " max=" + maxBlockSize;
 }
        public override void DecodeTerm(long[] empty, DataInput input, FieldInfo fieldInfo, BlockTermState _termState,
            bool absolute)
        {
            PulsingTermState termState = (PulsingTermState) _termState;

            Debug.Debug.Assert((empty.Length == 0);
            termState.Absolute = termState.Absolute || absolute;
            // if we have positions, its total TF, otherwise its computed based on docFreq.
            // TODO Double check this is right..
            long count = FieldInfo.IndexOptions_e.DOCS_AND_FREQS_AND_POSITIONS.CompareTo(fieldInfo.IndexOptions) <= 0
                ? termState.TotalTermFreq
                : termState.DocFreq;
            //System.out.println("  count=" + count + " threshold=" + maxPositions);

            if (count <= maxPositions)
            {
                // Inlined into terms dict -- just read the byte[] blob in,
                // but don't decode it now (we only decode when a DocsEnum
                // or D&PEnum is pulled):
                termState.PostingsSize = input.ReadVInt();
                if (termState.Postings == null || termState.Postings.Length < termState.PostingsSize)
                {
                    termState.Postings = new byte[ArrayUtil.Oversize(termState.PostingsSize, 1)];
                }
                // TODO: sort of silly to copy from one big byte[]
                // (the blob holding all inlined terms' blobs for
                // current term block) into another byte[] (just the
                // blob for this term)...
                input.ReadBytes(termState.Postings, 0, termState.PostingsSize);
                //System.out.println("  inlined bytes=" + termState.postingsSize);
                termState.Absolute = termState.Absolute || absolute;
            }
            else
            {
                int longsSize = fields == null ? 0 : fields[fieldInfo.Number];
                if (termState.Longs == null)
                {
                    termState.Longs = new long[longsSize];
                }
                for (int i = 0; i < longsSize; i++)
                {
                    termState.Longs[i] = input.ReadVLong();
                }
                termState.PostingsSize = -1;
                termState.WrappedTermState.DocFreq = termState.DocFreq;
                termState.WrappedTermState.TotalTermFreq = termState.TotalTermFreq;
                _wrappedPostingsReader.DecodeTerm(termState.Longs, input, fieldInfo,
                    termState.WrappedTermState,
                    termState.Absolute);
                termState.Absolute = false;
            }
        }
 public override void Read(DataInput indexIn, bool absolute)
 {
     if (absolute)
     {
         upto = indexIn.ReadVInt();
         fp = indexIn.ReadVLong();
     }
     else
     {
         int uptoDelta = indexIn.ReadVInt();
         if ((uptoDelta & 1) == 1)
         {
             // same block
             upto += (int)((uint)uptoDelta >> 1);
         }
         else
         {
             // new block
             upto = (int)((uint)uptoDelta >> 1);
             fp += indexIn.ReadVLong();
         }
     }
     Debug.Assert(upto < outerInstance.blockSize);
 }
 private void _decodeTerm(DataInput @in, FieldInfo fieldInfo, Lucene41PostingsWriter.IntBlockTermState termState)
 {
     bool fieldHasPositions = fieldInfo.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
     bool fieldHasOffsets = fieldInfo.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
     bool fieldHasPayloads = fieldInfo.HasPayloads();
     if (termState.DocFreq == 1)
     {
         termState.SingletonDocID = @in.ReadVInt();
     }
     else
     {
         termState.SingletonDocID = -1;
         termState.DocStartFP += @in.ReadVLong();
     }
     if (fieldHasPositions)
     {
         termState.PosStartFP += @in.ReadVLong();
         if (termState.TotalTermFreq > Lucene41PostingsFormat.BLOCK_SIZE)
         {
             termState.LastPosBlockOffset = @in.ReadVLong();
         }
         else
         {
             termState.LastPosBlockOffset = -1;
         }
         if ((fieldHasPayloads || fieldHasOffsets) && termState.TotalTermFreq >= Lucene41PostingsFormat.BLOCK_SIZE)
         {
             termState.PayStartFP += @in.ReadVLong();
         }
     }
     if (termState.DocFreq > Lucene41PostingsFormat.BLOCK_SIZE)
     {
         termState.SkipOffset = @in.ReadVLong();
     }
     else
     {
         termState.SkipOffset = -1;
     }
 }
        public override void DecodeTerm(long[] longs, DataInput @in, FieldInfo fieldInfo, BlockTermState _termState, bool absolute)
        {
            Lucene41PostingsWriter.IntBlockTermState termState = (Lucene41PostingsWriter.IntBlockTermState)_termState;
            bool fieldHasPositions = fieldInfo.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
            bool fieldHasOffsets = fieldInfo.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
            bool fieldHasPayloads = fieldInfo.HasPayloads();

            if (absolute)
            {
                termState.DocStartFP = 0;
                termState.PosStartFP = 0;
                termState.PayStartFP = 0;
            }
            if (Version < Lucene41PostingsWriter.VERSION_META_ARRAY) // backward compatibility
            {
                _decodeTerm(@in, fieldInfo, termState);
                return;
            }
            termState.DocStartFP += longs[0];
            if (fieldHasPositions)
            {
                termState.PosStartFP += longs[1];
                if (fieldHasOffsets || fieldHasPayloads)
                {
                    termState.PayStartFP += longs[2];
                }
            }
            if (termState.DocFreq == 1)
            {
                termState.SingletonDocID = @in.ReadVInt();
            }
            else
            {
                termState.SingletonDocID = -1;
            }
            if (fieldHasPositions)
            {
                if (termState.TotalTermFreq > Lucene41PostingsFormat.BLOCK_SIZE)
                {
                    termState.LastPosBlockOffset = @in.ReadVLong();
                }
                else
                {
                    termState.LastPosBlockOffset = -1;
                }
            }
            if (termState.DocFreq > Lucene41PostingsFormat.BLOCK_SIZE)
            {
                termState.SkipOffset = @in.ReadVLong();
            }
            else
            {
                termState.SkipOffset = -1;
            }
        }