internal PackedWriter(PackedInts.Format format, DataOutput @out, int valueCount, int bitsPerValue, int mem) : base(@out, valueCount, bitsPerValue) { this.Format_Renamed = format; Encoder = BulkOperation.Of(format, bitsPerValue); Iterations = Encoder.ComputeIterations(valueCount, mem); NextBlocks = new byte[Iterations * Encoder.ByteBlockCount()]; NextValues = new long[Iterations * Encoder.ByteValueCount()]; Off = 0; Written = 0; Finished = false; }
internal PackedReaderIterator(PackedInts.Format format, int packedIntsVersion, int valueCount, int bitsPerValue, DataInput @in, int mem) : base(valueCount, bitsPerValue, @in) { this.Format = format; this.PackedIntsVersion = packedIntsVersion; BulkOperation = BulkOperation.Of(format, bitsPerValue); Iterations_Renamed = Iterations(mem); Debug.Assert(valueCount == 0 || Iterations_Renamed > 0); NextBlocks = new byte[Iterations_Renamed * BulkOperation.ByteBlockCount()]; NextValues = new LongsRef(new long[Iterations_Renamed * BulkOperation.ByteValueCount()], 0, 0); NextValues.Offset = NextValues.Longs.Length; Position = -1; }
public static BulkOperation Of(PackedInts.Format format, int bitsPerValue) { if (format == PackedInts.Format.PACKED) { Debug.Assert(PackedBulkOps[bitsPerValue - 1] != null); return PackedBulkOps[bitsPerValue - 1]; } else if (format == PackedInts.Format.PACKED_SINGLE_BLOCK) { Debug.Assert(PackedSingleBlockBulkOps[bitsPerValue - 1] != null); return PackedSingleBlockBulkOps[bitsPerValue - 1]; } else { throw new InvalidOperationException(); } }
/// <summary> /// Compute the number of bytes required to encode a block of values that require /// <code>bitsPerValue</code> bits per value with format <code>format</code>. /// </summary> private static int EncodedSize(PackedInts.Format format, int packedIntsVersion, int bitsPerValue) { long byteCount = format.ByteCount(packedIntsVersion, Lucene41PostingsFormat.BLOCK_SIZE, bitsPerValue); Debug.Assert(byteCount >= 0 && byteCount <= int.MaxValue, byteCount.ToString()); return (int)byteCount; }
/// <summary> /// Compute the number of iterations required to decode <code>BLOCK_SIZE</code> /// values with the provided <seealso cref="Decoder"/>. /// </summary> private static int ComputeIterations(PackedInts.Decoder decoder) { return (int)Math.Ceiling((float)Lucene41PostingsFormat.BLOCK_SIZE / decoder.ByteValueCount()); }
private int[][] ReadPositions(int skip, int numFields, PackedInts.Reader flags, PackedInts.Reader numTerms, int[] termFreqs, int flag, int totalPositions, int[][] positionIndex) { int[][] positions = new int[numFields][]; reader.Reset(vectorsStream, totalPositions); // skip int toSkip = 0; int termIndex = 0; for (int i = 0; i < skip; ++i) { int f = (int)flags.Get(i); int termCount = (int)numTerms.Get(i); if ((f & flag) != 0) { for (int j = 0; j < termCount; ++j) { int freq = termFreqs[termIndex + j]; toSkip += freq; } } termIndex += termCount; } reader.Skip(toSkip); // read doc positions for (int i = 0; i < numFields; ++i) { int f = (int)flags.Get(skip + i); int termCount = (int)numTerms.Get(skip + i); if ((f & flag) != 0) { int totalFreq = positionIndex[i][termCount]; int[] fieldPositions = new int[totalFreq]; positions[i] = fieldPositions; for (int j = 0; j < totalFreq; ) { LongsRef nextPositions = reader.Next(totalFreq - j); for (int k = 0; k < nextPositions.Length; ++k) { fieldPositions[j++] = (int)nextPositions.Longs[nextPositions.Offset + k]; } } } termIndex += termCount; } reader.Skip(totalPositions - reader.Ord()); return positions; }
// field -> term index -> position index private int[][] PositionIndex(int skip, int numFields, PackedInts.Reader numTerms, int[] termFreqs) { int[][] positionIndex = new int[numFields][]; int termIndex = 0; for (int i = 0; i < skip; ++i) { int termCount = (int)numTerms.Get(i); termIndex += termCount; } for (int i = 0; i < numFields; ++i) { int termCount = (int)numTerms.Get(skip + i); positionIndex[i] = new int[termCount + 1]; for (int j = 0; j < termCount; ++j) { int freq = termFreqs[termIndex + j]; positionIndex[i][j + 1] = positionIndex[i][j] + freq; } termIndex += termCount; } return positionIndex; }
/// <summary> /// Same as <seealso cref="#getMutable(int, int, float)"/> with a pre-computed number /// of bits per value and format. /// @lucene.internal /// </summary> public static Mutable GetMutable(int valueCount, int bitsPerValue, PackedInts.Format format) { Debug.Assert(valueCount >= 0); if (format == PackedInts.Format.PACKED_SINGLE_BLOCK) { return Packed64SingleBlock.Create(valueCount, bitsPerValue); } else if (format == PackedInts.Format.PACKED) { switch (bitsPerValue) { case 8: return new Direct8(valueCount); case 16: return new Direct16(valueCount); case 32: return new Direct32(valueCount); case 64: return new Direct64(valueCount); case 24: if (valueCount <= Packed8ThreeBlocks.MAX_SIZE) { return new Packed8ThreeBlocks(valueCount); } break; case 48: if (valueCount <= Packed16ThreeBlocks.MAX_SIZE) { return new Packed16ThreeBlocks(valueCount); } break; } return new Packed64(valueCount, bitsPerValue); } else { throw new InvalidOperationException(); } }
public NumericDocValuesAnonymousInnerClassHelper(MemoryDocValuesProducer outerInstance, long[] decode, PackedInts.Reader ordsReader) { this.outerInstance = outerInstance; this.decode = decode; this.ordsReader = ordsReader; }