/// <summary> assertLeft takes an array of facts. Since the Current join may be joining /// against one or more objects, we need to pass all previously matched /// facts. /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); EqHashIndex inx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this); IEnumerator itr = rightmem.iterator(inx); if (itr != null) { while (itr.MoveNext()) { IFact vl = (IFact)itr.Current; if (vl != null) { propogateAssert(linx.add(vl), engine, mem); } } } }
/// <summary> Retracting from the left requires that we propogate the /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Remove(linx); EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this); // now we propogate the retract. To do that, we have // merge each item in the list with the Fact array // and call retract in the successor nodes IEnumerator itr = rightmem.iterator(eqinx); if (itr != null) { while (itr.MoveNext()) { propogateRetract(linx.add((IFact)itr.Current), engine, mem); } } }
protected internal virtual void printBetaNodes(BaseJoin bjoin, bool detailed, int betaTotal) { if (bjoin is HashedEqBNode || bjoin is HashedEqNJoin) { IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin); // we iterate over the keys in the HashMap IEnumerator bitr = bm.Keys.GetEnumerator(); while (bitr.MoveNext()) { Index indx = (Index)bm.Get(bitr.Current); if (detailed) { engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)getBetaRightMemory(bjoin); EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts)); // Add to the total count betaTotal += rightmem.count(eqinx); engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT); IEnumerator ritr = rightmem.iterator(eqinx); if (ritr != null) { StringBuilder buf = new StringBuilder(); while (ritr.MoveNext()) { buf.Append(((IFact)ritr.Current).FactId + ","); } engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT); } engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT); } } } else if (bjoin is HashedNotEqNJoin || bjoin is HashedNotEqBNode) { IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin); // we iterate over the keys in the HashMap IEnumerator bitr = bm.Keys.GetEnumerator(); while (bitr.MoveNext()) { Index indx = (Index)bm.Get(bitr.Current); if (detailed) { engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT); HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)getBetaRightMemory(bjoin); EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts)); // Add to the total count betaTotal += rightmem.count(eqinx); engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT); IEnumerator ritr = rightmem.iterator(eqinx); if (ritr != null) { StringBuilder buf = new StringBuilder(); while (ritr.MoveNext()) { buf.Append(((IFact)ritr.Current).FactId + ","); } engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT); } engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT); } } } else if (bjoin is ExistJoin) { ExistJoin henj = (ExistJoin)bjoin; IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(henj); // we iterate over the keys in the HashMap IEnumerator bitr = bm.Keys.GetEnumerator(); while (bitr.MoveNext()) { Index indx = (Index)bm.Get(bitr.Current); if (detailed) { engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)getBetaRightMemory(henj); EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(henj.binds, indx.Facts)); // Add to the total count betaTotal += rightmem.count(eqinx); engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT); IEnumerator ritr = rightmem.iterator(eqinx); if (ritr != null) { StringBuilder buf = new StringBuilder(); while (ritr.MoveNext()) { buf.Append(((IFact)ritr.Current).FactId + ","); } engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT); } engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT); } } } else if (bjoin is NotJoin) { NotJoin nj = (NotJoin)bjoin; IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)getBetaLeftMemory(bjoin); IEnumerator bitr = bm.Keys.GetEnumerator(); while (bitr.MoveNext()) { Index indx = (Index)bitr.Current; IBetaMemory bmem = (IBetaMemory)bm.Get(indx); engine.writeMessage(bmem.toPPString()); } } else if (bjoin is TemporalEqNode) { TemporalEqNode ten = (TemporalEqNode)bjoin; } else { IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin); // we iterate over the keys in the HashMap IEnumerator bitr = bm.Keys.GetEnumerator(); while (bitr.MoveNext()) { Index indx = (Index)bm.Get(bitr.Current); Object rightmem = betaRightMemories.Get(bjoin); if (detailed) { if (rightmem is HashedAlphaMemoryImpl) { HashedAlphaMemoryImpl hami = (HashedAlphaMemoryImpl)rightmem; engine.writeMessage(bjoin.toPPString() + " count=" + hami.size() + " - " + indx.toPPString() + Constants.LINEBREAK); } else { IGenericMap <Object, Object> rmap = (IGenericMap <Object, Object>)rightmem; engine.writeMessage(bjoin.toPPString() + " count=" + rmap.Count + " - " + indx.toPPString() + Constants.LINEBREAK); } } if (rightmem is HashedAlphaMemoryImpl) { betaTotal += ((HashedAlphaMemoryImpl)rightmem).size(); } else { betaTotal += ((IGenericMap <IFact, IFact>)rightmem).Count; } } } }