use of org.drools.core.util.FastIterator in project drools by kiegroup.
the class MemoryVisitor method checkRightTupleList.
private void checkRightTupleList(final TupleList memory) {
int count = 0;
FastIterator rightIt = memory.fastIterator();
for (Tuple rightTuple = memory.getFirst(); rightTuple != null; rightTuple = (Tuple) rightIt.next(rightTuple)) {
count++;
}
logger.info(indent() + "FactHashTable: " + memory.size() + ":" + count);
if (memory.size() != count) {
logger.info(indent() + "error");
}
}
use of org.drools.core.util.FastIterator in project drools by kiegroup.
the class NotNodeLeftTuple method getAccumulatedObjects.
@Override
public Collection<Object> getAccumulatedObjects() {
if (NodeTypeEnums.ExistsNode != getTupleSink().getType()) {
return Collections.emptyList();
}
BetaNode betaNode = ((BetaNode) getTupleSink());
BetaConstraints constraints = betaNode.getRawConstraints();
InternalWorkingMemory wm = getFactHandle().getEntryPoint().getInternalWorkingMemory();
BetaMemory bm = (BetaMemory) wm.getNodeMemory((MemoryFactory) getTupleSink());
TupleMemory rtm = bm.getRightTupleMemory();
FastIterator it = betaNode.getRightIterator(rtm);
ContextEntry[] contextEntry = bm.getContext();
constraints.updateFromTuple(contextEntry, wm, this);
Collection<Object> result = new ArrayList<>();
for (RightTuple rightTuple = betaNode.getFirstRightTuple(this, rtm, null, it); rightTuple != null; ) {
RightTuple nextRight = (RightTuple) it.next(rightTuple);
InternalFactHandle fh = rightTuple.getFactHandleForEvaluation();
if (constraints.isAllowedCachedLeft(contextEntry, fh)) {
result.add(fh.getObject());
}
rightTuple = nextRight;
}
return result;
}
use of org.drools.core.util.FastIterator in project drools by kiegroup.
the class AccumulateNodeVisitor method doVisit.
@Override
protected void doVisit(NetworkNode node, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
AccumulateNode an = (AccumulateNode) node;
DefaultNodeInfo ni = info.getNodeInfo(node);
final AccumulateMemory memory = (AccumulateMemory) info.getSession().getNodeMemory(an);
ni.setMemoryEnabled(true);
if (an.isObjectMemoryEnabled()) {
ni.setFactMemorySize(memory.getBetaMemory().getRightTupleMemory().size());
}
if (an.isLeftTupleMemoryEnabled()) {
ni.setTupleMemorySize(memory.getBetaMemory().getLeftTupleMemory().size());
FastIterator it = memory.getBetaMemory().getLeftTupleMemory().fullFastIterator();
int i = 0;
for (Tuple leftTuple = BetaNode.getFirstTuple(memory.getBetaMemory().getLeftTupleMemory(), it); leftTuple != null; leftTuple = (Tuple) it.next(leftTuple)) {
AccumulateContext ctx = (AccumulateContext) leftTuple.getContextObject();
if (ctx != null && ctx.result != null) {
i++;
}
}
ni.setCreatedFactHandles(i);
}
}
use of org.drools.core.util.FastIterator in project drools by kiegroup.
the class LeftTupleIndexRangeRBTree method toArray.
public Entry[] toArray() {
FastIterator it = tree.fastIterator();
if (it == null) {
return new Entry[0];
}
List<Comparable> toBeRemoved = new ArrayList<Comparable>();
List<Comparable> nestedToBeRemoved = new ArrayList<Comparable>();
List<Tuple> result = new ArrayList<Tuple>();
RBTree.Node<Comparable<Comparable>, RBTree<Comparable<Comparable>, TupleList>> node = null;
RBTree.Node<Comparable<Comparable>, TupleList> nestedNode = null;
while ((node = (RBTree.Node<Comparable<Comparable>, RBTree<Comparable<Comparable>, TupleList>>) it.next(node)) != null) {
nestedToBeRemoved.clear();
RBTree<Comparable<Comparable>, TupleList> nestedTree = node.value;
FastIterator nestedIt = nestedTree.fastIterator();
while ((nestedNode = (RBTree.Node<Comparable<Comparable>, TupleList>) nestedIt.next(nestedNode)) != null) {
TupleList list = nestedNode.value;
int listSize = list.size();
if (listSize == 0) {
nestedToBeRemoved.add(nestedNode.key);
} else {
Tuple entry = list.getFirst();
while (entry != null) {
result.add(entry);
entry = (Tuple) entry.getNext();
}
}
}
for (Comparable key : nestedToBeRemoved) {
nestedTree.delete(key);
}
if (nestedTree.isEmpty()) {
toBeRemoved.add(node.key);
}
}
for (Comparable key : toBeRemoved) {
tree.delete(key);
}
return result.toArray(new Tuple[result.size()]);
}
use of org.drools.core.util.FastIterator in project drools by kiegroup.
the class RightTupleIndexRangeRBTree method toArray.
public Entry[] toArray() {
FastIterator it = tree.fastIterator();
if (it == null) {
return new Entry[0];
}
List<Comparable> toBeRemoved = new ArrayList<Comparable>();
List<Tuple> result = new ArrayList<Tuple>();
RBTree.Node<Comparable<Comparable>, TupleList> node;
while ((node = (RBTree.Node<Comparable<Comparable>, TupleList>) it.next(null)) != null) {
TupleList bucket = node.value;
if (bucket.size() == 0) {
toBeRemoved.add(node.key);
} else {
Tuple entry = bucket.getFirst();
while (entry != null) {
result.add(entry);
entry = (Tuple) entry.getNext();
}
}
}
for (Comparable key : toBeRemoved) {
tree.delete(key);
}
return result.toArray(new Tuple[result.size()]);
}
Aggregations