Exemplo n.º 1
0
        /// <summary>
        /// Restore a <see cref="ForUtil"/> from a <see cref="DataInput"/>.
        /// </summary>
        internal ForUtil(DataInput @in)
        {
            int packedIntsVersion = @in.ReadVInt32();

            PackedInt32s.CheckVersion(packedIntsVersion);
            encodedSizes = new int[33];
            encoders     = new PackedInt32s.IEncoder[33];
            decoders     = new PackedInt32s.IDecoder[33];
            iterations   = new int[33];

            for (int bpv = 1; bpv <= 32; ++bpv)
            {
                var code         = @in.ReadVInt32();
                var formatId     = (int)((uint)code >> 5);
                var bitsPerValue = (code & 31) + 1;

                PackedInt32s.Format format = PackedInt32s.Format.ById(formatId);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(format.IsSupported(bitsPerValue));
                }
                encodedSizes[bpv] = EncodedSize(format, packedIntsVersion, bitsPerValue);
                encoders[bpv]     = PackedInt32s.GetEncoder(format, packedIntsVersion, bitsPerValue);
                decoders[bpv]     = PackedInt32s.GetDecoder(format, packedIntsVersion, bitsPerValue);
                iterations[bpv]   = ComputeIterations(decoders[bpv]);
            }
        }
Exemplo n.º 2
0
        static PForDeltaDocIdSet()
        {
            SINGLE_ZERO_BUFFER.Add(0);
            SINGLE_ZERO_BUFFER.Freeze();
            int maxByteBLockCount = 0;

            for (int i = 1; i < ITERATIONS.Length; ++i)
            {
                DECODERS[i] = PackedInt32s.GetDecoder(PackedInt32s.Format.PACKED, PackedInt32s.VERSION_CURRENT, i);
                Debug.Assert(BLOCK_SIZE % DECODERS[i].ByteValueCount == 0);
                ITERATIONS[i]        = BLOCK_SIZE / DECODERS[i].ByteValueCount;
                BYTE_BLOCK_COUNTS[i] = ITERATIONS[i] * DECODERS[i].ByteBlockCount;
                maxByteBLockCount    = Math.Max(maxByteBLockCount, DECODERS[i].ByteBlockCount);
            }
            MAX_BYTE_BLOCK_COUNT = maxByteBLockCount;
        }
        private void Refill()
        {
            int  token        = @in.ReadByte() & 0xFF;
            bool minEquals0   = (token & AbstractBlockPackedWriter.MIN_VALUE_EQUALS_0) != 0;
            int  bitsPerValue = (int)((uint)token >> AbstractBlockPackedWriter.BPV_SHIFT);

            if (bitsPerValue > 64)
            {
                throw new IOException("Corrupted");
            }
            long minValue = minEquals0 ? 0L : ZigZagDecode(1L + ReadVInt64(@in));

            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(minEquals0 || minValue != 0);
            }

            if (bitsPerValue == 0)
            {
                Arrays.Fill(values, minValue);
            }
            else
            {
                PackedInt32s.IDecoder decoder = PackedInt32s.GetDecoder(PackedInt32s.Format.PACKED, packedIntsVersion, bitsPerValue);
                int iterations = blockSize / decoder.ByteValueCount;
                int blocksSize = iterations * decoder.ByteBlockCount;
                if (blocks == null || blocks.Length < blocksSize)
                {
                    blocks = new byte[blocksSize];
                }

                int valueCount  = (int)Math.Min(this.valueCount - ord, blockSize);
                int blocksCount = (int)PackedInt32s.Format.PACKED.ByteCount(packedIntsVersion, valueCount, bitsPerValue);
                @in.ReadBytes(blocks, 0, blocksCount);

                decoder.Decode(blocks, 0, values, 0, iterations);

                if (minValue != 0)
                {
                    for (int i = 0; i < valueCount; ++i)
                    {
                        values[i] += minValue;
                    }
                }
            }
            off = 0;
        }
