Class 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
    • 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 this
      java.lang.String toString()  
      • 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
      • Methods inherited from interface com.yahoo.tensor.evaluation.TypeContext

        getType
    • 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 for
        ignoreUnknownValues - 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.
        Overrides:
        names in class Context
        Returns:
        the set of all variable names.
      • getIndex

        public final int getIndex​(java.lang.String name)
        Returns the index from a name.
        Specified by:
        getIndex in interface ContextIndex
        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 interface ContextIndex
      • 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 interface ContextIndex
        Overrides:
        getDouble in class Context
        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 class java.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 class java.lang.Object