public WriteVInt ( int i ) : void | ||
i | int | Smaller values take fewer bytes. Negative numbers are /// supported, but should be avoided. |
Результат | void |
/// <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)); } }
private static void SaveInts(int[] values, int length, DataOutput @out) { Debug.Assert(length > 0); if (length == 1) { @out.WriteVInt(values[0]); } else { bool allEqual = true; for (int i = 1; i < length; ++i) { if (values[i] != values[0]) { allEqual = false; break; } } if (allEqual) { @out.WriteVInt(0); @out.WriteVInt(values[0]); } else { long max = 0; for (int i = 0; i < length; ++i) { max |= (uint)values[i]; } int bitsRequired = PackedInts.BitsRequired(max); @out.WriteVInt(bitsRequired); PackedInts.Writer w = PackedInts.GetWriterNoHeader(@out, PackedInts.Format.PACKED, length, bitsRequired, 1); for (int i = 0; i < length; ++i) { w.Add(values[i]); } w.Finish(); } } }
public override void Write(DataOutput indexOut, bool absolute) { if (absolute) { indexOut.WriteVInt(upto); indexOut.WriteVLong(fp); } else if (fp == lastFP) { // same block Debug.Assert(upto >= lastUpto); int uptoDelta = upto - lastUpto; indexOut.WriteVInt(uptoDelta << 1 | 1); } else { // new block indexOut.WriteVInt(upto << 1); indexOut.WriteVLong(fp - lastFP); } lastUpto = upto; lastFP = fp; }
public override void EncodeTerm(long[] empty, DataOutput output, FieldInfo fieldInfo, BlockTermState _state, bool absolute) { PulsingTermState state = (PulsingTermState) _state; Debug.Debug.Assert((empty.Length == 0); this.absolute = this.absolute || absolute; if (state.bytes == null) { _wrappedPostingsWriter.EncodeTerm(longs, buffer, fieldInfo, state.wrappedState, this.absolute); for (int i = 0; i < longsSize; i++) { output.WriteVLong(longs[i]); } buffer.WriteTo(output); buffer.Reset(); this.absolute = false; } else { output.WriteVInt(state.bytes.Length); output.WriteBytes(state.bytes, 0, state.bytes.Length); this.absolute = this.absolute || absolute; } }