use of org.drools.core.util.FastIterator in project drools by kiegroup.
the class PhreakNotNode method doRightDeletes.
public void doRightDeletes(NotNode notNode, 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 = notNode.getRawConstraints();
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
FastIterator it = notNode.getRightIterator(rtm);
// assign now, so we can remove from memory before doing any possible propagations
boolean useComparisonIndex = rtm.getIndexType().isComparison();
RightTuple rootBlocker = useComparisonIndex ? null : (RightTuple) it.next(rightTuple);
if (rightTuple.getMemory() != null) {
// it may have been staged and never actually added
rtm.remove(rightTuple);
}
if (rightTuple.getBlocked() != null) {
for (LeftTuple leftTuple = rightTuple.getBlocked(); leftTuple != null; ) {
LeftTuple temp = leftTuple.getBlockedNext();
leftTuple.clearBlocker();
if (leftTuple.getStagedType() == LeftTuple.UPDATE) {
// ignore, as it will get processed via left iteration. Children cannot be processed twice
leftTuple = temp;
continue;
}
constraints.updateFromTuple(contextEntry, wm, leftTuple);
if (useComparisonIndex) {
rootBlocker = (RightTuple) rtm.getFirst(leftTuple);
}
// we know that older tuples have been checked so continue next
for (RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) it.next(newBlocker)) {
if (constraints.isAllowedCachedLeft(contextEntry, newBlocker.getFactHandleForEvaluation())) {
leftTuple.setBlocker(newBlocker);
newBlocker.addBlocked(leftTuple);
break;
}
}
if (leftTuple.getBlocker() == null) {
// was previous blocked and not in memory, so add
insertChildLeftTuple(sink, trgLeftTuples, ltm, leftTuple, rightTuple.getPropagationContext(), true);
}
leftTuple = temp;
}
}
rightTuple.setBlocked(null);
rightTuple.clearStaged();
rightTuple = next;
}
constraints.resetTuple(contextEntry);
}
use of org.drools.core.util.FastIterator in project drools by kiegroup.
the class RuleNetworkEvaluator method findLeftTupleBlocker.
public static void findLeftTupleBlocker(BetaNode betaNode, TupleMemory rtm, ContextEntry[] contextEntry, BetaConstraints constraints, LeftTuple leftTuple, boolean useLeftMemory) {
// This method will also remove rightTuples that are from subnetwork where no leftmemory use used
FastIterator it = betaNode.getRightIterator(rtm);
for (RightTuple rightTuple = betaNode.getFirstRightTuple(leftTuple, rtm, null, it); rightTuple != null; ) {
RightTuple nextRight = (RightTuple) it.next(rightTuple);
if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandleForEvaluation())) {
leftTuple.setBlocker(rightTuple);
if (useLeftMemory) {
rightTuple.addBlocked(leftTuple);
break;
} else if (betaNode.isRightInputIsRiaNode()) {
// If we aren't using leftMemory and the right input is a RIAN, then we must iterate and find all subetwork right tuples and remove them
// so we don't break
rtm.remove(rightTuple);
} else {
break;
}
}
rightTuple = nextRight;
}
}
use of org.drools.core.util.FastIterator in project drools by kiegroup.
the class ProtobufOutputMarshaller method writeBeliefSet.
private static void writeBeliefSet(MarshallerWriteContext context, BeliefSet beliefSet, org.drools.core.marshalling.impl.ProtobufMessages.EqualityKey.Builder _key) throws IOException {
ProtobufMessages.BeliefSet.Builder _beliefSet = ProtobufMessages.BeliefSet.newBuilder();
_beliefSet.setHandleId(beliefSet.getFactHandle().getId());
ObjectMarshallingStrategyStore objectMarshallingStrategyStore = context.objectMarshallingStrategyStore;
// for ( LinkedListEntry node = (LinkedListEntry) beliefSet.getFirst(); node != null; node = (LinkedListEntry) node.getNext() ) {
FastIterator it = beliefSet.iterator();
for (LinkedListEntry node = (LinkedListEntry) beliefSet.getFirst(); node != null; node = (LinkedListEntry) it.next(node)) {
LogicalDependency belief = (LogicalDependency) node.getObject();
ProtobufMessages.LogicalDependency.Builder _logicalDependency = ProtobufMessages.LogicalDependency.newBuilder();
// _belief.setActivation( value )
LogicalDependency dependency = (LogicalDependency) node.getObject();
org.drools.core.spi.Activation activation = dependency.getJustifier();
ProtobufMessages.Activation _activation = ProtobufMessages.Activation.newBuilder().setPackageName(activation.getRule().getPackage()).setRuleName(activation.getRule().getName()).setTuple(PersisterHelper.createTuple(activation.getTuple())).build();
_logicalDependency.setActivation(_activation);
if (belief.getObject() != null) {
ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(belief.getObject());
Integer index = context.getStrategyIndex(strategy);
_logicalDependency.setObjectStrategyIndex(index);
_logicalDependency.setObject(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, belief.getObject())));
}
if (belief.getMode() != null) {
ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(belief.getMode());
Integer index = context.getStrategyIndex(strategy);
_logicalDependency.setValueStrategyIndex(index);
_logicalDependency.setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, belief.getMode())));
}
_beliefSet.addLogicalDependency(_logicalDependency.build());
}
_key.setBeliefSet(_beliefSet);
}
use of org.drools.core.util.FastIterator 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.util.FastIterator 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);
}
Aggregations