Changeset 14875 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack
- Timestamp:
- 04/18/17 01:15:25 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStack.cs
r14834 r14875 9 9 T BottomOrDefault { get; } 10 10 T this[int key] { get; set; } 11 12 11 void Push(T item); 13 12 void Push(T item1, T item2); 14 13 void Push(T item1, T item2, T item3); 15 14 void Push(T item1, T item2, T item3, T item4); 16 17 15 void Push(IReadOnlyList<T> items, int startIndex = 0); 16 void Push(IReadOnlyList<T> items); 18 17 T Peek(); 19 18 T[] Peek(int count); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PushStack.cs
r14834 r14875 118 118 119 119 public T ReverseElementAt(int offset) { 120 return data[ data.Count - 1 -offset];120 return data[offset]; 121 121 } 122 122 … … 125 125 } 126 126 127 public T this[int key] 128 { 129 get 130 { 131 return data[key]; 132 } 133 set 134 { 135 data[key] = value; 136 } 127 public T this[int index] 128 { 129 get { return data[Count - 1 - index]; } 130 set { data[Count - 1 - index] = value; } 137 131 } 138 132 … … 141 135 var bottomIndex = Count - count; 142 136 143 for (var i = Count - 1; i > bottomIndex; i--) data[i] = data[i - 1]; 137 for (var i = Count - 1; i > bottomIndex; i--) 138 data[i] = data[i - 1]; 144 139 145 140 data[bottomIndex] = top; … … 149 144 if (index == Count - 1) return; 150 145 151 var item = ElementAt(index);146 var item = ReverseElementAt(index); 152 147 data.RemoveAt(index); 153 148 data.Add(item); … … 155 150 156 151 public T Pop() { 157 var value = data[Count - 1];152 var top = Top; 158 153 data.RemoveAt(Count - 1); 159 154 160 return value;155 return top; 161 156 } 162 157 … … 223 218 } 224 219 225 public void Push(IReadOnlyList<T> items, int startIndex = 0) {220 public void Push(IReadOnlyList<T> items, int startIndex) { 226 221 if (!IsEnabled) return; 227 222 … … 229 224 } 230 225 226 public void Push(IReadOnlyList<T> items) { 227 if (!IsEnabled) return; 228 229 data.AddRange(items); 230 } 231 231 232 public void Insert(int index, T item) { 232 233 if (!IsEnabled) return; 233 234 234 data.Insert( index, item);235 data.Insert(Count - index, item); 235 236 } 236 237 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/StackTypes.cs
r14834 r14875 2 2 using System; 3 3 4 // Be aware that it is assumed that this values are equal to HeuristicLab.BenchmarkSuite.DataTypes 4 5 [Flags] 5 6 public enum StackTypes : ushort { … … 13 14 Code = 0x80, 14 15 Exec = 0x100, 15 IntegerVector = 0x200, 16 FloatVector = 0x400, 17 BooleanVector = 0x800, 18 StringVector = 0x1000 16 Return = 0x200, 17 IntegerVector = 0x400, 18 FloatVector = 0x800, 19 StringVector = 0x1000, 20 BooleanVector = 0x2000 19 21 } 20 22 }
Note: See TracChangeset
for help on using the changeset viewer.