public /*synchronized*/ FloatArraySliceObj Concat(int idx, NeFloatSeqObj 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); double[] newBuffer = new double[size]; for (int i = 0; i < idx; i++) { newBuffer[i] = buffer[i]; } seq.Copy(0, seqLen, newBuffer, idx); PaddedFloatArray newArray = new PaddedFloatArray(newBuffer, newLen); return(newArray.Slice(0, newLen)); //## THINK ABOUT THIS. WOULD IT WORK? // buffer = newBuffer; // used = newLen; // return new FloatArraySliceObj(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 FloatArraySliceObj(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); double[] newBuffer = new double[buffer.Length]; for (int i = 0; i < idx; i++) { newBuffer[i] = buffer[i]; } seq.Copy(0, seqLen, newBuffer, idx); PaddedFloatArray newArray = new PaddedFloatArray(newBuffer, newLen); return(newArray.Slice(0, newLen)); } }
public static FloatArraySliceObj Create(NeFloatSeqObj seq, double value) { int len = seq.GetSize(); int size = MinBufferSize(len + 1); double[] buffer = new double[size]; seq.Copy(0, len, buffer, 0); buffer[len] = value; PaddedFloatArray paddedArray = new PaddedFloatArray(buffer, len + 1); return(paddedArray.Slice(0, len + 1)); }
public static FloatArraySliceObj Create(NeFloatSeqObj left, NeFloatSeqObj right) { int leftLen = left.GetSize(); int rightLen = right.GetSize(); int len = leftLen + rightLen; int size = MinBufferSize(len); double[] buffer = new double[size]; left.Copy(0, leftLen, buffer, 0); right.Copy(0, rightLen, buffer, leftLen); PaddedFloatArray paddedArray = new PaddedFloatArray(buffer, len); return(paddedArray.Slice(0, len)); }