예제 #1
0
        private void Flush()
        {
            encoder.Encode(nextValues, 0, nextBlocks, 0, iterations);
            int blockCount = (int)format.ByteCount(PackedInt32s.VERSION_CURRENT, off, m_bitsPerValue);

            m_out.WriteBytes(nextBlocks, blockCount);
            Arrays.Fill(nextValues, 0L);
            off = 0;
        }
예제 #2
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));
            }
        }