ruledlt.c
来自「clips源代码」· C语言 代码 · 共 576 行 · 第 1/2 页
C
576 行
/* another join, remember the right entering join as well. */ /*==========================================================*/ prevJoin = join->lastLevel; if (join->joinFromTheRight) { rightJoin = (struct joinNode *) join->rightSideEntryStructure; } else { rightJoin = NULL; } /*=================================================*/ /* If the join was attached to a pattern, remove */ /* any structures associated with the pattern that */ /* are no longer needed. */ /*=================================================*/ #if (! RUN_TIME) && (! BLOAD_ONLY) if (! destroy) { if ((join->rightSideEntryStructure != NULL) && (join->joinFromTheRight == FALSE)) { RemoveIntranetworkLink(theEnv,join); } }#endif /*======================================*/ /* Remove any partial matches contained */ /* in the beta memory of the join. */ /*======================================*/ if (destroy) { DestroyBetaMemory(theEnv,join,LHS); DestroyBetaMemory(theEnv,join,RHS); } else { FlushBetaMemory(theEnv,join,LHS); FlushBetaMemory(theEnv,join,RHS); } ReturnLeftMemory(theEnv,join); ReturnRightMemory(theEnv,join); /*===================================*/ /* Remove the expressions associated */ /* with the join. */ /*===================================*/ #if (! RUN_TIME) && (! BLOAD_ONLY) if (! destroy) { RemoveHashedExpression(theEnv,join->networkTest); RemoveHashedExpression(theEnv,join->secondaryNetworkTest); RemoveHashedExpression(theEnv,join->leftHash); RemoveHashedExpression(theEnv,join->rightHash); }#endif /*============================*/ /* Fix the right prime links. */ /*============================*/ if (join->firstJoin && (join->rightSideEntryStructure == NULL)) { lastLink = NULL; theLink = DefruleData(theEnv)->RightPrimeJoins; while (theLink != NULL) { if (theLink->join == join) { if (lastLink == NULL) { DefruleData(theEnv)->RightPrimeJoins = theLink->next; } else { lastLink->next = theLink->next; }#if (! RUN_TIME) && (! BLOAD_ONLY) rtn_struct(theEnv,joinLink,theLink);#endif theLink = NULL; } else { lastLink = theLink; theLink = lastLink->next; } } } /*===========================*/ /* Fix the left prime links. */ /*===========================*/ if (join->firstJoin && (join->patternIsNegated || join->joinFromTheRight) && (! join->patternIsExists)) { lastLink = NULL; theLink = DefruleData(theEnv)->LeftPrimeJoins; while (theLink != NULL) { if (theLink->join == join) { if (lastLink == NULL) { DefruleData(theEnv)->LeftPrimeJoins = theLink->next; } else { lastLink->next = theLink->next; }#if (! RUN_TIME) && (! BLOAD_ONLY) rtn_struct(theEnv,joinLink,theLink);#endif theLink = NULL; } else { lastLink = theLink; theLink = theLink->next; } } } /*==================================================*/ /* Remove the link to the join from the join above. */ /*==================================================*/ if (prevJoin != NULL) { lastLink = NULL; theLink = prevJoin->nextLinks; while (theLink != NULL) { if (theLink->join == join) { if (lastLink == NULL) { prevJoin->nextLinks = theLink->next; } else { lastLink->next = theLink->next; } #if (! RUN_TIME) && (! BLOAD_ONLY) rtn_struct(theEnv,joinLink,theLink);#endif theLink = NULL; } else { lastLink = theLink; theLink = theLink->next; } } } /*==========================================*/ /* Remove the right join link if it exists. */ /*==========================================*/ if (rightJoin != NULL) { lastLink = NULL; theLink = rightJoin->nextLinks; while (theLink != NULL) { if (theLink->join == join) { if (lastLink == NULL) { rightJoin->nextLinks = theLink->next; } else { lastLink->next = theLink->next; } #if (! RUN_TIME) && (! BLOAD_ONLY) rtn_struct(theEnv,joinLink,theLink);#endif theLink = NULL; } else { lastLink = theLink; theLink = theLink->next; } } if ((rightJoin->nextLinks == NULL) && (rightJoin->ruleToActivate == NULL)) { if (prevJoin != NULL) { lastMark = prevJoin->marked; prevJoin->marked = TRUE; DetachJoins(theEnv,rightJoin,destroy); prevJoin->marked = lastMark; } else { DetachJoins(theEnv,rightJoin,destroy); } } } /*==================*/ /* Delete the join. */ /*==================*/#if (! RUN_TIME) && (! BLOAD_ONLY) rtn_struct(theEnv,joinNode,join);#endif /*===========================================================*/ /* Move on to the next join to be removed. All the joins of */ /* a rule can be deleted by following the right joins links */ /* (when these links exist) and then following the left join */ /* links. This works because if join A enters join B from */ /* the right, the right/left links of join A eventually lead */ /* to the join which enters join B from the left. */ /*===========================================================*/ if (prevJoin == NULL) { return; } else if (prevJoin->ruleToActivate != NULL) { return; } else if (prevJoin->nextLinks == NULL) { join = prevJoin; } else { return; } } }#if (! RUN_TIME) && (! BLOAD_ONLY)/***********************************************************************//* RemoveIntranetworkLink: Removes the link between a join node in the *//* join network and its corresponding pattern node in the pattern *//* network. If the pattern node is then no longer associated with *//* any other joins, it is removed using the function DetachPattern. *//***********************************************************************/static void RemoveIntranetworkLink( void *theEnv, struct joinNode *join) { struct patternNodeHeader *patternPtr; struct joinNode *joinPtr, *lastJoin; /*================================================*/ /* Determine the pattern that enters this join. */ /* Determine the list of joins which this pattern */ /* enters from the right. */ /*================================================*/ patternPtr = (struct patternNodeHeader *) join->rightSideEntryStructure; joinPtr = patternPtr->entryJoin; lastJoin = NULL; /*=================================================*/ /* Loop through the list of joins that the pattern */ /* enters until the join being removed is found. */ /* Remove this join from the list. */ /*=================================================*/ while (joinPtr != NULL) { if (joinPtr == join) { if (lastJoin == NULL) { patternPtr->entryJoin = joinPtr->rightMatchNode; } else { lastJoin->rightMatchNode = joinPtr->rightMatchNode; } joinPtr = NULL; } else { lastJoin = joinPtr; joinPtr = joinPtr->rightMatchNode; } } /*===================================================*/ /* If the terminal node of the pattern doesn't point */ /* to any joins, then start removing the pattern. */ /*===================================================*/ if (patternPtr->entryJoin == NULL) { DetachPattern(theEnv,(int) join->rhsType,patternPtr); } }#endif /* (! RUN_TIME) && (! BLOAD_ONLY) */#endif /* DEFRULE_CONSTRUCT */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?