Changeset 15017 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorTakeExpressions.cs
- Timestamp:
- 06/01/17 09:28:34 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorTakeExpressions.cs
r14952 r15017 2 2 3 3 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 4 using System; 5 using System.Linq; 6 4 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 5 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions; 6 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 7 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; … … 17 21 protected VectorTakeExpression(bool deserializing) : base(deserializing) { } 18 22 19 protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack< List<T>> vectorStack) {23 protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) { 20 24 return vectorStack.IsEmpty || interpreter.IntegerStack.IsEmpty; 21 25 } 22 26 23 protected void Eval(IInternalPushInterpreter interpreter, IPushStack<List<T>> vectorStack) { 24 var count = (int)interpreter.IntegerStack.Pop(); 27 protected void Eval(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) { 25 28 26 29 if (vectorStack.Top.Count == 0) 27 30 return; 28 31 29 count %= vectorStack.Top.Count;32 var count = interpreter.IntegerStack.Pop().AsInt(vectorStack.Top.Count); 30 33 31 34 if (count < 0) 32 35 count *= -1; 33 36 34 var result = vectorStack.Top.GetRange(0, count); 35 vectorStack.SetTop(result); 37 var vector = vectorStack.Top; 38 var list = vector as List<T>; 39 40 if (list != null) { 41 var newTop = new T[count]; 42 list.CopyTo(0, newTop, 0, count); 43 vectorStack.Top = newTop; 44 return; 45 } 46 47 var array = vector as T[]; 48 if (array != null) { 49 var newTop = new T[count]; 50 Array.Copy(array, 0, newTop, 0, count); 51 vectorStack.Top = newTop; 52 return; 53 } 54 55 vectorStack.Top = vector.Take(count).ToArray(); 36 56 } 37 57 }
Note: See TracChangeset
for help on using the changeset viewer.