void RemoveConstraint( Environment *theEnv, struct constraintRecord *theConstraint) { struct constraintRecord *tmpPtr, *prevPtr = NULL; if (theConstraint == NULL) return; /*========================================*/ /* If the bucket value is less than zero, */ /* then the constraint wasn't stored in */ /* the hash table. */ /*========================================*/ if (! theConstraint->installed) { ReturnConstraintRecord(theEnv,theConstraint); return; } /*================================*/ /* Find and remove the constraint */ /* from the contraint hash table. */ /*================================*/ tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[theConstraint->bucket]; while (tmpPtr != NULL) { if (tmpPtr == theConstraint) { theConstraint->count--; if (theConstraint->count == 0) { if (prevPtr == NULL) { ConstraintData(theEnv)->ConstraintHashtable[theConstraint->bucket] = theConstraint->next; } else { prevPtr->next = theConstraint->next; } DeinstallConstraintRecord(theEnv,theConstraint); ReturnConstraintRecord(theEnv,theConstraint); } return; } prevPtr = tmpPtr; tmpPtr = tmpPtr->next; } return; }
struct constraintRecord *AddConstraint( Environment *theEnv, struct constraintRecord *theConstraint) { struct constraintRecord *tmpPtr; unsigned long hashValue; if (theConstraint == NULL) return NULL; hashValue = HashConstraint(theConstraint); for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[hashValue]; tmpPtr != NULL; tmpPtr = tmpPtr->next) { if (ConstraintCompare(theConstraint,tmpPtr)) { tmpPtr->count++; ReturnConstraintRecord(theEnv,theConstraint); return tmpPtr; } } InstallConstraintRecord(theEnv,theConstraint); theConstraint->count = 1; theConstraint->bucket = (unsigned int) hashValue; theConstraint->installed = true; theConstraint->next = ConstraintData(theEnv)->ConstraintHashtable[hashValue]; ConstraintData(theEnv)->ConstraintHashtable[hashValue] = theConstraint; return theConstraint; }
static void DeallocateConstraintData( Environment *theEnv) { #if ! RUN_TIME struct constraintRecord *tmpPtr, *nextPtr; int i; for (i = 0; i < SIZE_CONSTRAINT_HASH; i++) { tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i]; while (tmpPtr != NULL) { nextPtr = tmpPtr->next; ReturnConstraintRecord(theEnv,tmpPtr); tmpPtr = nextPtr; } } rm(theEnv,ConstraintData(theEnv)->ConstraintHashtable, sizeof(struct constraintRecord *) * SIZE_CONSTRAINT_HASH); #else #if MAC_XCD #pragma unused(theEnv) #endif #endif #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) if (ConstraintData(theEnv)->NumberOfConstraints != 0) { genfree(theEnv,ConstraintData(theEnv)->ConstraintArray, (sizeof(CONSTRAINT_RECORD) * ConstraintData(theEnv)->NumberOfConstraints)); } #endif }
globle struct constraintRecord *AddConstraint( void *theEnv, struct constraintRecord *theConstraint) { struct constraintRecord *tmpPtr; unsigned long hashValue; if (theConstraint == NULL) return(NULL); hashValue = HashConstraint(theConstraint); for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[hashValue]; tmpPtr != NULL; tmpPtr = tmpPtr->next) { if (ConstraintCompare(theConstraint,tmpPtr)) { tmpPtr->count++; ReturnConstraintRecord(theEnv,theConstraint); return(tmpPtr); } } InstallConstraintRecord(theEnv,theConstraint); theConstraint->count = 1; theConstraint->bucket = hashValue; theConstraint->next = ConstraintData(theEnv)->ConstraintHashtable[hashValue]; ConstraintData(theEnv)->ConstraintHashtable[hashValue] = theConstraint; return(theConstraint); }
static void ReturnConstraintRecord( Environment *theEnv, CONSTRAINT_RECORD *constraints) { if (constraints == NULL) return; if (! constraints->installed) { ReturnExpression(theEnv,constraints->classList); ReturnExpression(theEnv,constraints->restrictionList); ReturnExpression(theEnv,constraints->maxValue); ReturnExpression(theEnv,constraints->minValue); ReturnExpression(theEnv,constraints->minFields); ReturnExpression(theEnv,constraints->maxFields); } ReturnConstraintRecord(theEnv,constraints->multifield); rtn_struct(theEnv,constraintRecord,constraints); }