protected void WriteValues(int bitsRequired)
        {
            PackedInt32s.IEncoder encoder = PackedInt32s.GetEncoder(PackedInt32s.Format.PACKED, PackedInt32s.VERSION_CURRENT, bitsRequired);
            int iterations = m_values.Length / encoder.ByteValueCount;
            int blockSize  = encoder.ByteBlockCount * iterations;

            if (m_blocks is null || m_blocks.Length < blockSize)
            {
                m_blocks = new byte[blockSize];
            }
            if (m_off < m_values.Length)
            {
                Arrays.Fill(m_values, m_off, m_values.Length, 0L);
            }
            encoder.Encode(m_values, 0, m_blocks, 0, iterations);
            int blockCount = (int)PackedInt32s.Format.PACKED.ByteCount(PackedInt32s.VERSION_CURRENT, m_off, bitsRequired);

            m_out.WriteBytes(m_blocks, blockCount);
        }
Beispiel #2
0
            internal virtual void PforEncode()
            {
                if (numExceptions > 0)
                {
                    int mask = (1 << bitsPerValue) - 1;
                    int ex   = 0;
                    for (int i = 0; i < bufferSize; ++i)
                    {
                        if (buffer[i] > mask)
                        {
                            exceptionIndices[ex] = i;
                            exceptions[ex++]     = (int)((uint)buffer[i] >> bitsPerValue);
                            buffer[i]           &= mask;
                        }
                    }
                    Debug.Assert(ex == numExceptions);
                    Arrays.Fill(exceptions, numExceptions, BLOCK_SIZE, 0);
                }

                if (bitsPerValue > 0)
                {
                    PackedInt32s.IEncoder encoder = PackedInt32s.GetEncoder(PackedInt32s.Format.PACKED, PackedInt32s.VERSION_CURRENT, bitsPerValue);
                    int numIterations             = ITERATIONS[bitsPerValue];
                    encoder.Encode(buffer, 0, data.Bytes, data.Length, numIterations);
                    data.Length += encoder.ByteBlockCount * numIterations;
                }

                if (numExceptions > 0)
                {
                    Debug.Assert(bitsPerException > 0);
                    data.WriteByte((byte)(sbyte)numExceptions);
                    data.WriteByte((byte)(sbyte)bitsPerException);
                    PackedInt32s.IEncoder encoder = PackedInt32s.GetEncoder(PackedInt32s.Format.PACKED, PackedInt32s.VERSION_CURRENT, bitsPerException);
                    int numIterations             = (numExceptions + encoder.ByteValueCount - 1) / encoder.ByteValueCount;
                    encoder.Encode(exceptions, 0, data.Bytes, data.Length, numIterations);
                    data.Length += (int)PackedInt32s.Format.PACKED.ByteCount(PackedInt32s.VERSION_CURRENT, numExceptions, bitsPerException);
                    for (int i = 0; i < numExceptions; ++i)
                    {
                        data.WriteByte((byte)(sbyte)exceptionIndices[i]);
                    }
                }
            }
Beispiel #3
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));
            }
        }
Beispiel #4
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);
                Debug.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]);
            }
        }