示例#1
0
        public override object Clone()
        {
            ArrayItemList <T> arrayItemList = new ArrayItemList <T>(this.Capacity);

            arrayItemList.Promote(this);
            return(arrayItemList);
        }
示例#2
0
 public override FrugalListStoreState Add(T value)
 {
     if (this._entries == null || this._count >= (int)this._entries.Length)
     {
         if (this._entries == null)
         {
             this._entries = new T[9];
         }
         else
         {
             int length = (int)this._entries.Length;
             length = (length >= 18 ? length + (length >> 2) : length + 3);
             T[] tArray = new T[length];
             Array.Copy(this._entries, 0, tArray, 0, (int)this._entries.Length);
             this._entries = tArray;
         }
         this._entries[this._count] = value;
         ArrayItemList <T> arrayItemList = this;
         arrayItemList._count = arrayItemList._count + 1;
     }
     else
     {
         this._entries[this._count] = value;
         ArrayItemList <T> arrayItemList1 = this;
         arrayItemList1._count = arrayItemList1._count + 1;
     }
     return(FrugalListStoreState.Success);
 }
示例#3
0
        public override void Insert(int index, T value)
        {
            if (this._entries == null || this._count >= (int)this._entries.Length)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            Array.Copy(this._entries, index, this._entries, index + 1, this._count - index);
            this._entries[index] = value;
            ArrayItemList <T> arrayItemList = this;

            arrayItemList._count = arrayItemList._count + 1;
        }
示例#4
0
        public override void RemoveAt(int index)
        {
            int num = this._count - index - 1;

            if (num > 0)
            {
                Array.Copy(this._entries, index + 1, this._entries, index, num);
            }
            this._entries[this._count - 1] = default(T);
            ArrayItemList <T> arrayItemList = this;

            arrayItemList._count = arrayItemList._count - 1;
        }
示例#5
0
        public void Promote(ArrayItemList <T> oldList)
        {
            int count = oldList.Count;

            if ((int)this._entries.Length < count)
            {
                throw new ArgumentException("list is smaller than oldList", "oldList");
            }
            this.SetCount(oldList.Count);
            for (int i = 0; i < count; i++)
            {
                this.SetAt(i, oldList.EntryAt(i));
            }
        }
示例#6
0
        public int Add(T value)
        {
            if (this._listStore == null)
            {
                this._listStore = new SingleItemList <T>();
            }
            FrugalListStoreState frugalListStoreState = this._listStore.Add(value);

            if (frugalListStoreState != FrugalListStoreState.Success)
            {
                if (FrugalListStoreState.ThreeItemList == frugalListStoreState)
                {
                    ThreeItemList <T> threeItemList = new ThreeItemList <T>();
                    threeItemList.Promote(this._listStore);
                    threeItemList.Add(value);
                    this._listStore = threeItemList;
                }
                else if (FrugalListStoreState.SixItemList != frugalListStoreState)
                {
                    if (FrugalListStoreState.Array != frugalListStoreState)
                    {
                        throw new InvalidOperationException();
                    }
                    ArrayItemList <T> arrayItemList = new ArrayItemList <T>(this._listStore.Count + 1);
                    arrayItemList.Promote(this._listStore);
                    this._listStore = arrayItemList;
                    arrayItemList.Add(value);
                    this._listStore = arrayItemList;
                }
                else
                {
                    SixItemList <T> sixItemList = new SixItemList <T>();
                    sixItemList.Promote(this._listStore);
                    this._listStore = sixItemList;
                    sixItemList.Add(value);
                    this._listStore = sixItemList;
                }
            }
            return(this._listStore.Count - 1);
        }