Class AbstractArrayContext
- java.lang.Object
-
- com.yahoo.searchlib.rankingexpression.evaluation.Context
-
- com.yahoo.searchlib.rankingexpression.evaluation.AbstractArrayContext
-
- All Implemented Interfaces:
ContextIndex
,com.yahoo.tensor.evaluation.EvaluationContext<Reference>
,com.yahoo.tensor.evaluation.TypeContext<Reference>
,java.lang.Cloneable
- Direct Known Subclasses:
ArrayContext
,DoubleOnlyArrayContext
public abstract class AbstractArrayContext extends Context implements java.lang.Cloneable, ContextIndex
Superclass of contexts which supports array index based lookup. Instances may be reused indefinitely for evaluations of a single ranking expression, in a single thread at the time.- Author:
- bratseth
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractArrayContext(RankingExpression expression)
Create a fast lookup context for an expression.protected
AbstractArrayContext(RankingExpression expression, boolean ignoreUnknownValues)
protected
AbstractArrayContext(RankingExpression expression, boolean ignoreUnknownValues, Value missingValue)
Create a fast lookup context for an expression.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractArrayContext
clone()
Creates a clone of this context suitable for evaluating against the same ranking expression in a different thread (i.e, name name to index map, different value set.protected double[]
doubleValues()
double
getDouble(int index)
Perform a fast lookup directly of the value as a double.int
getIndex(java.lang.String name)
Returns the index from a name.protected boolean
ignoreUnknownValues()
java.util.Set<java.lang.String>
names()
Returns all the names available in this, or throws an UnsupportedOperationException if this operation is not supported.protected java.util.Map<java.lang.String,java.lang.Integer>
nameToIndex()
int
size()
Returns the max number of variables which may be set in thisjava.lang.String
toString()
-
Methods inherited from class com.yahoo.searchlib.rankingexpression.evaluation.Context
get, get, get, getTensor, getType, put, put
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.yahoo.searchlib.rankingexpression.evaluation.ContextIndex
get
-
-
-
-
Constructor Detail
-
AbstractArrayContext
protected AbstractArrayContext(RankingExpression expression)
Create a fast lookup context for an expression. This instance should be reused indefinitely by a single thread. This will fail if unknown values are attempted added.
-
AbstractArrayContext
protected AbstractArrayContext(RankingExpression expression, boolean ignoreUnknownValues)
-
AbstractArrayContext
protected AbstractArrayContext(RankingExpression expression, boolean ignoreUnknownValues, Value missingValue)
Create a fast lookup context for an expression. This instance should be reused indefinitely by a single thread.- Parameters:
expression
- the expression to create a context forignoreUnknownValues
- whether attempts to put values not present in this expression should fail (false - the default), or be ignored (true)
-
-
Method Detail
-
nameToIndex
protected final java.util.Map<java.lang.String,java.lang.Integer> nameToIndex()
-
doubleValues
protected final double[] doubleValues()
-
ignoreUnknownValues
protected final boolean ignoreUnknownValues()
-
names
public java.util.Set<java.lang.String> names()
Description copied from class:Context
Returns all the names available in this, or throws an UnsupportedOperationException if this operation is not supported. This default implementation does the latter.
-
getIndex
public final int getIndex(java.lang.String name)
Returns the index from a name.- Specified by:
getIndex
in interfaceContextIndex
- Throws:
java.lang.NullPointerException
- is this name is not known to this context
-
size
public int size()
Returns the max number of variables which may be set in this- Specified by:
size
in interfaceContextIndex
-
getDouble
public double getDouble(int index)
Perform a fast lookup directly of the value as a double. This is faster than get(index).asDouble()- Specified by:
getDouble
in interfaceContextIndex
- Overrides:
getDouble
in classContext
- Parameters:
index
- the index of the variable whose value to return.- Returns:
- the value of the indexed variable.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
clone
public AbstractArrayContext clone()
Creates a clone of this context suitable for evaluating against the same ranking expression in a different thread (i.e, name name to index map, different value set.- Overrides:
clone
in classjava.lang.Object
-
-