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

📄 symbol.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 4 页
字号:
   {    char *theBitMap = vTheBitMap;    int tally, i;    BITMAP_HN *past = NULL, *peek;    /*====================================*/    /* Get the hash value for the bitmap. */    /*====================================*/    if (theBitMap == NULL)      {       CLIPSSystemError("SYMBOL",2);       ExitCLIPS(5);      }    tally = HashBitMap(theBitMap,BITMAP_HASH_SIZE,size);    peek = BitMapTable[tally];    /*==================================================*/    /* Search for the bitmap in the list of entries for */    /* this hash table location.  If the bitmap is      */    /* found, then return the address of the bitmap.    */    /*==================================================*/    while (peek != NULL)      {       if (peek->size == size)         {          for (i = 0; i < size ; i++)            { if (peek->contents[i] != theBitMap[i]) break; }                      if (i == size) return((VOID *) peek);         }                past = peek;       peek = peek->next;      }    /*==================================================*/    /* Add the bitmap at the end of the list of entries */    /* for this hash table location.  Return the        */    /*==================================================*/           peek = get_struct(bitMapHashNode);    if (past == NULL) BitMapTable[tally] = peek;    else past->next = peek;    peek->contents = (char *) gm2(size);    peek->next = NULL;    peek->bucket = tally;    peek->count = 0;    peek->size = (unsigned short) size;        for (i = 0; i < size ; i++) peek->contents[i] = theBitMap[i];    /*================================================*/    /* Add the bitmap to the list of ephemeral items. */    /*================================================*/        AddEphemeralHashNode((GENERIC_HN *) peek,&EphemeralBitMapList,                         sizeof(BITMAP_HN),sizeof(long));    peek->depth = CurrentEvaluationDepth;        /*===================================*/    /* Return the address of the bitmap. */    /*===================================*/        return((VOID *) peek);   }     /*******************************************************//* InitializeAtomTables: Initializes the SymbolTable,  *//*   IntegerTable, and FloatTable. It also initializes *//*   the CLIPSTrueSymbol and CLIPSFalseSymbol.         *//*******************************************************/globle VOID InitializeAtomTables()   {    int i;    /*=========================*/    /* Create the hash tables. */    /*=========================*/        SymbolTable = (SYMBOL_HN **)                   gm2((int) sizeof (SYMBOL_HN *) * SYMBOL_HASH_SIZE);    FloatTable = (FLOAT_HN **)                   gm2((int) sizeof (FLOAT_HN *) * FLOAT_HASH_SIZE);    IntegerTable = (INTEGER_HN **)                    gm2((int) sizeof (INTEGER_HN *) * INTEGER_HASH_SIZE);                        BitMapTable = (BITMAP_HN **)                    gm2((int) sizeof (BITMAP_HN *) * BITMAP_HASH_SIZE);    /*===================================================*/    /* Initialize all of the hash table entries to NULL. */    /*===================================================*/        for (i = 0; i < SYMBOL_HASH_SIZE; i++) SymbolTable[i] = NULL;    for (i = 0; i < FLOAT_HASH_SIZE; i++) FloatTable[i] = NULL;    for (i = 0; i < INTEGER_HASH_SIZE; i++) IntegerTable[i] = NULL;    for (i = 0; i < BITMAP_HASH_SIZE; i++) BitMapTable[i] = NULL;    /*========================*/    /* Predefine some values. */    /*========================*/        CLIPSTrueSymbol = AddSymbol(TRUE_STRING);    IncrementSymbolCount(CLIPSTrueSymbol);    CLIPSFalseSymbol = AddSymbol(FALSE_STRING);    IncrementSymbolCount(CLIPSFalseSymbol);    PositiveInfinity = AddSymbol(POSITIVE_INFINITY_STRING);    IncrementSymbolCount(PositiveInfinity);    NegativeInfinity = AddSymbol(NEGATIVE_INFINITY_STRING);    IncrementSymbolCount(NegativeInfinity);    Zero = AddLong(0L);    IncrementIntegerCount(Zero);   }/***************************************************//* HashSymbol: Computes a hash value for a symbol. *//***************************************************/globle int HashSymbol(word,range)  char *word;  int range;  {   register int k,j,i;   register int length;   int tally;   unsigned long count = 0L,tmpLong;   char *tmpPtr;   tmpPtr = (char *) &tmpLong;   /*===============================================*/   /* Count the number of characters in the symbol. */   /*===============================================*/   for (length = 0; word[length]; length++)     { /* Do Nothing */ }   /*================================================================ */   /* Add up the first part of the word as unsigned long int values.  */   /*================================================================ */   length = length / sizeof(unsigned long);   for (i = 0 , j = 0 ; i < length; i++)     {      for (k = 0 ; k < sizeof(unsigned long) ; k++ , j++)        tmpPtr[k] = word[j];      count += tmpLong;     }   /*============================================*/   /* Add the remaining characters to the count. */   /*============================================*/   tmpLong = 0L;   for (word = (char *) &word[j], k = 0;         *word;         word++, k++)      {      tmpPtr[k] = *word;      /* count += (unsigned long) *word; */     }        count += tmpLong;   /*========================*/   /* Return the hash value. */   /*========================*/   tally = (int) (count % range);   if (tally < 0) return(-tally);   return(tally);  }/*************************************************//* HashFloat: Computes a hash value for a float. *//*************************************************/globle int HashFloat(number,range)  double number;  int range;  {   union     {      double fv;      unsigned long int liv;     } fis;   unsigned long count;   int tally;   fis.liv = 0;   fis.fv = number;   count = fis.liv;   tally = (int) (count % range);   if (tally < 0) return(-tally);   return(tally);  }/******************************************************//* HashInteger: Computes a hash value for an integer. *//******************************************************/globle int HashInteger(number,range)  long int number;  int range;  {   int tally;   tally = (int) (number % range);   if (tally < 0) return(-tally);   return(tally);  }  /***************************************************//* HashBitMap: Computes a hash value for a bitmap. *//***************************************************/globle int HashBitMap(word,range,length)  char *word;  int range, length;  {   register int k,j,i;   int tally;   int longLength;   unsigned long count = 0L,tmpLong;   char *tmpPtr;   tmpPtr = (char *) &tmpLong;   /*================================================================ */   /* Add up the first part of the word as unsigned long int values.  */   /*================================================================ */   longLength = length / sizeof(unsigned long);   for (i = 0 , j = 0 ; i < longLength; i++)     {      for (k = 0 ; k < sizeof(unsigned long) ; k++ , j++)        tmpPtr[k] = word[j];      count += tmpLong;     }   /*============================================*/   /* Add the remaining characters to the count. */   /*============================================*/   for (; j < length; j++) count += (unsigned long) word[j];   /*========================*/   /* Return the hash value. */   /*========================*/   tally = (int) (count % range);   if (tally < 0) return(-tally);   return(tally);  }  /*****************************************************//* DecrementSymbolCount: Decrements the count value  *//*   for a SymbolTable entry. Adds the symbol to the *//*   EphemeralSymbolList if the count becomes zero.  *//*****************************************************/globle VOID DecrementSymbolCount(theValue)  SYMBOL_HN *theValue;  {   if (theValue->count < 0)     {      CLIPSSystemError("SYMBOL",3);      ExitCLIPS(5);     }   if (theValue->count == 0)     {      CLIPSSystemError("SYMBOL",4);      ExitCLIPS(5);     }   theValue->count--;   if (theValue->count != 0) return;   if (theValue->markedEphemeral == CLIPS_FALSE)      {        AddEphemeralHashNode((GENERIC_HN *) theValue,&EphemeralSymbolList,                           sizeof(SYMBOL_HN),AVERAGE_STRING_SIZE);     }   return;  }/***************************************************//* DecrementFloatCount: Decrements the count value *//*   for a FloatTable entry. Adds the float to the *//*   EphemeralFloatList if the count becomes zero. *//***************************************************/globle VOID DecrementFloatCount(theValue)  FLOAT_HN *theValue;  {   if (theValue->count <= 0)     {      CLIPSSystemError("SYMBOL",5);      ExitCLIPS(5);     }   theValue->count--;   if (theValue->count != 0) return;   if (theValue->markedEphemeral == CLIPS_FALSE)     {        AddEphemeralHashNode((GENERIC_HN *) theValue,&EphemeralFloatList,                           sizeof(FLOAT_HN),0);     }   return;  }/*********************************************************//* DecrementIntegerCount: Decrements the count value for *//*   an IntegerTable entry. Adds the integer to the      *//*   EphemeralIntegerList if the count becomes zero.     *//*********************************************************/globle VOID DecrementIntegerCount(theValue)  INTEGER_HN *theValue;  {   if (theValue->count <= 0)     {      CLIPSSystemError("SYMBOL",6);      ExitCLIPS(5);     }   theValue->count--;   if (theValue->count != 0) return;   if (theValue->markedEphemeral == CLIPS_FALSE)      {        AddEphemeralHashNode((GENERIC_HN *) theValue,&EphemeralIntegerList,                           sizeof(INTEGER_HN),0);     }   return;  }/*****************************************************//* DecrementBitMapCount: Decrements the count value  *//*   for a BitmapTable entry. Adds the bitmap to the *//*   EphemeralBitMapList if the count becomes zero.  *//*****************************************************/globle VOID DecrementBitMapCount(theValue)

⌨️ 快捷键说明

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