コード例 #1
0
ファイル: GrowableWriter.cs プロジェクト: voquanghoa/YAFNET
        public virtual GrowableWriter Resize(int newSize)
        {
            GrowableWriter next  = new GrowableWriter(BitsPerValue, newSize, acceptableOverheadRatio);
            int            limit = Math.Min(Count, newSize);

            PackedInt32s.Copy(current, 0, next, 0, limit, PackedInt32s.DEFAULT_BUFFER_SIZE);
            return(next);
        }
コード例 #2
0
ファイル: GrowableWriter.cs プロジェクト: voquanghoa/YAFNET
        private void EnsureCapacity(long value)
        {
            if ((value & currentMask) == value)
            {
                return;
            }
            int bitsRequired = value < 0 ? 64 : PackedInt32s.BitsRequired(value);

            Debug.Assert(bitsRequired > current.BitsPerValue);
            int valueCount = Count;

            PackedInt32s.Mutable next = PackedInt32s.GetMutable(valueCount, bitsRequired, acceptableOverheadRatio);
            PackedInt32s.Copy(current, 0, next, 0, valueCount, PackedInt32s.DEFAULT_BUFFER_SIZE);
            current     = next;
            currentMask = Mask(current.BitsPerValue);
        }
コード例 #3
0
 /// <summary>
 /// Create a new copy of size <paramref name="newSize"/> based on the content of
 /// this buffer. This method is much more efficient than creating a new
 /// instance and copying values one by one.
 /// </summary>
 public T Resize(long newSize)
 {
     T copy = NewUnfilledCopy(newSize);
     int numCommonPages = Math.Min(copy.subMutables.Length, subMutables.Length);
     long[] copyBuffer = new long[1024];
     for (int i = 0; i < copy.subMutables.Length; ++i)
     {
         int valueCount = i == copy.subMutables.Length - 1 ? LastPageSize(newSize) : PageSize;
         int bpv = i < numCommonPages ? subMutables[i].BitsPerValue : this.bitsPerValue;
         copy.subMutables[i] = NewMutable(valueCount, bpv);
         if (i < numCommonPages)
         {
             int copyLength = Math.Min(valueCount, subMutables[i].Count);
             PackedInt32s.Copy(subMutables[i], 0, copy.subMutables[i], 0, copyLength, copyBuffer);
         }
     }
     return copy;
 }