Search in sources :

Example 1 with OpenIntToList

use of org.matheclipse.core.eval.util.OpenIntToList in project symja_android_library by axkr.

the class HashedOrderlessMatcher method evaluateHashedValues.

private static IAST evaluateHashedValues(final IAST orderlessAST, OpenIntToList<AbstractHashedPatternRules> hashRuleMap, int[] hashValues) {
    boolean evaled = false;
    IAST result = orderlessAST.copyHead();
    for (int i = 0; i < hashValues.length - 1; i++) {
        if (hashValues[i] == 0) {
            // already used entry
            continue;
        }
        evaled: for (int j = i + 1; j < hashValues.length; j++) {
            if (hashValues[j] == 0) {
                // already used entry
                continue;
            }
            final List<AbstractHashedPatternRules> hashRuleList = hashRuleMap.get(AbstractHashedPatternRules.calculateHashcode(hashValues[i], hashValues[j]));
            if (hashRuleList != null) {
                for (AbstractHashedPatternRules hashRule : hashRuleList) {
                    if (!hashRule.isPattern1() && !hashRule.isPattern2()) {
                        if (hashValues[i] != hashRule.getHash1() || hashValues[j] != hashRule.getHash2()) {
                            if (hashValues[i] != hashRule.getHash2() || hashValues[j] != hashRule.getHash1()) {
                                // hash code of both entries aren't matching
                                continue;
                            }
                            if (updateHashValues(result, orderlessAST, hashRule, hashValues, j, i)) {
                                evaled = true;
                                break evaled;
                            }
                            continue;
                        }
                        if (updateHashValues(result, orderlessAST, hashRule, hashValues, i, j)) {
                            evaled = true;
                            break evaled;
                        }
                        if (hashValues[i] != hashRule.getHash2() || hashValues[j] != hashRule.getHash1()) {
                            // hash code of both entries aren't matching
                            continue;
                        }
                        if (updateHashValues(result, orderlessAST, hashRule, hashValues, j, i)) {
                            evaled = true;
                            break evaled;
                        }
                        continue;
                    }
                    if (updateHashValues(result, orderlessAST, hashRule, hashValues, i, j)) {
                        evaled = true;
                        break evaled;
                    }
                    if (updateHashValues(result, orderlessAST, hashRule, hashValues, j, i)) {
                        evaled = true;
                        break evaled;
                    }
                }
            }
        }
    }
    if (evaled) {
        // append the rest of the unevaluated arguments
        for (int i = 0; i < hashValues.length; i++) {
            if (hashValues[i] != 0) {
                result.append(orderlessAST.get(i + 1));
            }
        }
        return result;
    }
    return F.NIL;
}
Also used : List(java.util.List) OpenIntToList(org.matheclipse.core.eval.util.OpenIntToList) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

List (java.util.List)1 OpenIntToList (org.matheclipse.core.eval.util.OpenIntToList)1 IAST (org.matheclipse.core.interfaces.IAST)1