Search in sources :

Example 21 with FastIterator

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");
    }
}
Also used : FastIterator(org.drools.core.util.FastIterator) Tuple(org.drools.core.spi.Tuple)

Example 22 with FastIterator

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;
}
Also used : BetaConstraints(org.drools.core.common.BetaConstraints) ArrayList(java.util.ArrayList) MemoryFactory(org.drools.core.common.MemoryFactory) ContextEntry(org.drools.core.rule.ContextEntry) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) FastIterator(org.drools.core.util.FastIterator) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 23 with FastIterator

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);
    }
}
Also used : AccumulateMemory(org.drools.core.reteoo.AccumulateNode.AccumulateMemory) AccumulateNode(org.drools.core.reteoo.AccumulateNode) FastIterator(org.drools.core.util.FastIterator) Tuple(org.drools.core.spi.Tuple) AccumulateContext(org.drools.core.reteoo.AccumulateNode.AccumulateContext)

Example 24 with FastIterator

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()]);
}
Also used : ArrayList(java.util.ArrayList) Entry(org.drools.core.util.Entry) RBTree(org.drools.core.util.RBTree) FastIterator(org.drools.core.util.FastIterator) Tuple(org.drools.core.spi.Tuple)

Example 25 with FastIterator

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()]);
}
Also used : Entry(org.drools.core.util.Entry) ArrayList(java.util.ArrayList) RBTree(org.drools.core.util.RBTree) FastIterator(org.drools.core.util.FastIterator) Tuple(org.drools.core.spi.Tuple)

Aggregations

FastIterator (org.drools.core.util.FastIterator)40 RightTuple (org.drools.core.reteoo.RightTuple)27 LeftTuple (org.drools.core.reteoo.LeftTuple)24 TupleMemory (org.drools.core.reteoo.TupleMemory)21 BetaConstraints (org.drools.core.common.BetaConstraints)18 ContextEntry (org.drools.core.rule.ContextEntry)18 Tuple (org.drools.core.spi.Tuple)12 BetaMemory (org.drools.core.reteoo.BetaMemory)11 PhreakJoinNode.updateChildLeftTuple (org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple)9 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)8 ArrayList (java.util.ArrayList)5 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)5 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)5 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)5 FromMemory (org.drools.core.reteoo.FromNode.FromMemory)4 ObjectSource (org.drools.core.reteoo.ObjectSource)4 HashMap (java.util.HashMap)3 InternalFactHandle (org.drools.core.common.InternalFactHandle)3 AccumulateNode (org.drools.core.reteoo.AccumulateNode)3 BetaNode (org.drools.core.reteoo.BetaNode)3