internal override void PackPendingValues() { // compute max delta long minValue = pending[0]; long maxValue = pending[0]; for (int i = 1; i < pendingOff; ++i) { minValue = Math.Min(minValue, pending[i]); maxValue = Math.Max(maxValue, pending[i]); } long delta = maxValue - minValue; minValues[valuesOff] = minValue; if (delta == 0) { values[valuesOff] = new PackedInt32s.NullReader(pendingOff); } else { // build a new packed reader int bitsRequired = delta < 0 ? 64 : PackedInt32s.BitsRequired(delta); for (int i = 0; i < pendingOff; ++i) { pending[i] -= minValue; } PackedInt32s.Mutable mutable = PackedInt32s.GetMutable(pendingOff, bitsRequired, acceptableOverheadRatio); for (int i = 0; i < pendingOff;) { i += mutable.Set(i, pending, i, pendingOff - i); } values[valuesOff] = mutable; } }
/// <summary> /// Sole constructor. </summary> public BlockPackedReader(IndexInput @in, int packedIntsVersion, int blockSize, long valueCount, bool direct) { this.valueCount = valueCount; blockShift = PackedInt32s.CheckBlockSize(blockSize, AbstractBlockPackedWriter.MIN_BLOCK_SIZE, AbstractBlockPackedWriter.MAX_BLOCK_SIZE); blockMask = blockSize - 1; int numBlocks = PackedInt32s.NumBlocks(valueCount, blockSize); long[] minValues = null; subReaders = new PackedInt32s.Reader[numBlocks]; for (int i = 0; i < numBlocks; ++i) { int token = @in.ReadByte() & 0xFF; int bitsPerValue = token.TripleShift(AbstractBlockPackedWriter.BPV_SHIFT); if (bitsPerValue > 64) { throw new Exception("Corrupted"); } if ((token & AbstractBlockPackedWriter.MIN_VALUE_EQUALS_0) == 0) { if (minValues == null) { minValues = new long[numBlocks]; } minValues[i] = BlockPackedReaderIterator.ZigZagDecode(1L + BlockPackedReaderIterator.ReadVInt64(@in)); } if (bitsPerValue == 0) { subReaders[i] = new PackedInt32s.NullReader(blockSize); } else { int size = (int)Math.Min(blockSize, valueCount - (long)i * blockSize); if (direct) { long pointer = @in.GetFilePointer(); subReaders[i] = PackedInt32s.GetDirectReaderNoHeader(@in, PackedInt32s.Format.PACKED, packedIntsVersion, size, bitsPerValue); @in.Seek(pointer + PackedInt32s.Format.PACKED.ByteCount(packedIntsVersion, size, bitsPerValue)); } else { subReaders[i] = PackedInt32s.GetReaderNoHeader(@in, PackedInt32s.Format.PACKED, packedIntsVersion, size, bitsPerValue); } } } this.minValues = minValues; }
internal override void PackPendingValues() { if (Debugging.AssertsEnabled) { Debugging.Assert(pendingOff > 0); } minValues[valuesOff] = pending[0]; averages[valuesOff] = pendingOff == 1 ? 0 : (float)(pending[pendingOff - 1] - pending[0]) / (pendingOff - 1); for (int i = 0; i < pendingOff; ++i) { // LUCENENET NOTE: IMPORTANT: The cast to float is critical here for it to work in x86 pending[i] = ZigZagEncode(pending[i] - minValues[valuesOff] - (long)(float)(averages[valuesOff] * (long)i)); } long maxDelta = 0; for (int i = 0; i < pendingOff; ++i) { if (pending[i] < 0) { maxDelta = -1; break; } else { maxDelta = Math.Max(maxDelta, pending[i]); } } if (maxDelta == 0) { values[valuesOff] = new PackedInt32s.NullReader(pendingOff); } else { int bitsRequired = maxDelta < 0 ? 64 : PackedInt32s.BitsRequired(maxDelta); PackedInt32s.Mutable mutable = PackedInt32s.GetMutable(pendingOff, bitsRequired, acceptableOverheadRatio); for (int i = 0; i < pendingOff;) { i += mutable.Set(i, pending, i, pendingOff - i); } values[valuesOff] = mutable; } }
/// <summary> /// Sole constructor. </summary> public MonotonicBlockPackedReader(IndexInput @in, int packedIntsVersion, int blockSize, long valueCount, bool direct) { this.valueCount = valueCount; blockShift = PackedInt32s.CheckBlockSize(blockSize, AbstractBlockPackedWriter.MIN_BLOCK_SIZE, AbstractBlockPackedWriter.MAX_BLOCK_SIZE); blockMask = blockSize - 1; int numBlocks = PackedInt32s.NumBlocks(valueCount, blockSize); minValues = new long[numBlocks]; averages = new float[numBlocks]; subReaders = new PackedInt32s.Reader[numBlocks]; for (int i = 0; i < numBlocks; ++i) { minValues[i] = @in.ReadVInt64(); averages[i] = J2N.BitConversion.Int32BitsToSingle(@in.ReadInt32()); int bitsPerValue = @in.ReadVInt32(); if (bitsPerValue > 64) { throw new Exception("Corrupted"); } if (bitsPerValue == 0) { subReaders[i] = new PackedInt32s.NullReader(blockSize); } else { int size = (int)Math.Min(blockSize, valueCount - (long)i * blockSize); if (direct) { long pointer = @in.GetFilePointer(); subReaders[i] = PackedInt32s.GetDirectReaderNoHeader(@in, PackedInt32s.Format.PACKED, packedIntsVersion, size, bitsPerValue); @in.Seek(pointer + PackedInt32s.Format.PACKED.ByteCount(packedIntsVersion, size, bitsPerValue)); } else { subReaders[i] = PackedInt32s.GetReaderNoHeader(@in, PackedInt32s.Format.PACKED, packedIntsVersion, size, bitsPerValue); } } } }