Package net.sf.saxon.expr.elab
Class LearningEvaluator
- java.lang.Object
-
- net.sf.saxon.expr.elab.LearningEvaluator
-
- All Implemented Interfaces:
SequenceEvaluator
public class LearningEvaluator extends java.lang.Object implements SequenceEvaluator
ALearningEvaluator
initially performs lazy incremental evaluation of an expression; but if this proves unproductive, it switches after a while to eager evaluation. Lazy evaluation is considered unproductive if the input sequence is read to completion. A MemoClosure reports back if the input sequence is read to completion, and if the number of sequences that are completely read is equal to the total number of evaluations, lazy evaluation is abandoned.
-
-
Constructor Summary
Constructors Constructor Description LearningEvaluator(Expression expr, SequenceEvaluator lazy)
Construct aLearningEvaluator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Sequence
evaluate(XPathContext context)
Evaluate a construct to produce a value (which might be a lazily evaluated Sequence)boolean
hasDecidedToEvaluateEagerly()
Ask whether the LearningEvaluator has decided to use eager evaluation alwaysvoid
reportCompletion(int serialNumber)
Callback method called when a lazily-evaluated expression has been read to completion
-
-
-
Constructor Detail
-
LearningEvaluator
public LearningEvaluator(Expression expr, SequenceEvaluator lazy)
Construct aLearningEvaluator
- Parameters:
expr
- the expression to be evaluatedlazy
- a SequenceEvaluator that evaluates the expression. Although this is generally obtained by callinggetElaborator().lazily()
, it does not necessarily perform lazy evaluation; some expressions such as literals and variable references choose to evaluate themselves eagerly all the time.
-
-
Method Detail
-
evaluate
public Sequence evaluate(XPathContext context) throws XPathException
Evaluate a construct to produce a value (which might be a lazily evaluated Sequence)- Specified by:
evaluate
in interfaceSequenceEvaluator
- Parameters:
context
- the evaluation context- Returns:
- a Sequence (not necessarily grounded)
- Throws:
XPathException
- if a dynamic error occurs during the evaluation.
-
reportCompletion
public void reportCompletion(int serialNumber)
Callback method called when a lazily-evaluated expression has been read to completion- Parameters:
serialNumber
- identifies the evaluation
-
hasDecidedToEvaluateEagerly
public boolean hasDecidedToEvaluateEagerly()
Ask whether the LearningEvaluator has decided to use eager evaluation always- Returns:
- true if sufficient evaluations have been performed to determine that lazy evaluation offers no benefits
-
-