public override void Promote(FrugalListBase <T> oldList) { if (1 != oldList.Count) { throw new ArgumentException("oldList"); } this.SetCount(1); this.SetAt(0, oldList.EntryAt(0)); }
public override void Promote(FrugalListBase <T> oldList) { for (int i = 0; i < oldList.Count; i++) { if (this.Add(oldList.EntryAt(i)) != FrugalListStoreState.Success) { throw new ArgumentException("list is smaller than oldList", "oldList"); } } }
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); }
public override void Promote(FrugalListBase <T> oldList) { int count = oldList.Count; if (3 < count) { throw new ArgumentException("oldList"); } this.SetCount(oldList.Count); switch (count) { case 0: { return; } case 1: { this.SetAt(0, oldList.EntryAt(0)); return; } case 2: { this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); return; } case 3: { this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); this.SetAt(2, oldList.EntryAt(2)); return; } } throw new ArgumentOutOfRangeException("index"); }
public FrugalStructList(int size) { this._listStore = null; this.Capacity = size; }
public abstract void Promote(FrugalListBase <T> newList);