⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rulebld.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
   if (IdenticalExpression(testJoin->secondaryNetworkTest,secondaryJoinTest) != TRUE)     { return(FALSE); }        /*====================================================================*/   /* The alpha memory hashing values associated with the join must be   */   /* identical to the hashing values stored with the join to be shared. */   /*====================================================================*/   if (IdenticalExpression(testJoin->leftHash,leftHash) != TRUE)     { return(FALSE); }   if (IdenticalExpression(testJoin->rightHash,rightHash) != TRUE)     { return(FALSE); }        /*=============================================*/   /* The join can be shared since all conditions */   /* for sharing have been satisfied.            */   /*=============================================*/   return(TRUE);  }/*************************************************************************//* CreateNewJoin: Creates a new join and links it into the join network. *//*************************************************************************/static struct joinNode *CreateNewJoin(  void *theEnv,  struct expr *joinTest,  struct expr *secondaryJoinTest,  struct joinNode *lhsEntryStruct,  void *rhsEntryStruct,  int joinFromTheRight,  int negatedRHSPattern,  int existsRHSPattern,  struct expr *leftHash,  struct expr *rightHash)  {   struct joinNode *newJoin;   struct joinLink *theLink;      /*===============================================*/   /* If compilations are being watch, print +j to  */   /* indicate that a new join has been created for */   /* this pattern of the rule (i.e. a join could   */   /* not be shared with another rule.              */   /*===============================================*/#if DEBUGGING_FUNCTIONS   if ((EnvGetWatchItem(theEnv,"compilations") == TRUE) && GetPrintWhileLoading(theEnv))     { EnvPrintRouter(theEnv,WDIALOG,"+j"); }#endif   /*======================*/   /* Create the new join. */   /*======================*/   newJoin = get_struct(theEnv,joinNode);      /*======================================================*/   /* The first join of a rule does not have a beta memory */   /* unless the RHS pattern is an exists or not CE.       */   /*======================================================*/      if ((lhsEntryStruct != NULL) || existsRHSPattern || negatedRHSPattern || joinFromTheRight)     {      if (leftHash == NULL)             {               newJoin->leftMemory = get_struct(theEnv,betaMemory);          newJoin->leftMemory->beta = genalloc(theEnv,sizeof(struct partialMatch *));         newJoin->leftMemory->beta[0] = NULL;         newJoin->leftMemory->size = 1;         newJoin->leftMemory->count = 0;         }      else        {         newJoin->leftMemory = get_struct(theEnv,betaMemory);          newJoin->leftMemory->beta = genalloc(theEnv,sizeof(struct partialMatch *) * INITIAL_BETA_HASH_SIZE);         memset(newJoin->leftMemory->beta,0,sizeof(struct partialMatch *) * INITIAL_BETA_HASH_SIZE);         newJoin->leftMemory->size = INITIAL_BETA_HASH_SIZE;         newJoin->leftMemory->count = 0;        }            /*===========================================================*/      /* If the first join of a rule connects to an exists or not  */      /* CE, then we create an empty partial match for the usually */      /* empty left beta memory so that we can track the current   */      /* current right memory partial match satisfying the CE.     */      /*===========================================================*/               if ((lhsEntryStruct == NULL) && (existsRHSPattern || negatedRHSPattern || joinFromTheRight))        {         newJoin->leftMemory->beta[0] = CreateEmptyPartialMatch(theEnv);          newJoin->leftMemory->beta[0]->owner = newJoin;         newJoin->leftMemory->count = 1;        }     }   else     { newJoin->leftMemory = NULL; }        if (joinFromTheRight)     {      if (leftHash == NULL)             {               newJoin->rightMemory = get_struct(theEnv,betaMemory);          newJoin->rightMemory->beta = genalloc(theEnv,sizeof(struct partialMatch *));         newJoin->rightMemory->last = genalloc(theEnv,sizeof(struct partialMatch *));         newJoin->rightMemory->beta[0] = NULL;         newJoin->rightMemory->last[0] = NULL;         newJoin->rightMemory->size = 1;         newJoin->rightMemory->count = 0;         }      else        {         newJoin->rightMemory = get_struct(theEnv,betaMemory);          newJoin->rightMemory->beta = genalloc(theEnv,sizeof(struct partialMatch *) * INITIAL_BETA_HASH_SIZE);         newJoin->rightMemory->last = genalloc(theEnv,sizeof(struct partialMatch *) * INITIAL_BETA_HASH_SIZE);         memset(newJoin->rightMemory->beta,0,sizeof(struct partialMatch *) * INITIAL_BETA_HASH_SIZE);         memset(newJoin->rightMemory->last,0,sizeof(struct partialMatch *) * INITIAL_BETA_HASH_SIZE);         newJoin->rightMemory->size = INITIAL_BETA_HASH_SIZE;         newJoin->rightMemory->count = 0;        }          }   else if ((lhsEntryStruct == NULL) && (rhsEntryStruct == NULL))     {      newJoin->rightMemory = get_struct(theEnv,betaMemory);       newJoin->rightMemory->beta = genalloc(theEnv,sizeof(struct partialMatch *));      newJoin->rightMemory->last = genalloc(theEnv,sizeof(struct partialMatch *));      newJoin->rightMemory->beta[0] = CreateEmptyPartialMatch(theEnv);      newJoin->rightMemory->beta[0]->owner = newJoin;      newJoin->rightMemory->beta[0]->rhsMemory = TRUE;      newJoin->rightMemory->last[0] = newJoin->rightMemory->beta[0];      newJoin->rightMemory->size = 1;      newJoin->rightMemory->count = 1;         }   else     { newJoin->rightMemory = NULL; }        newJoin->nextLinks = NULL;   newJoin->joinFromTheRight = joinFromTheRight;      if (existsRHSPattern)     { newJoin->patternIsNegated = FALSE; }   else     { newJoin->patternIsNegated = negatedRHSPattern; }   newJoin->patternIsExists = existsRHSPattern;   newJoin->marked = FALSE;   newJoin->initialize = EnvGetIncrementalReset(theEnv);   newJoin->logicalJoin = FALSE;   newJoin->ruleToActivate = NULL;   newJoin->memoryAdds = 0;   newJoin->memoryDeletes = 0;   newJoin->memoryCompares = 0;   /*==============================================*/   /* Install the expressions used to determine    */   /* if a partial match satisfies the constraints */   /* associated with this join.                   */   /*==============================================*/   newJoin->networkTest = AddHashedExpression(theEnv,joinTest);   newJoin->secondaryNetworkTest = AddHashedExpression(theEnv,secondaryJoinTest);      /*=====================================================*/   /* Install the expression used to hash the beta memory */   /* partial match to determine the location to search   */   /* in the alpha memory.                                */   /*=====================================================*/      newJoin->leftHash = AddHashedExpression(theEnv,leftHash);   newJoin->rightHash = AddHashedExpression(theEnv,rightHash);   /*============================================================*/   /* Initialize the values associated with the LHS of the join. */   /*============================================================*/   newJoin->lastLevel = lhsEntryStruct;   if (lhsEntryStruct == NULL)     {      newJoin->firstJoin = TRUE;      newJoin->depth = 1;     }   else     {      newJoin->firstJoin = FALSE;      newJoin->depth = lhsEntryStruct->depth;      newJoin->depth++; /* To work around Sparcworks C compiler bug */            theLink = get_struct(theEnv,joinLink);      theLink->join = newJoin;      theLink->enterDirection = LHS;      theLink->next = lhsEntryStruct->nextLinks;      lhsEntryStruct->nextLinks = theLink;     }   /*=======================================================*/   /* Initialize the pointer values associated with the RHS */   /* of the join (both for the new join and the join or    */   /* pattern which enters this join from the right.        */   /*=======================================================*/   newJoin->rightSideEntryStructure = rhsEntryStruct;      if (rhsEntryStruct == NULL)     {       if (newJoin->firstJoin)        {         theLink = get_struct(theEnv,joinLink);         theLink->join = newJoin;         theLink->enterDirection = RHS;         theLink->next = DefruleData(theEnv)->RightPrimeJoins;         DefruleData(theEnv)->RightPrimeJoins = theLink;        }              newJoin->rightMatchNode = NULL;              return(newJoin);      }        /*===========================================================*/   /* If the first join of a rule is a not CE, then it needs to */   /* be "primed" under certain circumstances. This used to be  */   /* handled by adding the (initial-fact) pattern to a rule    */   /* with the not CE as its first pattern, but this alternate  */   /* mechanism is now used so patterns don't have to be added. */   /*===========================================================*/        if (newJoin->firstJoin && (newJoin->patternIsNegated || newJoin->joinFromTheRight) && (! newJoin->patternIsExists))     {      theLink = get_struct(theEnv,joinLink);      theLink->join = newJoin;      theLink->enterDirection = LHS;      theLink->next = DefruleData(theEnv)->LeftPrimeJoins;      DefruleData(theEnv)->LeftPrimeJoins = theLink;     }          if (joinFromTheRight)     {      theLink = get_struct(theEnv,joinLink);      theLink->join = newJoin;      theLink->enterDirection = RHS;      theLink->next = ((struct joinNode *) rhsEntryStruct)->nextLinks;      ((struct joinNode *) rhsEntryStruct)->nextLinks = theLink;      newJoin->rightMatchNode = NULL;     }   else     {      newJoin->rightMatchNode = ((struct patternNodeHeader *) rhsEntryStruct)->entryJoin;      ((struct patternNodeHeader *) rhsEntryStruct)->entryJoin = newJoin;     }   /*================================*/   /* Return the newly created join. */   /*================================*/   return(newJoin);  }#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -