public /*synchronized*/ IntArraySliceObj Concat(int idx, NeIntSeqObj seq) { int seqLen = seq.GetSize(); int newLen = idx + seqLen; if (newLen > buffer.Length) { // We run out of space, expanding the array buffer int size = MinBufferSize(newLen); long[] newBuffer = new long[size]; for (int i = 0; i < idx; i++) { newBuffer[i] = buffer[i]; } seq.Copy(0, seqLen, newBuffer, idx); PaddedIntArray newArray = new PaddedIntArray(newBuffer, newLen); return(newArray.Slice(0, newLen)); //## THINK ABOUT THIS. WOULD IT WORK? // buffer = newBuffer; // used = newLen; // return new IntArraySliceObj(this, buffer, 0, used); } else if (idx == used) { // There's space for the new elements seq.Copy(0, seqLen, buffer, idx); used = newLen; return(new IntArraySliceObj(this, buffer, 0, used)); } else { // The next slot was already taken. This is supposed to happen only rarely Debug.Assert(idx < used & idx < buffer.Length); long[] newBuffer = new long[buffer.Length]; for (int i = 0; i < idx; i++) { newBuffer[i] = buffer[i]; } seq.Copy(0, seqLen, newBuffer, idx); PaddedIntArray newArray = new PaddedIntArray(newBuffer, newLen); return(newArray.Slice(0, newLen)); } }
public static IntArraySliceObj Create(NeIntSeqObj seq, long value) { int len = seq.GetSize(); int size = MinBufferSize(len + 1); long[] buffer = new long[size]; seq.Copy(0, len, buffer, 0); buffer[len] = value; PaddedIntArray paddedArray = new PaddedIntArray(buffer, len + 1); return(paddedArray.Slice(0, len + 1)); }
public static IntArraySliceObj Create(NeIntSeqObj left, NeIntSeqObj right) { int leftLen = left.GetSize(); int rightLen = right.GetSize(); int len = leftLen + rightLen; int size = MinBufferSize(len); long[] buffer = new long[size]; left.Copy(0, leftLen, buffer, 0); right.Copy(0, rightLen, buffer, leftLen); PaddedIntArray paddedArray = new PaddedIntArray(buffer, len); return(paddedArray.Slice(0, len)); }