use of org.matheclipse.core.visit.HashValueVisitor in project symja_android_library by axkr.
the class HashedOrderlessMatcher method evaluateRepeated.
/**
* Evaluate an <code>Orderless</code> AST with the defined
* <code>HashedPatternRules</code> as long as the header of the given
* expression equals the evaluated expression.
*
* @param orderlessAST
* @return
* @see HashedPatternRules
*/
public IAST evaluateRepeated(final IAST orderlessAST) {
if (orderlessAST.isEvalFlagOn(IAST.IS_HASH_EVALED)) {
return F.NIL;
}
IAST temp = orderlessAST;
if (checkMinimmumASTs(temp)) {
boolean evaled = false;
int[] hashValues;
if (!fPatternHashRuleMap.isEmpty()) {
IExpr head = orderlessAST.head();
IAST result = F.NIL;
while (temp.isPresent()) {
hashValues = new int[(temp.size() - 1)];
HashValueVisitor v = new HashValueVisitor();
for (int i = 0; i < hashValues.length; i++) {
hashValues[i] = temp.get(i + 1).accept(v);
v.setUp();
}
result = evaluateHashedValues(temp, fPatternHashRuleMap, hashValues);
if (result.isPresent()) {
temp = result;
evaled = true;
if (!temp.head().equals(head)) {
temp.setEvalFlags(IAST.IS_HASH_EVALED);
return temp;
}
} else {
break;
}
}
}
if (!fHashRuleMap.isEmpty()) {
hashValues = new int[(temp.size() - 1)];
for (int i = 0; i < hashValues.length; i++) {
hashValues[i] = temp.get(i + 1).head().hashCode();
}
IAST result = evaluateHashedValues(temp, fHashRuleMap, hashValues);
if (result.isPresent()) {
result.setEvalFlags(IAST.IS_HASH_EVALED);
return result;
}
}
if (evaled) {
temp.setEvalFlags(IAST.IS_HASH_EVALED);
return temp;
}
}
orderlessAST.setEvalFlags(IAST.IS_HASH_EVALED);
return F.NIL;
}
use of org.matheclipse.core.visit.HashValueVisitor in project symja_android_library by axkr.
the class HashedOrderlessMatcher method evaluate.
/**
* Evaluate an <code>Orderless</code> AST only once with the defined
* <code>HashedPatternRules</code>.
*
* @param orderlessAST
* @return
* @see HashedPatternRules
*/
public IAST evaluate(final IAST orderlessAST) {
// TODO Performance hotspot
int[] hashValues = new int[(orderlessAST.size() - 1)];
if (!fPatternHashRuleMap.isEmpty()) {
HashValueVisitor v = new HashValueVisitor();
for (int i = 0; i < hashValues.length; i++) {
hashValues[i] = orderlessAST.get(i + 1).accept(v);
v.setUp();
}
IAST result = evaluateHashedValues(orderlessAST, fPatternHashRuleMap, hashValues);
if (result.isPresent()) {
return result;
}
}
if (!fHashRuleMap.isEmpty()) {
for (int i = 0; i < hashValues.length; i++) {
hashValues[i] = orderlessAST.get(i + 1).head().hashCode();
}
return evaluateHashedValues(orderlessAST, fHashRuleMap, hashValues);
}
return F.NIL;
}
Aggregations