Exemplo n.º 4
0
        static PForDeltaDocIdSet()
        {
            int maxByteBLockCount = 0;

            for (int i = 1; i < ITERATIONS.Length; ++i)
            {
                DECODERS[i] = PackedInt32s.GetDecoder(PackedInt32s.Format.PACKED, PackedInt32s.VERSION_CURRENT, i);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(BLOCK_SIZE % DECODERS[i].ByteValueCount == 0);
                }
                ITERATIONS[i]        = BLOCK_SIZE / DECODERS[i].ByteValueCount;
                BYTE_BLOCK_COUNTS[i] = ITERATIONS[i] * DECODERS[i].ByteBlockCount;
                maxByteBLockCount    = Math.Max(maxByteBLockCount, DECODERS[i].ByteBlockCount);
            }
            MAX_BYTE_BLOCK_COUNT = maxByteBLockCount;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a new <see cref="ForUtil"/> instance and save state into <paramref name="out"/>.
        /// </summary>
        internal ForUtil(float acceptableOverheadRatio, DataOutput @out)
        {
            @out.WriteVInt32(PackedInt32s.VERSION_CURRENT);
            encodedSizes = new int[33];
            encoders     = new PackedInt32s.IEncoder[33];
            decoders     = new PackedInt32s.IDecoder[33];
            iterations   = new int[33];

            for (int bpv = 1; bpv <= 32; ++bpv)
            {
                PackedInt32s.FormatAndBits formatAndBits = PackedInt32s.FastestFormatAndBits(Lucene41PostingsFormat.BLOCK_SIZE, bpv, acceptableOverheadRatio);
                Debug.Assert(formatAndBits.Format.IsSupported(formatAndBits.BitsPerValue));
                Debug.Assert(formatAndBits.BitsPerValue <= 32);
                encodedSizes[bpv] = EncodedSize(formatAndBits.Format, PackedInt32s.VERSION_CURRENT, formatAndBits.BitsPerValue);
                encoders[bpv]     = PackedInt32s.GetEncoder(formatAndBits.Format, PackedInt32s.VERSION_CURRENT, formatAndBits.BitsPerValue);
                decoders[bpv]     = PackedInt32s.GetDecoder(formatAndBits.Format, PackedInt32s.VERSION_CURRENT, formatAndBits.BitsPerValue);
                iterations[bpv]   = ComputeIterations(decoders[bpv]);

                @out.WriteVInt32(formatAndBits.Format.Id << 5 | (formatAndBits.BitsPerValue - 1));
            }
        }
Exemplo n.º 6
0
        private static int LoadMaxDataSize() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
        {
            int maxDataSize = 0;

            for (int version = PackedInt32s.VERSION_START; version <= PackedInt32s.VERSION_CURRENT; version++)
            {
                foreach (PackedInt32s.Format format in PackedInt32s.Format.Values /* Enum.GetValues(typeof(PackedInts.Format))*/)
                {
                    for (int bpv = 1; bpv <= 32; ++bpv)
                    {
                        if (!format.IsSupported(bpv))
                        {
                            continue;
                        }
                        PackedInt32s.IDecoder decoder = PackedInt32s.GetDecoder(format, version, bpv);
                        int iterations = ComputeIterations(decoder);
                        maxDataSize = Math.Max(maxDataSize, iterations * decoder.ByteValueCount);
                    }
                }
            }
            return(maxDataSize);
        }
Exemplo n.º 7
0
        static ForUtil()
        {
            int maxDataSize = 0;

            for (int version = PackedInt32s.VERSION_START; version <= PackedInt32s.VERSION_CURRENT; version++)
            {
                foreach (PackedInt32s.Format format in PackedInt32s.Format.Values /* Enum.GetValues(typeof(PackedInts.Format))*/)
                {
                    for (int bpv = 1; bpv <= 32; ++bpv)
                    {
                        if (!format.IsSupported(bpv))
                        {
                            continue;
                        }
                        PackedInt32s.IDecoder decoder = PackedInt32s.GetDecoder(format, version, bpv);
                        int iterations = ComputeIterations(decoder);
                        maxDataSize = Math.Max(maxDataSize, iterations * decoder.ByteValueCount);
                    }
                }
            }
            MAX_DATA_SIZE = maxDataSize;
        }