Search in sources :

Example 1 with AbstractHashTable

use of org.drools.core.util.AbstractHashTable in project drools by kiegroup.

the class PhreakAccumulateNode method doRightInserts.

public void doRightInserts(AccumulateNode accNode, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
    Accumulate accumulate = accNode.getAccumulate();
    BetaMemory bm = am.getBetaMemory();
    TupleMemory ltm = bm.getLeftTupleMemory();
    TupleMemory rtm = bm.getRightTupleMemory();
    ContextEntry[] contextEntry = bm.getContext();
    BetaConstraints constraints = accNode.getRawConstraints();
    if (srcRightTuples.getInsertSize() > 32 && rtm instanceof AbstractHashTable) {
        ((AbstractHashTable) rtm).ensureCapacity(srcRightTuples.getInsertSize());
    }
    for (RightTuple rightTuple = srcRightTuples.getInsertFirst(); rightTuple != null; ) {
        RightTuple next = rightTuple.getStagedNext();
        rtm.add(rightTuple);
        if (ltm != null && ltm.size() > 0) {
            constraints.updateFromFactHandle(contextEntry, wm, rightTuple.getFactHandleForEvaluation());
            FastIterator leftIt = accNode.getLeftIterator(ltm);
            for (LeftTuple leftTuple = accNode.getFirstLeftTuple(rightTuple, ltm, leftIt); leftTuple != null; leftTuple = (LeftTuple) leftIt.next(leftTuple)) {
                if (constraints.isAllowedCachedRight(contextEntry, leftTuple)) {
                    final AccumulateContext accctx = (AccumulateContext) leftTuple.getContextObject();
                    addMatch(accNode, accumulate, leftTuple, rightTuple, null, null, wm, am, accctx, true);
                    // so any existing leftTuples we know are updates, but only add if not already added
                    if (leftTuple.getStagedType() == LeftTuple.NONE) {
                        trgLeftTuples.addUpdate(leftTuple);
                    }
                }
            }
        }
        rightTuple.clearStaged();
        rightTuple = next;
    }
    constraints.resetFactHandle(contextEntry);
}
Also used : AbstractHashTable(org.drools.core.util.AbstractHashTable) BetaConstraints(org.drools.core.common.BetaConstraints) BetaMemory(org.drools.core.reteoo.BetaMemory) FastIterator(org.drools.core.util.FastIterator) RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) ContextEntry(org.drools.core.rule.ContextEntry) AccumulateContext(org.drools.core.reteoo.AccumulateNode.AccumulateContext) Accumulate(org.drools.core.rule.Accumulate)

Example 2 with AbstractHashTable

use of org.drools.core.util.AbstractHashTable in project drools by kiegroup.

the class PhreakJoinNode method doRightInserts.

public void doRightInserts(JoinNode joinNode, LeftTupleSink sink, BetaMemory bm, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
    TupleMemory ltm = bm.getLeftTupleMemory();
    TupleMemory rtm = bm.getRightTupleMemory();
    ContextEntry[] contextEntry = bm.getContext();
    BetaConstraints constraints = joinNode.getRawConstraints();
    if (srcRightTuples.getInsertSize() > 32 && rtm instanceof AbstractHashTable) {
        ((AbstractHashTable) rtm).ensureCapacity(srcRightTuples.getInsertSize());
    }
    for (RightTuple rightTuple = srcRightTuples.getInsertFirst(); rightTuple != null; ) {
        RightTuple next = rightTuple.getStagedNext();
        rtm.add(rightTuple);
        if (ltm != null && ltm.size() > 0) {
            FastIterator it = joinNode.getLeftIterator(ltm);
            constraints.updateFromFactHandle(contextEntry, wm, rightTuple.getFactHandleForEvaluation());
            for (LeftTuple leftTuple = joinNode.getFirstLeftTuple(rightTuple, ltm, it); leftTuple != null; leftTuple = (LeftTuple) it.next(leftTuple)) {
                if (leftTuple.getStagedType() == LeftTuple.UPDATE) {
                    // ignore, as it will get processed via left iteration. Children cannot be processed twice
                    continue;
                }
                if (constraints.isAllowedCachedRight(contextEntry, leftTuple)) {
                    insertChildLeftTuple(trgLeftTuples, leftTuple, rightTuple, null, null, sink, true);
                }
            }
        }
        rightTuple.clearStaged();
        rightTuple = next;
    }
    constraints.resetFactHandle(contextEntry);
}
Also used : AbstractHashTable(org.drools.core.util.AbstractHashTable) BetaConstraints(org.drools.core.common.BetaConstraints) FastIterator(org.drools.core.util.FastIterator) RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) ContextEntry(org.drools.core.rule.ContextEntry)

Aggregations

BetaConstraints (org.drools.core.common.BetaConstraints)2 LeftTuple (org.drools.core.reteoo.LeftTuple)2 RightTuple (org.drools.core.reteoo.RightTuple)2 TupleMemory (org.drools.core.reteoo.TupleMemory)2 ContextEntry (org.drools.core.rule.ContextEntry)2 AbstractHashTable (org.drools.core.util.AbstractHashTable)2 FastIterator (org.drools.core.util.FastIterator)2 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)1 BetaMemory (org.drools.core.reteoo.BetaMemory)1 Accumulate (org.drools.core.rule.Accumulate)1