Пример #1
0
        public override int Set(int index, long[] arr, int off, int len)
        {
            Debug.Assert(len > 0, "len must be > 0 (got " + len + ")");
            Debug.Assert(index >= 0 && index < m_valueCount);
            len = Math.Min(len, m_valueCount - index);
            Debug.Assert(off + len <= arr.Length);

            int originalIndex = index;

            // go to the next block boundary
            int valuesPerBlock = 64 / m_bitsPerValue;
            int offsetInBlock  = index % valuesPerBlock;

            if (offsetInBlock != 0)
            {
                for (int i = offsetInBlock; i < valuesPerBlock && len > 0; ++i)
                {
                    Set(index++, arr[off++]);
                    --len;
                }
                if (len == 0)
                {
                    return(index - originalIndex);
                }
            }

            // bulk set
            Debug.Assert(index % valuesPerBlock == 0);
            BulkOperation op = BulkOperation.Of(PackedInt32s.Format.PACKED_SINGLE_BLOCK, m_bitsPerValue);

            Debug.Assert(op.Int64BlockCount == 1);
            Debug.Assert(op.Int64ValueCount == valuesPerBlock);
            int blockIndex = index / valuesPerBlock;
            int nblocks    = (index + len) / valuesPerBlock - blockIndex;

            op.Encode(arr, off, blocks, blockIndex, nblocks);
            int diff = nblocks * valuesPerBlock;

            index += diff;
            len   -= diff;

            if (index > originalIndex)
            {
                // stay at the block boundary
                return(index - originalIndex);
            }
            else
            {
                // no progress so far => already at a block boundary but no full block to
                // set
                Debug.Assert(index == originalIndex);
                return(base.Set(index, arr, off, len));
            }
        }
Пример #2
0
 internal PackedWriter(PackedInt32s.Format format, DataOutput @out, int valueCount, int bitsPerValue, int mem)
     : base(@out, valueCount, bitsPerValue)
 {
     this.format = 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;
 }
Пример #3
0
        public override int Set(int index, long[] arr, int off, int len)
        {
            Debug.Assert(len > 0, "len must be > 0 (got " + len + ")");
            Debug.Assert(index >= 0 && index < m_valueCount);
            len = Math.Min(len, m_valueCount - index);
            Debug.Assert(off + len <= arr.Length);

            int originalIndex = index;

            PackedInt32s.IEncoder encoder = BulkOperation.Of(PackedInt32s.Format.PACKED, m_bitsPerValue);

            // go to the next block where the value does not span across two blocks
            int offsetInBlocks = index % encoder.Int64ValueCount;

            if (offsetInBlocks != 0)
            {
                for (int i = offsetInBlocks; i < encoder.Int64ValueCount && len > 0; ++i)
                {
                    Set(index++, arr[off++]);
                    --len;
                }
                if (len == 0)
                {
                    return(index - originalIndex);
                }
            }

            // bulk set
            Debug.Assert(index % encoder.Int64ValueCount == 0);
            int blockIndex = (int)((ulong)((long)index * m_bitsPerValue) >> BLOCK_BITS);

            Debug.Assert((((long)index * m_bitsPerValue) & MOD_MASK) == 0);
            int iterations = len / encoder.Int64ValueCount;

            encoder.Encode(arr, off, blocks, blockIndex, iterations);
            int setValues = iterations * encoder.Int64ValueCount;

            index += setValues;
            len   -= setValues;
            Debug.Assert(len >= 0);

            if (index > originalIndex)
            {
                // stay at the block boundary
                return(index - originalIndex);
            }
            else
            {
                // no progress so far => already at a block boundary but no full block to get
                Debug.Assert(index == originalIndex);
                return(base.Set(index, arr, off, len));
            }
        }
Пример #4
0
 internal PackedReaderIterator(PackedInt32s.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             = Iterations(mem);
     Debug.Assert(valueCount == 0 || iterations > 0);
     nextBlocks        = new byte[iterations * bulkOperation.ByteBlockCount];
     nextValues        = new Int64sRef(new long[iterations * bulkOperation.ByteValueCount], 0, 0);
     nextValues.Offset = nextValues.Int64s.Length;
     position          = -1;
 }
Пример #5
0
        public override int Get(int index, long[] arr, int off, int len)
        {
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(len > 0, "len must be > 0 (got {0})", len);
            }
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(index >= 0 && index < m_valueCount);
            }
            len = Math.Min(len, m_valueCount - index);
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(off + len <= arr.Length);
            }

            int originalIndex = index;

            PackedInt32s.IDecoder decoder = BulkOperation.Of(PackedInt32s.Format.PACKED, m_bitsPerValue);

            // go to the next block where the value does not span across two blocks
            int offsetInBlocks = index % decoder.Int64ValueCount;

            if (offsetInBlocks != 0)
            {
                for (int i = offsetInBlocks; i < decoder.Int64ValueCount && len > 0; ++i)
                {
                    arr[off++] = Get(index++);
                    --len;
                }
                if (len == 0)
                {
                    return(index - originalIndex);
                }
            }

            // bulk get
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(index % decoder.Int64ValueCount == 0);
            }
            int blockIndex = (int)(((long)index * m_bitsPerValue).TripleShift(BLOCK_BITS));

            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert((((long)index * m_bitsPerValue) & MOD_MASK) == 0);
            }
            int iterations = len / decoder.Int64ValueCount;

            decoder.Decode(blocks, blockIndex, arr, off, iterations);
            int gotValues = iterations * decoder.Int64ValueCount;

            index += gotValues;
            len   -= gotValues;
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(len >= 0);
            }

            if (index > originalIndex)
            {
                // stay at the block boundary
                return(index - originalIndex);
            }
            else
            {
                // no progress so far => already at a block boundary but no full block to get
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(index == originalIndex);
                }
                return(base.Get(index, arr, off, len));
            }
        }