Lucene.Net.Store.DataOutput.WriteVInt C# (CSharp) Method

WriteVInt() public method

Writes an int in a variable-length format. Writes between one and five bytes. Smaller values take fewer bytes. Negative numbers are supported, but should be avoided.

VByte is a variable-length format for positive integers is defined where the high-order bit of each byte indicates whether more bytes remain to be read. The low-order seven bits are appended as increasingly more significant bits in the resulting integer value. Thus values from zero to 127 may be stored in a single byte, values from 128 to 16,383 may be stored in two bytes, and so on.

VByte Encoding Example

Value Byte 1 Byte 2 Byte 3
0 00000000
1 00000001
2 00000010
...
127 01111111
128 10000000 00000001
129 10000001 00000001
130 10000010 00000001
...
16,383 11111111 01111111
16,384 10000000 10000000 00000001
16,385 10000001 10000000 00000001
...

this provides compression while still being efficient to decode.

If there is an I/O error writing to the underlying medium.
public WriteVInt ( int i ) : void
i int Smaller values take fewer bytes. Negative numbers are /// supported, but should be avoided.
return void
        public void WriteVInt(int i)
        {
            while ((i & ~0x7F) != 0)
            {
                WriteByte((byte)unchecked((sbyte)((i & 0x7F) | 0x80)));
                i = (int)((uint)i >> 7);
            }
            WriteByte((byte)(sbyte)i);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Create a new <seealso cref="ForUtil"/> instance and save state into <code>out</code>.
        /// </summary>
        public ForUtil(float acceptableOverheadRatio, DataOutput @out)
        {
            @out.WriteVInt(PackedInts.VERSION_CURRENT);
            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)
            {
                PackedInts.FormatAndBits formatAndBits = PackedInts.FastestFormatAndBits(Lucene41PostingsFormat.BLOCK_SIZE, bpv, acceptableOverheadRatio);
                Debug.Assert(formatAndBits.format.IsSupported(formatAndBits.bitsPerValue));
                Debug.Assert(formatAndBits.bitsPerValue <= 32);
                EncodedSizes[bpv] = EncodedSize(formatAndBits.format, PackedInts.VERSION_CURRENT, formatAndBits.bitsPerValue);
                Encoders[bpv] = PackedInts.GetEncoder(formatAndBits.format, PackedInts.VERSION_CURRENT, formatAndBits.bitsPerValue);
                Decoders[bpv] = PackedInts.GetDecoder(formatAndBits.format, PackedInts.VERSION_CURRENT, formatAndBits.bitsPerValue);
                Iterations[bpv] = ComputeIterations(Decoders[bpv]);

                @out.WriteVInt(formatAndBits.format.id << 5 | (formatAndBits.bitsPerValue - 1));
            }
        }
All Usage Examples Of Lucene.Net.Store.DataOutput::WriteVInt