- Timestamp:
- 05/02/17 22:03:01 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/FeatureTests/DirtyList/PushStack3.cs
r14777 r14908 22 22 23 23 public PushStack3() { 24 this.data = new LinkedList<T>();25 this.IsEnabled = true;24 data = new LinkedList<T>(); 25 IsEnabled = true; 26 26 } 27 27 … … 32 32 get 33 33 { 34 return this.data.Last.Value;34 return data.Last.Value; 35 35 } 36 36 } … … 40 40 get 41 41 { 42 return this.Count > 0 ? Top : default(T);42 return Count > 0 ? Top : default(T); 43 43 } 44 44 } … … 48 48 get 49 49 { 50 return this.data.First.Value;50 return data.First.Value; 51 51 } 52 52 } … … 56 56 get 57 57 { 58 return this.Count > 0 ? Bottom : default(T);58 return Count > 0 ? Bottom : default(T); 59 59 } 60 60 } … … 64 64 get 65 65 { 66 return this.data.Count;66 return data.Count; 67 67 } 68 68 } … … 72 72 get 73 73 { 74 return this.Count == 0;74 return Count == 0; 75 75 } 76 76 } … … 85 85 86 86 public void Add(T item) { 87 this.Push(item);87 Push(item); 88 88 } 89 89 90 90 public void Clear() { 91 this.data.Clear();91 data.Clear(); 92 92 } 93 93 94 94 public bool Contains(T item) { 95 return this.data.Contains(item);95 return data.Contains(item); 96 96 } 97 97 98 98 public void CopyTo(T[] array, int arrayIndex) { 99 this.data.CopyTo(array, arrayIndex);99 data.CopyTo(array, arrayIndex); 100 100 } 101 101 102 102 public IEnumerator<T> GetEnumerator() { 103 return this.data.GetEnumerator();103 return data.GetEnumerator(); 104 104 } 105 105 106 106 public T ElementAt(int index) { 107 return this.data.ElementAt(index);107 return data.ElementAt(index); 108 108 } 109 109 … … 113 113 114 114 public void SetTop(T value) { 115 this.data.Last.Value = value;115 data.Last.Value = value; 116 116 } 117 117 … … 138 138 139 139 public void Swap(int count) { 140 var topValue = this.Top;141 var current = this.data.Last;142 var bottomIndex = this.Count - count;143 144 145 for (var i = this.Count - 1; i > bottomIndex; i--) {140 var topValue = Top; 141 var current = data.Last; 142 var bottomIndex = Count - count; 143 144 145 for (var i = Count - 1; i > bottomIndex; i--) { 146 146 current.Value = current.Previous.Value; 147 147 current = current.Previous; 148 148 } 149 149 150 this.data.Last.Value = topValue;150 data.Last.Value = topValue; 151 151 } 152 152 153 153 public void Yank(int index) { 154 if (index == this.Count - 1) return;155 156 var item = this.GetByIndex(index);157 this.data.Remove(item);158 this.data.AddLast(item);154 if (index == Count - 1) return; 155 156 var item = GetByIndex(index); 157 data.Remove(item); 158 data.AddLast(item); 159 159 } 160 160 161 161 public T Pop() { 162 162 var value = Top; 163 this.data.RemoveLast();163 data.RemoveLast(); 164 164 165 165 return value; … … 178 178 179 179 public T Peek() { 180 return this.Top;180 return Top; 181 181 } 182 182 183 183 public T[] Peek(int count) { 184 184 var items = new T[count]; 185 var current = this.data.Last;185 var current = data.Last; 186 186 187 187 for (var i = 0; i < count; i++) { … … 194 194 195 195 public void Push(T item) { 196 if (! this.IsEnabled) return;197 198 this.data.AddLast(item);196 if (!IsEnabled) return; 197 198 data.AddLast(item); 199 199 } 200 200 201 201 public void Push(T item1, T item2) { 202 if (! this.IsEnabled) return;203 204 this.data.AddLast(item1);205 this.data.AddLast(item2);202 if (!IsEnabled) return; 203 204 data.AddLast(item1); 205 data.AddLast(item2); 206 206 } 207 207 208 208 public void Push(T item1, T item2, T item3) { 209 if (! this.IsEnabled) return;210 211 this.data.AddLast(item1);212 this.data.AddLast(item2);213 this.data.AddLast(item3);209 if (!IsEnabled) return; 210 211 data.AddLast(item1); 212 data.AddLast(item2); 213 data.AddLast(item3); 214 214 } 215 215 216 216 public void Push(T item1, T item2, T item3, T item4) { 217 if (! this.IsEnabled) return;218 219 this.data.AddLast(item1);220 this.data.AddLast(item2);221 this.data.AddLast(item3);222 this.data.AddLast(item4);217 if (!IsEnabled) return; 218 219 data.AddLast(item1); 220 data.AddLast(item2); 221 data.AddLast(item3); 222 data.AddLast(item4); 223 223 } 224 224 225 225 public void PushResult(int count, Func<T[], T> templateFunc) { 226 if (! this.IsEnabled) return;226 if (!IsEnabled) return; 227 227 228 228 Push(templateFunc(Pop(count))); … … 230 230 231 231 public void PushRange(IReadOnlyList<T> items) { 232 if (! this.IsEnabled) return;233 234 for (var i = 0; i < items.Count; i++) this.data.AddLast(items[i]);232 if (!IsEnabled) return; 233 234 for (var i = 0; i < items.Count; i++) data.AddLast(items[i]); 235 235 } 236 236 237 237 public void Insert(int index, T value) { 238 if (! this.IsEnabled) return;238 if (!IsEnabled) return; 239 239 240 240 var node = GetByIndex(index); 241 this.data.AddBefore(node, value);241 data.AddBefore(node, value); 242 242 } 243 243 244 244 public bool Remove(T item) { 245 return this.data.Remove(item);245 return data.Remove(item); 246 246 } 247 247 248 248 public void RemoveTop() { 249 this.data.RemoveLast();249 data.RemoveLast(); 250 250 } 251 251 252 252 public void Remove(int count) { 253 for (var i = 0; i < count; i++) this.data.RemoveLast();253 for (var i = 0; i < count; i++) data.RemoveLast(); 254 254 } 255 255 … … 257 257 var node = GetByIndex(index); 258 258 259 this.data.Remove(node);259 data.Remove(node); 260 260 } 261 261 … … 271 271 272 272 public bool TryPop(out T item) { 273 if ( this.Count > 0) {274 item = this.Pop();273 if (Count > 0) { 274 item = Pop(); 275 275 return true; 276 276 }
Note: See TracChangeset
for help on using the changeset viewer.