void DetachPattern( int rhsType, struct patternNodeHeader *theHeader) { if (PatternParserArray[rhsType] != NULL) { FlushAlphaBetaMemory(theHeader->alphaMemory); (*PatternParserArray[rhsType]->removePatternFunction)(theHeader); } }
static void ClearBload() { unsigned long int space; long i; struct patternParser *theParser = NULL; struct patternEntity *theEntity = NULL; void *theModule; /*===========================================*/ /* Delete all known entities before removing */ /* the defrule data structures. */ /*===========================================*/ GetNextPatternEntity(&theParser,&theEntity); while (theEntity != NULL) { (*theEntity->theInfo->base.deleteFunction)(theEntity); theEntity = NULL; GetNextPatternEntity(&theParser,&theEntity); } /*=========================================*/ /* Remove all activations from the agenda. */ /*=========================================*/ SaveCurrentModule(); for (theModule = GetNextDefmodule(NULL); theModule != NULL; theModule = GetNextDefmodule(theModule)) { SetCurrentModule(theModule); RemoveAllActivations(); } RestoreCurrentModule(); ClearFocusStack(); /*==========================================================*/ /* Remove all partial matches from the beta memories in the */ /* join network. Alpha memories do not need to be examined */ /* since all pattern entities have been deleted by now. */ /*==========================================================*/ for (i = 0; i < NumberOfJoins; i++) { FlushAlphaBetaMemory(JoinArray[i].beta); } /*================================================*/ /* Decrement the symbol count for each rule name. */ /*================================================*/ for (i = 0; i < NumberOfDefrules; i++) { UnmarkConstructHeader(&DefruleArray[i].header); } /*==================================================*/ /* Return the space allocated for the bload arrays. */ /*==================================================*/ space = NumberOfDefruleModules * sizeof(struct defruleModule); if (space != 0) genlongfree((void *) ModuleArray,space); space = NumberOfDefrules * sizeof(struct defrule); if (space != 0) genlongfree((void *) DefruleArray,space); #if FUZZY_DEFTEMPLATES space = NumberOfPatternFuzzyValues * sizeof(struct fzSlotLocator); if (space != 0) genlongfree((void *) PatternFuzzyValueArray,space); #endif space = NumberOfJoins * sizeof(struct joinNode); if (space != 0) genlongfree((void *) JoinArray,space); }
static void ClearBload( void *theEnv) { unsigned long int space; long i; struct patternParser *theParser = NULL; struct patternEntity *theEntity = NULL; void *theModule; /*===========================================*/ /* Delete all known entities before removing */ /* the defrule data structures. */ /*===========================================*/ GetNextPatternEntity(theEnv,&theParser,&theEntity); while (theEntity != NULL) { (*theEntity->theInfo->base.deleteFunction)(theEnv,theEntity); theEntity = NULL; GetNextPatternEntity(theEnv,&theParser,&theEntity); } /*=========================================*/ /* Remove all activations from the agenda. */ /*=========================================*/ SaveCurrentModule(theEnv); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,theModule); RemoveAllActivations(theEnv); } RestoreCurrentModule(theEnv); EnvClearFocusStack(theEnv); /*==========================================================*/ /* Remove all partial matches from the beta memories in the */ /* join network. Alpha memories do not need to be examined */ /* since all pattern entities have been deleted by now. */ /*==========================================================*/ for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfJoins; i++) { FlushAlphaBetaMemory(theEnv,DefruleBinaryData(theEnv)->JoinArray[i].beta); } /*================================================*/ /* Decrement the symbol count for each rule name. */ /*================================================*/ for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfDefrules; i++) { UnmarkConstructHeader(theEnv,&DefruleBinaryData(theEnv)->DefruleArray[i].header); } /*==================================================*/ /* Return the space allocated for the bload arrays. */ /*==================================================*/ space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->ModuleArray,space); DefruleBinaryData(theEnv)->NumberOfDefruleModules = 0; space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->DefruleArray,space); DefruleBinaryData(theEnv)->NumberOfDefrules = 0; space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->JoinArray,space); DefruleBinaryData(theEnv)->NumberOfJoins = 0; }
static void DetachJoins( struct defrule *theRule) { struct joinNode *join; struct joinNode *prevJoin; struct joinNode *joinPtr, *lastJoin, *rightJoin; /*==================================*/ /* Find the last join for the rule. */ /*==================================*/ join = theRule->lastJoin; theRule->lastJoin = NULL; if (join == NULL) return; /*===================================================*/ /* Remove the activation link from the last join. If */ /* there are joins below this join, then all of the */ /* joins for this rule were shared with another rule */ /* and thus no joins can be deleted. */ /*===================================================*/ join->ruleToActivate = NULL; if (join->nextLevel != NULL) return; /*===========================*/ /* Begin removing the joins. */ /*===========================*/ while (join != NULL) { /*==========================================================*/ /* Remember the join "above" this join (the one that enters */ /* from the left). If the join is entered from the right by */ /* 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 ((join->rightSideEntryStructure != NULL) && (join->joinFromTheRight == FALSE)) { RemoveIntranetworkLink(join); } /*======================================*/ /* Remove any partial matches contained */ /* in the beta memory of the join. */ /*======================================*/ FlushAlphaBetaMemory(join->beta); join->beta = NULL; /*===================================*/ /* Remove the expressions associated */ /* with the join. */ /*===================================*/ RemoveHashedExpression(join->networkTest); /*==================================================*/ /* Remove the link to the join from the join above. */ /*==================================================*/ if (prevJoin == NULL) { rtn_struct(joinNode,join); return; } lastJoin = NULL; joinPtr = prevJoin->nextLevel; while (joinPtr != NULL) { if (joinPtr == join) { if (lastJoin == NULL) { prevJoin->nextLevel = joinPtr->rightDriveNode; } else { lastJoin->rightDriveNode = joinPtr->rightDriveNode; } joinPtr = NULL; } else { lastJoin = joinPtr; joinPtr = joinPtr->rightDriveNode; } } /*==================*/ /* Delete the join. */ /*==================*/ rtn_struct(joinNode,join); /*==========================================*/ /* Remove the right join link if it exists. */ /*==========================================*/ if (rightJoin != NULL) { rightJoin->nextLevel = NULL; prevJoin = rightJoin; } /*===========================================================*/ /* 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->ruleToActivate != NULL) { join = NULL; } else if (prevJoin->nextLevel == NULL) { join = prevJoin; } else { join = NULL; } } }