1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
5 | using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
|
---|
6 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
7 |
|
---|
8 | /// <summary>
|
---|
9 | /// Concats two vectors on the type stack.
|
---|
10 | /// </summary>
|
---|
11 | public abstract class VectorConcatExpression<T> : StatelessExpression {
|
---|
12 | protected bool Eval(IInternalPushInterpreter interpter, IPushStack<List<T>> stack) {
|
---|
13 | if (stack.Count < 2 ||
|
---|
14 | stack.Top.Count + stack.ReverseElementAt(1).Count > interpter.Configuration.MaxVectorLength)
|
---|
15 | return false;
|
---|
16 |
|
---|
17 | var first = stack.Pop();
|
---|
18 | var second = stack.Top;
|
---|
19 | var result = new T[first.Count + second.Count];
|
---|
20 |
|
---|
21 | first.CopyTo(result, 0);
|
---|
22 | second.CopyTo(result, first.Count);
|
---|
23 | stack.SetTop(new List<T>(result));
|
---|
24 |
|
---|
25 | return true;
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].CONCAT")]
|
---|
30 | public class IntegerVectorConcatExpression : VectorConcatExpression<long> {
|
---|
31 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
32 | return Eval(interpreter, interpreter.IntegerVectorStack);
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | [PushExpression(StackTypes.FloatVector, "FLOAT[].CONCAT")]
|
---|
37 | public class FloatVectorConcatExpression : VectorConcatExpression<double> {
|
---|
38 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
39 | return Eval(interpreter, interpreter.FloatVectorStack);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].CONCAT")]
|
---|
44 | public class BooleanVectorConcatExpression : VectorConcatExpression<bool> {
|
---|
45 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
46 | return Eval(interpreter, interpreter.BooleanVectorStack);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | [PushExpression(StackTypes.StringVector, "STRING[].CONCAT")]
|
---|
51 | public class StringVectorConcatExpression : VectorConcatExpression<string> {
|
---|
52 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
53 | return Eval(interpreter, interpreter.StringVectorStack);
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|