public override object Clone() { SixItemList <T> sixItemList = new SixItemList <T>(); sixItemList.Promote(this); return(sixItemList); }
public override FrugalListStoreState Add(T value) { switch (this._count) { case 0: { this._entry0 = value; break; } case 1: { this._entry1 = value; break; } case 2: { this._entry2 = value; break; } case 3: { this._entry3 = value; break; } case 4: { this._entry4 = value; break; } case 5: { this._entry5 = value; break; } default: { return(FrugalListStoreState.Array); } } SixItemList <T> sixItemList = this; sixItemList._count = sixItemList._count + 1; return(FrugalListStoreState.Success); }
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 void Promote(SixItemList <T> oldList) { int count = oldList.Count; 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; } case 4: { this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); this.SetAt(2, oldList.EntryAt(2)); this.SetAt(3, oldList.EntryAt(3)); return; } case 5: { this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); this.SetAt(2, oldList.EntryAt(2)); this.SetAt(3, oldList.EntryAt(3)); this.SetAt(4, oldList.EntryAt(4)); return; } case 6: { this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); this.SetAt(2, oldList.EntryAt(2)); this.SetAt(3, oldList.EntryAt(3)); this.SetAt(4, oldList.EntryAt(4)); this.SetAt(5, oldList.EntryAt(5)); return; } } throw new ArgumentOutOfRangeException("oldList"); }
public override void Insert(int index, T value) { if (this._count >= 6) { throw new ArgumentOutOfRangeException("index"); } switch (index) { case 0: { this._entry5 = this._entry4; this._entry4 = this._entry3; this._entry3 = this._entry2; this._entry2 = this._entry1; this._entry1 = this._entry0; this._entry0 = value; break; } case 1: { this._entry5 = this._entry4; this._entry4 = this._entry3; this._entry3 = this._entry2; this._entry2 = this._entry1; this._entry1 = value; break; } case 2: { this._entry5 = this._entry4; this._entry4 = this._entry3; this._entry3 = this._entry2; this._entry2 = value; break; } case 3: { this._entry5 = this._entry4; this._entry4 = this._entry3; this._entry3 = value; break; } case 4: { this._entry5 = this._entry4; this._entry4 = value; break; } case 5: { this._entry5 = value; break; } default: { throw new ArgumentOutOfRangeException("index"); } } SixItemList <T> sixItemList = this; sixItemList._count = sixItemList._count + 1; }