Esempio n. 1
0
        public /*synchronized*/ ArraySliceObj Concat(int idx, NeSeqObj 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);
                Obj[] newBuffer = new Obj[size];
                for (int i = 0; i < idx; i++)
                {
                    newBuffer[i] = buffer[i];
                }
                seq.Copy(0, seqLen, newBuffer, idx);
                PaddedArray newArray = new PaddedArray(newBuffer, newLen);
                return(newArray.Slice(0, newLen));
                //## THINK ABOUT THIS. WOULD IT WORK?
                // buffer = newBuffer;
                // used = newLen;
                // return new ArraySliceObj(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 ArraySliceObj(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);

                Obj[] newBuffer = new Obj[buffer.Length];
                for (int i = 0; i < idx; i++)
                {
                    newBuffer[i] = buffer[i];
                }
                seq.Copy(0, seqLen, newBuffer, idx);
                PaddedArray newArray = new PaddedArray(newBuffer, newLen);
                return(newArray.Slice(0, newLen));
            }
        }
Esempio n. 2
0
        public static ArraySliceObj Create(NeSeqObj seq, Obj obj)
        {
            int len  = seq.GetSize();
            int size = MinBufferSize(len + 1);

            Obj[] buffer = new Obj[size];
            seq.Copy(0, len, buffer, 0);
            buffer[len] = obj;
            PaddedArray paddedArray = new PaddedArray(buffer, len + 1);

            return(paddedArray.Slice(0, len + 1));
        }
Esempio n. 3
0
        public static ArraySliceObj Create(NeSeqObj left, NeSeqObj right)
        {
            int leftLen  = left.GetSize();
            int rightLen = right.GetSize();
            int len      = leftLen + rightLen;
            int size     = MinBufferSize(len);

            Obj[] buffer = new Obj[size];
            left.Copy(0, leftLen, buffer, 0);
            right.Copy(0, rightLen, buffer, leftLen);
            PaddedArray paddedArray = new PaddedArray(buffer, len);

            return(paddedArray.Slice(0, len));
        }