public virtual GrowableWriter Resize(int newSize) { GrowableWriter next = new GrowableWriter(BitsPerValue, newSize, AcceptableOverheadRatio); int limit = Math.Min(Size(), newSize); PackedInts.Copy(Current, 0, next, 0, limit, PackedInts.DEFAULT_BUFFER_SIZE); return(next); }
private void EnsureCapacity(long value) { if ((value & CurrentMask) == value) { return; } int bitsRequired = value < 0 ? 64 : PackedInts.BitsRequired(value); Debug.Assert(bitsRequired > Current.BitsPerValue); int valueCount = Size(); PackedInts.Mutable next = PackedInts.GetMutable(valueCount, bitsRequired, AcceptableOverheadRatio); PackedInts.Copy(Current, 0, next, 0, valueCount, PackedInts.DEFAULT_BUFFER_SIZE); Current = next; CurrentMask = Mask(Current.BitsPerValue); }
/// <summary> /// Create a new copy of size <code>newSize</code> 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].Size()); PackedInts.Copy(SubMutables[i], 0, copy.SubMutables[i], 0, copyLength, copyBuffer); } } return(copy); }