summaryrefslogtreecommitdiffstats
path: root/searchlib/src/main/java/com/yahoo
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-11-02 07:15:33 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2021-11-02 07:15:33 +0100
commit83ad134d70540f2da14a40d68aaa0d9d4e7af8be (patch)
tree8b931d63b382592a803bc656c54d5a28c7d4dd0a /searchlib/src/main/java/com/yahoo
parentb14d9ee1e58e2f349972bd66ffcf4b169f90b2cb (diff)
Unify on using a list for backing.
Diffstat (limited to 'searchlib/src/main/java/com/yahoo')
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java13
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ComparisonNode.java23
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java34
3 files changed, 29 insertions, 41 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java
index 0aa62513fdb..55fe66be69e 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.rankingexpression.rule;
-import com.google.common.collect.ImmutableList;
import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.searchlib.rankingexpression.evaluation.Context;
import com.yahoo.searchlib.rankingexpression.evaluation.Value;
@@ -22,17 +21,17 @@ import java.util.List;
*/
public final class ArithmeticNode extends CompositeNode {
- private final ImmutableList<ExpressionNode> children;
- private final ImmutableList<ArithmeticOperator> operators;
+ private final List<ExpressionNode> children;
+ private final List<ArithmeticOperator> operators;
public ArithmeticNode(List<ExpressionNode> children, List<ArithmeticOperator> operators) {
- this.children = ImmutableList.copyOf(children);
- this.operators = ImmutableList.copyOf(operators);
+ this.children = List.copyOf(children);
+ this.operators = List.copyOf(operators);
}
public ArithmeticNode(ExpressionNode leftExpression, ArithmeticOperator operator, ExpressionNode rightExpression) {
- this.children = ImmutableList.of(leftExpression, rightExpression);
- this.operators = ImmutableList.of(operator);
+ this.children = List.of(leftExpression, rightExpression);
+ this.operators = List.of(operator);
}
public List<ArithmeticOperator> operators() { return operators; }
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ComparisonNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ComparisonNode.java
index 02f130cb251..600d3b8d408 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ComparisonNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ComparisonNode.java
@@ -7,7 +7,6 @@ import com.yahoo.searchlib.rankingexpression.evaluation.Value;
import com.yahoo.tensor.TensorType;
import com.yahoo.tensor.evaluation.TypeContext;
-import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
@@ -21,32 +20,28 @@ public class ComparisonNode extends BooleanNode {
/** The operator string of this condition. */
private final TruthOperator operator;
- private final ExpressionNode leftCondition, rightCondition;
+ private final List<ExpressionNode> conditions;
public ComparisonNode(ExpressionNode leftCondition, TruthOperator operator, ExpressionNode rightCondition) {
- this.leftCondition = leftCondition;
+ conditions = List.of(leftCondition, rightCondition);
this.operator = operator;
- this.rightCondition = rightCondition;
}
@Override
public List<ExpressionNode> children() {
- List<ExpressionNode> children = new ArrayList<>(2);
- children.add(leftCondition);
- children.add(rightCondition);
- return children;
+ return conditions;
}
public TruthOperator getOperator() { return operator; }
- public ExpressionNode getLeftCondition() { return leftCondition; }
+ public ExpressionNode getLeftCondition() { return conditions.get(0); }
- public ExpressionNode getRightCondition() { return rightCondition; }
+ public ExpressionNode getRightCondition() { return conditions.get(1); }
@Override
public StringBuilder toString(StringBuilder string, SerializationContext context, Deque<String> path, CompositeNode parent) {
- leftCondition.toString(string, context, path, this).append(' ').append(operator).append(' ');
- return rightCondition.toString(string, context, path, this);
+ getLeftCondition().toString(string, context, path, this).append(' ').append(operator).append(' ');
+ return getRightCondition().toString(string, context, path, this);
}
@Override
@@ -56,8 +51,8 @@ public class ComparisonNode extends BooleanNode {
@Override
public Value evaluate(Context context) {
- Value leftValue = leftCondition.evaluate(context);
- Value rightValue = rightCondition.evaluate(context);
+ Value leftValue = getLeftCondition().evaluate(context);
+ Value rightValue = getRightCondition().evaluate(context);
return leftValue.compare(operator,rightValue);
}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
index 51b68cee443..02d437e83bf 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
@@ -17,10 +17,7 @@ import java.util.List;
* @author bratseth
*/
public final class IfNode extends CompositeNode {
-
- /** The expression nodes that make up this condition. */
- private final ExpressionNode condition, trueExpression, falseExpression;
- /** Frequent calls to children() makes this caching necessary. Might skip the entries above and just keep them as list.*/
+ /** [condition, trueExpression, falseExpression]*/
private final List<ExpressionNode> asList;
private final Double trueProbability;
@@ -41,10 +38,7 @@ public final class IfNode extends CompositeNode {
Double trueProbability) {
if (trueProbability != null && ( trueProbability < 0.0 || trueProbability > 1.0) )
throw new IllegalArgumentException("trueProbability must be a between 0.0 and 1.0, not " + trueProbability);
- this.condition = condition;
this.trueProbability = trueProbability;
- this.trueExpression = trueExpression;
- this.falseExpression = falseExpression;
this.asList = List.of(condition, trueExpression, falseExpression);
}
@@ -53,11 +47,11 @@ public final class IfNode extends CompositeNode {
return asList;
}
- public ExpressionNode getCondition() { return condition; }
+ public ExpressionNode getCondition() { return asList.get(0); }
- public ExpressionNode getTrueExpression() { return trueExpression; }
+ public ExpressionNode getTrueExpression() { return asList.get(1); }
- public ExpressionNode getFalseExpression() { return falseExpression; }
+ public ExpressionNode getFalseExpression() { return asList.get(2); }
/** The average probability that the condition of this node will evaluate to true, or null if not known */
public Double getTrueProbability() { return trueProbability; }
@@ -65,9 +59,9 @@ public final class IfNode extends CompositeNode {
@Override
public StringBuilder toString(StringBuilder string, SerializationContext context, Deque<String> path, CompositeNode parent) {
string.append("if (");
- condition.toString(string, context, path, this).append(", ");
- trueExpression.toString(string, context, path, this).append(", ");
- falseExpression.toString(string, context, path, this);
+ getCondition().toString(string, context, path, this).append(", ");
+ getTrueExpression().toString(string, context, path, this).append(", ");
+ getFalseExpression().toString(string, context, path, this);
if (trueProbability != null) {
string.append(", ").append(trueProbability);
}
@@ -76,23 +70,23 @@ public final class IfNode extends CompositeNode {
@Override
public TensorType type(TypeContext<Reference> context) {
- TensorType trueType = trueExpression.type(context);
- TensorType falseType = falseExpression.type(context);
+ TensorType trueType = getTrueExpression().type(context);
+ TensorType falseType = getFalseExpression().type(context);
return trueType.dimensionwiseGeneralizationWith(falseType).orElseThrow(() ->
new IllegalArgumentException("An if expression must produce compatible types in both " +
"alternatives, but the 'true' type is " + trueType + " while the " +
"'false' type is " + falseType +
- "\n'true' branch: " + trueExpression +
- "\n'false' branch: " + falseExpression)
+ "\n'true' branch: " + getTrueExpression() +
+ "\n'false' branch: " + getFalseExpression())
);
}
@Override
public Value evaluate(Context context) {
- if (condition.evaluate(context).asBoolean())
- return trueExpression.evaluate(context);
+ if (getCondition().evaluate(context).asBoolean())
+ return getTrueExpression().evaluate(context);
else
- return falseExpression.evaluate(context);
+ return getFalseExpression().evaluate(context);
}
@Override