use of org.drools.core.reteoo.LeftTuple 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);
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakAccumulateNode method doLeftDeletes.
public void doLeftDeletes(AccumulateNode accNode, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
BetaMemory bm = am.getBetaMemory();
TupleMemory ltm = bm.getLeftTupleMemory();
Accumulate accumulate = accNode.getAccumulate();
for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
if (leftTuple.getMemory() != null) {
// it may have been staged and never actually added
ltm.remove(leftTuple);
final AccumulateContext accctx = (AccumulateContext) leftTuple.getContextObject();
leftTuple.setContextObject(null);
removePreviousMatchesForLeftTuple(accumulate, leftTuple, wm, am, accctx, false);
if (accctx.propagated) {
normalizeStagedTuples(stagedLeftTuples, accctx.resultLeftTuple);
trgLeftTuples.addDelete(accctx.resultLeftTuple);
}
}
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakAccumulateNode method doLeftUpdates.
public void doLeftUpdates(AccumulateNode accNode, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
BetaMemory bm = am.getBetaMemory();
TupleMemory rtm = bm.getRightTupleMemory();
Accumulate accumulate = accNode.getAccumulate();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = accNode.getRawConstraints();
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
final AccumulateContext accctx = (AccumulateContext) leftTuple.getContextObject();
constraints.updateFromTuple(contextEntry, wm, leftTuple);
FastIterator rightIt = accNode.getRightIterator(rtm);
RightTuple rightTuple = accNode.getFirstRightTuple(leftTuple, rtm, null, rightIt);
LeftTuple childLeftTuple = leftTuple.getFirstChild();
// if rightTuple is null, we assume there was a bucket change and that bucket is empty
if (childLeftTuple != null && rtm.isIndexed() && !rightIt.isFullIterator() && (rightTuple == null || (rightTuple.getMemory() != childLeftTuple.getRightParent().getMemory()))) {
// our index has changed, so delete all the previous matchings
removePreviousMatchesForLeftTuple(accumulate, leftTuple, wm, am, accctx, true);
// null so the next check will attempt matches for new bucket
childLeftTuple = null;
}
// we can't do anything if RightTupleMemory is empty
if (rightTuple != null) {
doLeftUpdatesProcessChildren(accNode, am, wm, bm, accumulate, constraints, rightIt, leftTuple, accctx, rightTuple, childLeftTuple);
}
leftTuple.clearStaged();
trgLeftTuples.addUpdate(leftTuple);
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakAccumulateNode method doLeftInserts.
public void doLeftInserts(AccumulateNode accNode, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, 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();
boolean leftTupleMemoryEnabled = accNode.isLeftTupleMemoryEnabled();
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
boolean useLeftMemory = leftTupleMemoryEnabled || RuleNetworkEvaluator.useLeftMemory(accNode, leftTuple);
if (useLeftMemory) {
ltm.add(leftTuple);
}
AccumulateContext accresult = new AccumulateContext();
leftTuple.setContextObject(accresult);
accresult.context = accumulate.createContext();
accumulate.init(am.workingMemoryContext, accresult.context, leftTuple, wm);
constraints.updateFromTuple(contextEntry, wm, leftTuple);
FastIterator rightIt = accNode.getRightIterator(rtm);
for (RightTuple rightTuple = accNode.getFirstRightTuple(leftTuple, rtm, null, rightIt); rightTuple != null; ) {
RightTuple nextRightTuple = (RightTuple) rightIt.next(rightTuple);
if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandleForEvaluation())) {
// add a match
addMatch(accNode, accumulate, leftTuple, rightTuple, null, null, wm, am, accresult, useLeftMemory);
if (!useLeftMemory && accNode.isRightInputIsRiaNode()) {
// RIAN with no left memory must have their right tuples removed
rtm.remove(rightTuple);
}
}
rightTuple = nextRightTuple;
}
leftTuple.clearStaged();
trgLeftTuples.addInsert(leftTuple);
constraints.resetTuple(contextEntry);
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakEvalNode method doLeftUpdates.
public void doLeftUpdates(EvalConditionNode evalNode, EvalMemory em, LeftTupleSink sink, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
EvalCondition condition = evalNode.getCondition();
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
boolean wasPropagated = leftTuple.getFirstChild() != null && leftTuple.getContextObject() != EVAL_LEFT_TUPLE_DELETED;
boolean allowed = condition.isAllowed(leftTuple, wm, em.context);
if (allowed) {
leftTuple.setContextObject(null);
if (wasPropagated) {
// update
LeftTuple childLeftTuple = leftTuple.getFirstChild();
childLeftTuple.setPropagationContext(leftTuple.getPropagationContext());
normalizeStagedTuples(stagedLeftTuples, childLeftTuple);
trgLeftTuples.addUpdate(childLeftTuple);
} else {
// assert
trgLeftTuples.addInsert(sink.createLeftTuple(leftTuple, sink, leftTuple.getPropagationContext(), true));
}
} else {
if (wasPropagated) {
// retract
leftTuple.setContextObject(EVAL_LEFT_TUPLE_DELETED);
LeftTuple childLeftTuple = leftTuple.getFirstChild();
childLeftTuple.setPropagationContext(leftTuple.getPropagationContext());
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
}
// else do nothing
}
leftTuple.clearStaged();
leftTuple = next;
}
}
Aggregations