Пример #1
0
        //////////////////////////////////////////////////////////////////////////////

        public static ArraySliceObj Create(Obj obj)
        {
            Obj[] buffer = new Obj[32];
            buffer[0] = obj;
            PaddedArray paddedArray = new PaddedArray(buffer, 1);

            return(paddedArray.Slice(0, 1));
        }
Пример #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));
        }
Пример #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));
        }
Пример #4
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));
            }
        }
Пример #5
0
        public /*synchronized*/ ArraySliceObj Append(int idx, Obj obj)
        {
            if (idx == buffer.Length)
            {
                // We run out of space, expanding the array buffer
                int   size      = buffer.Length;
                int   newSize   = 2 * size;
                Obj[] newBuffer = new Obj[newSize];
                for (int i = 0; i < size; i++)
                {
                    newBuffer[i] = buffer[i];
                }
                newBuffer[idx] = obj;
                PaddedArray newArray = new PaddedArray(newBuffer, idx + 1);
                return(newArray.Slice(0, idx + 1));

                //## THINK ABOUT THIS. WOULD IT WORK?
                // buffer = newBuffer;
                // used++;
                // return new ArraySliceObj(this, buffer, 0, used);
            }
            else if (idx == used)
            {
                // There's space for the new element
                buffer[idx] = obj;
                used++;
                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];
                }
                newBuffer[idx] = obj;
                PaddedArray newArray = new PaddedArray(newBuffer, idx + 1);
                return(newArray.Slice(0, idx + 1));
            }
        }