globle BOOLEAN RemoveHashedFact( struct fact *theFact) { int hashValue; struct factHashEntry *hptr, *prev; hashValue = HashFact(theFact); for (hptr = FactHashTable[hashValue], prev = NULL; hptr != NULL; hptr = hptr->next) { if (hptr->theFact == theFact) { if (prev == NULL) { FactHashTable[hashValue] = hptr->next; rtn_struct(factHashEntry,hptr); return(1); } else { prev->next = hptr->next; rtn_struct(factHashEntry,hptr); return(1); } } prev = hptr; } return(0); }
globle int HandleExistingFuzzyFact( VOID **theFact) { struct fact *tempFact; struct factHashEntry *theFactHash; int hashValue; struct fact *theFactPtr = (struct fact *)*theFact; hashValue = HashFact(theFactPtr); /* Fuzzy facts never get duplicated ... they just get modified if they already exist ... always allow duplication for them... do the required modification to the fact if it already exists */ theFactHash = FactHashTable[hashValue]; tempFact = NULL; while (theFactHash != NULL) { if (theFactPtr->whichDeftemplate == theFactHash->theFact->whichDeftemplate) { /* same template definitions for fact */ if (MultifieldsEqual(&theFactPtr->theProposition, &theFactHash->theFact->theProposition)) { /* MultiFieldsEqual will compare fuzzy fields to be equal if they are both of the same FUZZY_VALUE type */ tempFact = theFactHash->theFact; #if CERTAINTY_FACTORS /* If facts are the same we need to perform global contribution calculation for CF */ changeCFofNewVsExistingFact(theFactPtr, tempFact); #endif /* fuzzy facts (ie. any fuzzy slots) perform global contribution calculation(s) for each fuzzy slot */ changeValueOfFuzzySlots(tempFact, theFactPtr); break; } } theFactHash = theFactHash->next; } if (tempFact != NULL) /* existing fact! retract it before new one gets asserted */ Retract(tempFact); return(hashValue); }
globle int HandleFactDuplication( void *theFact) { struct fact *tempPtr; int hashValue; hashValue = HashFact((struct fact *) theFact); if (FactDuplication) return(hashValue); tempPtr = FactExists((struct fact *) theFact,hashValue); if (tempPtr == NULL) return(hashValue); ReturnFact((struct fact *) theFact); #if LOGICAL_DEPENDENCIES && DEFRULE_CONSTRUCT AddLogicalDependencies((struct patternEntity *) tempPtr,TRUE); #endif return(-1); }
globle int ItemHashValue( int theType, void *theValue, int theRange) { switch(theType) { case FLOAT: return(HashFloat(ValueToDouble(theValue),theRange)); case INTEGER: return(HashInteger(ValueToLong(theValue),theRange)); case SYMBOL: case STRING: #if OBJECT_SYSTEM case INSTANCE_NAME: #endif return(HashSymbol(ValueToString(theValue),theRange)); case MULTIFIELD: return(HashMultifield((struct multifield *) theValue,theRange)); #if DEFTEMPLATE_CONSTRUCT case FACT_ADDRESS: return(HashFact((struct fact *) theValue) % theRange); #endif case EXTERNAL_ADDRESS: #if OBJECT_SYSTEM case INSTANCE_ADDRESS: #endif return(((int) theValue) % theRange); default: SystemError("UTILITY",1); return(-1L); } return(-1L); }
globle intBool RemoveHashedFact( void *theEnv, struct fact *theFact) { unsigned long hashValue; struct factHashEntry *hptr, *prev; hashValue = HashFact(theFact); hashValue = (hashValue % FactData(theEnv)->FactHashTableSize); for (hptr = FactData(theEnv)->FactHashTable[hashValue], prev = NULL; hptr != NULL; hptr = hptr->next) { if (hptr->theFact == theFact) { if (prev == NULL) { FactData(theEnv)->FactHashTable[hashValue] = hptr->next; rtn_struct(theEnv,factHashEntry,hptr); if (FactData(theEnv)->NumberOfFacts == 1) { ResetFactHashTable(theEnv); } return(1); } else { prev->next = hptr->next; rtn_struct(theEnv,factHashEntry,hptr); if (FactData(theEnv)->NumberOfFacts == 1) { ResetFactHashTable(theEnv); } return(1); } } prev = hptr; } return(0); }
globle unsigned long HandleFactDuplication( void *theEnv, void *theFact, intBool *duplicate) { struct fact *tempPtr; unsigned long hashValue; *duplicate = FALSE; hashValue = HashFact((struct fact *) theFact); if (FactData(theEnv)->FactDuplication) return(hashValue); tempPtr = FactExists(theEnv,(struct fact *) theFact,hashValue); if (tempPtr == NULL) return(hashValue); ReturnFact(theEnv,(struct fact *) theFact); #if DEFRULE_CONSTRUCT AddLogicalDependencies(theEnv,(struct patternEntity *) tempPtr,TRUE); #endif *duplicate = TRUE; return(0); }