- Timestamp:
- 05/02/17 22:03:01 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/FeatureTests/DirtyList/PushStack.cs
r14777 r14908 22 22 23 23 public PushStack(int capacity = 0) { 24 this.data = new List<T>(capacity);25 this.IsEnabled = true;24 data = new List<T>(capacity); 25 IsEnabled = true; 26 26 } 27 27 … … 32 32 get 33 33 { 34 return this.data.Capacity;34 return data.Capacity; 35 35 } 36 36 } … … 40 40 get 41 41 { 42 return this.data[this.Count - 1];42 return data[Count - 1]; 43 43 } 44 44 } … … 48 48 get 49 49 { 50 return this.Count > 0 ? this.data[this.Count - 1] : default(T);50 return Count > 0 ? data[Count - 1] : default(T); 51 51 } 52 52 } … … 56 56 get 57 57 { 58 return this.data[0];58 return data[0]; 59 59 } 60 60 } … … 64 64 get 65 65 { 66 return this.Count > 0 ? this.data[0] : default(T);66 return Count > 0 ? data[0] : default(T); 67 67 } 68 68 } … … 72 72 get 73 73 { 74 return this.data.Count;74 return data.Count; 75 75 } 76 76 } … … 80 80 get 81 81 { 82 return this.Count == 0;82 return Count == 0; 83 83 } 84 84 } … … 93 93 94 94 public void Add(T item) { 95 this.Push(item);95 Push(item); 96 96 } 97 97 98 98 public void Clear() { 99 this.data.Clear();99 data.Clear(); 100 100 } 101 101 102 102 public bool Contains(T item) { 103 return this.data.Contains(item);103 return data.Contains(item); 104 104 } 105 105 106 106 public void CopyTo(T[] array, int arrayIndex) { 107 this.data.CopyTo(array, arrayIndex);107 data.CopyTo(array, arrayIndex); 108 108 } 109 109 110 110 public IEnumerator<T> GetEnumerator() { 111 return this.data.GetEnumerator();111 return data.GetEnumerator(); 112 112 } 113 113 114 114 public T ElementAt(int index) { 115 return this.data[index];115 return data[index]; 116 116 } 117 117 118 118 public T ReverseElementAt(int offset) { 119 return this.data[this.data.Count - 1 - offset];119 return data[data.Count - 1 - offset]; 120 120 } 121 121 122 122 public void SetTop(T value) { 123 this.data[this.Count - 1] = value;123 data[Count - 1] = value; 124 124 } 125 125 … … 128 128 get 129 129 { 130 return this.data[key];130 return data[key]; 131 131 } 132 132 set 133 133 { 134 this.data[key] = value;134 data[key] = value; 135 135 } 136 136 } 137 137 138 138 public void Swap(int count) { 139 var top = this.Top;140 var bottomIndex = this.Count - count;141 142 for (var i = this.Count - 1; i > bottomIndex; i--) this.data[i] = this.data[i - 1];143 144 this.data[bottomIndex] = top;139 var top = Top; 140 var bottomIndex = Count - count; 141 142 for (var i = Count - 1; i > bottomIndex; i--) data[i] = data[i - 1]; 143 144 data[bottomIndex] = top; 145 145 } 146 146 147 147 public void Yank(int index) { 148 if (index == this.Count - 1) return;149 150 var item = this.ElementAt(index);151 this.data.RemoveAt(index);152 this.data.Add(item);148 if (index == Count - 1) return; 149 150 var item = ElementAt(index); 151 data.RemoveAt(index); 152 data.Add(item); 153 153 } 154 154 155 155 public T Pop() { 156 var value = this.data[this.Count - 1];157 this.data.RemoveAt(this.Count - 1);156 var value = data[Count - 1]; 157 data.RemoveAt(Count - 1); 158 158 159 159 return value; … … 161 161 162 162 public T[] Pop(int count) { 163 var items = this.Peek(count);164 this.Remove(count);163 var items = Peek(count); 164 Remove(count); 165 165 166 166 return items; … … 168 168 169 169 public T Peek() { 170 return this.Top;170 return Top; 171 171 } 172 172 173 173 public T[] Peek(int count) { 174 var startIndex = this.Count - count;174 var startIndex = Count - count; 175 175 176 176 var items = new T[count]; 177 this.data.CopyTo(startIndex, items, 0, count);177 data.CopyTo(startIndex, items, 0, count); 178 178 179 179 return items; … … 181 181 182 182 public void Push(T item) { 183 if (! this.IsEnabled) return;184 185 this.data.Add(item);183 if (!IsEnabled) return; 184 185 data.Add(item); 186 186 } 187 187 188 188 public void Push(T item1, T item2) { 189 if (! this.IsEnabled) return;190 191 this.data.Add(item1);192 this.data.Add(item2);189 if (!IsEnabled) return; 190 191 data.Add(item1); 192 data.Add(item2); 193 193 } 194 194 195 195 public void Push(T item1, T item2, T item3) { 196 if (! this.IsEnabled) return;197 198 this.data.Add(item1);199 this.data.Add(item2);200 this.data.Add(item3);196 if (!IsEnabled) return; 197 198 data.Add(item1); 199 data.Add(item2); 200 data.Add(item3); 201 201 } 202 202 203 203 public void Push(T item1, T item2, T item3, T item4) { 204 if (! this.IsEnabled) return;205 206 this.data.Add(item1);207 this.data.Add(item2);208 this.data.Add(item3);209 this.data.Add(item4);204 if (!IsEnabled) return; 205 206 data.Add(item1); 207 data.Add(item2); 208 data.Add(item3); 209 data.Add(item4); 210 210 } 211 211 212 212 public void PushResult(int count, Func<T[], T> templateFunc) { 213 if (! this.IsEnabled) return;214 215 var startIndex = this.Count - count;213 if (!IsEnabled) return; 214 215 var startIndex = Count - count; 216 216 var items = new T[count]; 217 217 218 this.data.CopyTo(startIndex, items, 0, count);219 this.Remove(count - 1);220 221 this.data[this.Count - 1] = templateFunc(items);218 data.CopyTo(startIndex, items, 0, count); 219 Remove(count - 1); 220 221 data[Count - 1] = templateFunc(items); 222 222 } 223 223 224 224 public void Push(IReadOnlyList<T> items) { 225 if (! this.IsEnabled) return;226 227 for (var i = 0; i < items.Count; i++) this.data.Add(items[i]);225 if (!IsEnabled) return; 226 227 for (var i = 0; i < items.Count; i++) data.Add(items[i]); 228 228 } 229 229 230 230 public void Insert(int index, T item) { 231 if (! this.IsEnabled) return;232 233 this.data.Insert(index, item);231 if (!IsEnabled) return; 232 233 data.Insert(index, item); 234 234 } 235 235 236 236 public void Insert(int index, params T[] items) { 237 if (! this.IsEnabled) return;238 239 this.data.InsertRange(index, items);237 if (!IsEnabled) return; 238 239 data.InsertRange(index, items); 240 240 } 241 241 242 242 public void Insert(int index, IEnumerable<T> items) { 243 if (! this.IsEnabled) return;244 245 this.data.InsertRange(index, items);243 if (!IsEnabled) return; 244 245 data.InsertRange(index, items); 246 246 } 247 247 248 248 public bool Remove(T item) { 249 var index = this.Count - 1;250 if (( this.Count > 0) && this.data[index].Equals(item)) {251 this.data.RemoveAt(index);249 var index = Count - 1; 250 if ((Count > 0) && data[index].Equals(item)) { 251 data.RemoveAt(index); 252 252 return true; 253 253 } … … 256 256 257 257 public void RemoveTop() { 258 this.data.RemoveAt(this.Count - 1);258 data.RemoveAt(Count - 1); 259 259 } 260 260 261 261 public void Remove(int count) { 262 for (var i = 0; i < count; i++) this.data.RemoveAt(this.Count - 1);262 for (var i = 0; i < count; i++) data.RemoveAt(Count - 1); 263 263 } 264 264 265 265 public void RemoveAt(int index) { 266 this.data.RemoveAt(index);266 data.RemoveAt(index); 267 267 } 268 268 269 269 public void RemoveAt(int index, int count) { 270 this.data.RemoveRange(index, count);270 data.RemoveRange(index, count); 271 271 } 272 272 273 273 public bool TryPop(out T item) { 274 if ( this.Count > 0) {275 item = this.Pop();274 if (Count > 0) { 275 item = Pop(); 276 276 return true; 277 277 }
Note: See TracChangeset
for help on using the changeset viewer.