Exemplo n.º 1
0
        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 PackedInts.NullReader(PendingOff);
            }
            else
            {
                // build a new packed reader
                int bitsRequired = delta < 0 ? 64 : PackedInts.BitsRequired(delta);
                for (int i = 0; i < PendingOff; ++i)
                {
                    Pending[i] -= minValue;
                }
                PackedInts.Mutable mutable = PackedInts.GetMutable(PendingOff, bitsRequired, AcceptableOverheadRatio);
                for (int i = 0; i < PendingOff;)
                {
                    i += mutable.Set(i, Pending, i, PendingOff - i);
                }
                Values[ValuesOff] = mutable;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sole constructor. </summary>
        public BlockPackedReader(IndexInput @in, int packedIntsVersion, int blockSize, long valueCount, bool direct)
        {
            this.ValueCount = valueCount;
            BlockShift      = PackedInts.CheckBlockSize(blockSize, AbstractBlockPackedWriter.MIN_BLOCK_SIZE, AbstractBlockPackedWriter.MAX_BLOCK_SIZE);
            BlockMask       = blockSize - 1;
            int numBlocks = PackedInts.NumBlocks(valueCount, blockSize);

            long[] minValues = null;
            SubReaders = new PackedInts.Reader[numBlocks];
            for (int i = 0; i < numBlocks; ++i)
            {
                int token        = @in.ReadByte() & 0xFF;
                int bitsPerValue = (int)((uint)token >> 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.ReadVLong(@in));
                }
                if (bitsPerValue == 0)
                {
                    SubReaders[i] = new PackedInts.NullReader(blockSize);
                }
                else
                {
                    int size = (int)Math.Min(blockSize, valueCount - (long)i * blockSize);
                    if (direct)
                    {
                        long pointer = @in.FilePointer;
                        SubReaders[i] = PackedInts.GetDirectReaderNoHeader(@in, PackedInts.Format.PACKED, packedIntsVersion, size, bitsPerValue);
                        @in.Seek(pointer + PackedInts.Format.PACKED.ByteCount(packedIntsVersion, size, bitsPerValue));
                    }
                    else
                    {
                        SubReaders[i] = PackedInts.GetReaderNoHeader(@in, PackedInts.Format.PACKED, packedIntsVersion, size, bitsPerValue);
                    }
                }
            }
            this.MinValues = minValues;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sole constructor. </summary>
        public MonotonicBlockPackedReader(IndexInput @in, int packedIntsVersion, int blockSize, long valueCount, bool direct)
        {
            this.ValueCount = valueCount;
            BlockShift      = PackedInts.CheckBlockSize(blockSize, AbstractBlockPackedWriter.MIN_BLOCK_SIZE, AbstractBlockPackedWriter.MAX_BLOCK_SIZE);
            BlockMask       = blockSize - 1;
            int numBlocks = PackedInts.NumBlocks(valueCount, blockSize);

            MinValues  = new long[numBlocks];
            Averages   = new float[numBlocks];
            SubReaders = new PackedInts.Reader[numBlocks];
            for (int i = 0; i < numBlocks; ++i)
            {
                MinValues[i] = @in.ReadVLong();
                Averages[i]  = Number.IntBitsToFloat(@in.ReadInt());
                int bitsPerValue = @in.ReadVInt();
                if (bitsPerValue > 64)
                {
                    throw new Exception("Corrupted");
                }
                if (bitsPerValue == 0)
                {
                    SubReaders[i] = new PackedInts.NullReader(blockSize);
                }
                else
                {
                    int size = (int)Math.Min(blockSize, valueCount - (long)i * blockSize);
                    if (direct)
                    {
                        long pointer = @in.FilePointer;
                        SubReaders[i] = PackedInts.GetDirectReaderNoHeader(@in, PackedInts.Format.PACKED, packedIntsVersion, size, bitsPerValue);
                        @in.Seek(pointer + PackedInts.Format.PACKED.ByteCount(packedIntsVersion, size, bitsPerValue));
                    }
                    else
                    {
                        SubReaders[i] = PackedInts.GetReaderNoHeader(@in, PackedInts.Format.PACKED, packedIntsVersion, size, bitsPerValue);
                    }
                }
            }
        }
        internal override void PackPendingValues()
        {
            Debug.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)
            {
                Pending[i] = ZigZagEncode(Pending[i] - MinValues[ValuesOff] - (long)(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 PackedInts.NullReader(PendingOff);
            }
            else
            {
                int bitsRequired           = maxDelta < 0 ? 64 : PackedInts.BitsRequired(maxDelta);
                PackedInts.Mutable mutable = PackedInts.GetMutable(PendingOff, bitsRequired, AcceptableOverheadRatio);
                for (int i = 0; i < PendingOff;)
                {
                    i += mutable.Set(i, Pending, i, PendingOff - i);
                }
                Values[ValuesOff] = mutable;
            }
        }