Changeset 14908 for branches/PushGP/HeuristicLab.PushGP/FeatureTests
- Timestamp:
- 05/02/17 22:03:01 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/FeatureTests/DirtyList
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/FeatureTests/DirtyList/PushList.cs
r14777 r14908 13 13 if (!IsEnabled) return; 14 14 15 this.items[items.Count - 1].Add(item);15 items[items.Count - 1].Add(item); 16 16 } 17 17 … … 36 36 37 37 public void Clear() { 38 this.items.Clear();38 items.Clear(); 39 39 } 40 40 } -
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 } -
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.