Exemple #1
0
        public byte[] Backward([Optional, DefaultParameterValue(default(ByteWormStatus))] ref ByteWormStatus status)
        {
            byte[] BackwardRet = default;
            if (Off)
            {
                return(null);
            }
            mIdx -= 1;
            if (mIdx < 0)
            {
                mIdx    = 0;
                mStatus = ByteWormStatus.NoLess;
                if (status != default(int))
                {
                    status = mStatus;
                }
                return(null);
            }

            BackwardRet = this[mIdx];
            if (mSize == 1)
            {
                mStatus = ByteWormStatus.JustOne;
            }
            else
            {
                mStatus = ByteWormStatus.Less;
                if (status != default(int))
                {
                    status = mStatus;
                }
            }

            return(BackwardRet);
        }
Exemple #2
0
        /* TODO ERROR: Skipped EndRegionDirectiveTrivia */
        /* TODO ERROR: Skipped RegionDirectiveTrivia */
        public int Add(byte[] value)
        {
            if (Off)
            {
                return(-1);
            }
            // ' We don't want empty objects. This is a worm!  It needs pieces! LOL.
            if (value is null)
            {
                return(-1);
            }
            int l = value.Length;

            OffToggle();
            Array.Resize(ref mPos, mSize + 1);
            Array.Resize(ref mSizes, mSize + 1);
            mPos[mSize]   = (int)mHeap.Length;
            mSizes[mSize] = l;
            mIdx          = mSize;
            mHeap        += value;
            mSize        += 1;
            mStatus       = ByteWormStatus.NoMore;
            OffToggle();
            return(mIdx);
        }
Exemple #3
0
        public byte[] Forward([Optional, DefaultParameterValue(default(ByteWormStatus))] ref ByteWormStatus status)
        {
            byte[] ForwardRet = default;
            if (Off)
            {
                return(null);
            }
            mIdx += 1;
            if (mIdx >= mSize)
            {
                mIdx    = mSize - 1;
                mStatus = ByteWormStatus.NoMore;
                if (status != default(int))
                {
                    status = mStatus;
                }
                return(null);
            }

            ForwardRet = this[mIdx];
            if (mSize == 1)
            {
                mStatus = ByteWormStatus.JustOne;
            }
            else
            {
                mStatus = ByteWormStatus.More;
                if (status != default(int))
                {
                    status = mStatus;
                }
            }

            return(ForwardRet);
        }
Exemple #4
0
        /* TODO ERROR: Skipped EndRegionDirectiveTrivia */
        /* TODO ERROR: Skipped RegionDirectiveTrivia */
        public byte[] this[int index]
        {
            get
            {
                if (Off)
                {
                    return(null);
                }
                else
                {
                    OffToggle();
                }
                if (index < 0 || index >= mSize)
                {
                    mStatus = ByteWormStatus.OutOfBounds;
                    OffToggle();
                    return(null);
                }

                byte[] b;
                b = mHeap.GrabBytes((IntPtr)mPos[index], mSizes[index]);
                OffToggle();
                return(b);
            }
        }
Exemple #5
0
        /* TODO ERROR: Skipped EndRegionDirectiveTrivia */
        /* TODO ERROR: Skipped RegionDirectiveTrivia */
        public byte[] ToIndex(int index, [Optional, DefaultParameterValue(default(ByteWormStatus))] ref ByteWormStatus status)
        {
            if (Off)
            {
                return(null);
            }
            if (index == mIdx)
            {
                if (status != default(int))
                {
                    status = mStatus;
                }
                return(this[mIdx]);
            }

            if (index >= mSize - 1)
            {
                index   = mSize;
                mStatus = ByteWormStatus.OutOfBounds;
                if (status != default(int))
                {
                    status = mStatus;
                }
                return(null);
            }
            else if (index < 0)
            {
                index   = -1;
                mStatus = ByteWormStatus.OutOfBounds;
                if (status != default(int))
                {
                    status = mStatus;
                }
                return(null);
            }

            if (mSize == 1)
            {
                mStatus = ByteWormStatus.JustOne;
            }
            else if (mIdx < index)
            {
                mStatus = ByteWormStatus.Less;
            }
            else
            {
                mStatus = ByteWormStatus.More;
            }

            mIdx = index;
            if (status != default(int))
            {
                status = mStatus;
            }
            return(this[index]);
        }
Exemple #6
0
        public int Truncate(int idx = -1)
        {
            if (Off)
            {
                return(-1);
            }
            int x;

            if (idx == -1)
            {
                idx = mIdx;
            }

            if (idx > mSize - 1)
            {
                mStatus = ByteWormStatus.OutOfBounds;
                return(-1);
            }
            else if (idx == mSize - 1)
            {
                return(idx);
            }

            OffToggle();
            Array.Resize(ref mSizes, idx + 1);
            Array.Resize(ref mPos, idx + 1);
            x            = mSizes[idx] + mPos[idx];
            mHeap.Length = x;
            mSize        = idx + 1;
            mIdx         = idx;
            if (mSize == 1)
            {
                mStatus = ByteWormStatus.JustOne;
            }
            else
            {
                mStatus = ByteWormStatus.NoMore;
            }

            OffToggle();
            return(idx);
        }
Exemple #7
0
 public void Clear()
 {
     if (Off)
     {
         return;
     }
     else
     {
         OffToggle();
     }
     mHeap.Clear();
     mPos    = null;
     mSizes  = null;
     mSize   = 0;
     mIdx    = -1;
     mStatus = ByteWormStatus.None;
     if (Off)
     {
         OffToggle();
     }
 }
Exemple #8
0
        internal void Partition(int[] sizes, ByteWormStatus status)
        {
            if (sizes is null)
            {
                return;
            }
            if (Off)
            {
                return;
            }
            else
            {
                OffToggle();
            }
            int i = 0;
            int c = sizes.Length - 1;
            int d = 0;
            int e = 0;

            mPos   = new int[c + 1];
            mSizes = new int[c + 1];
            mSize  = 0;
            mIdx   = -1;
            var loopTo = c;

            for (i = 0; i <= loopTo; i++)
            {
                mPos[i]   = e;
                mSizes[i] = sizes[i];
                e        += sizes[i];
            }

            mSize   = c + 1;
            mIdx    = c;
            mStatus = status;
            OffToggle();
        }