home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Tests / lex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-02  |  1.2 KB  |  48 lines  |  [TEXT/MPS ]

  1. static unsigned int
  2. apple_hash (str, len)
  3.      register char *str;
  4.      register int unsigned len;
  5. {
  6.   static unsigned char asso_values[] =
  7.     {
  8.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  9.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  10.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  11.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  12.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  13.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  14.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  15.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  16.      115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
  17.      115, 115, 115, 115, 115,   1, 115,   2,   1,  24,
  18.       26,   5,  19,  28,   6,  13, 115,   1,  12,   1,
  19.       30,  21,  35, 115,  39,  12,   1,  20,  27,   9,
  20.      115, 115,   1, 115, 115, 115, 115, 115,
  21.     };
  22.   register int hval = len;
  23.  
  24.   switch (hval)
  25.     {
  26.       default:
  27.       case 3:
  28.         hval += asso_values[str[2]];
  29.       case 2:
  30.       case 1:
  31.         hval += asso_values[str[0]];
  32.     }
  33.   return hval + asso_values[str[len - 1]];
  34. }
  35.  
  36. main() {
  37.   int a;
  38.   char b[10];
  39.   int i;
  40.   
  41.   b[1] = 0;
  42.   
  43.   for(i = 0; i < 110; i++) {
  44.     b[0] = i;
  45.     printf("%d\n", apple_hash(b, 1));
  46.   }
  47. }
  48.