home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / rxhtable.c < prev    next >
C/C++ Source or Header  |  1998-06-21  |  1KB  |  73 lines

  1. /** Rxhtable.c
  2.   *
  3.   *   DESCRIPTION:
  4.   *   ===========
  5.   *
  6.   * This function finds the index associated with the function
  7.   * name given in the argument string.
  8.   *                                            
  9.   * It uses a hashing function that was found using the program
  10.   * 'hash' by W.G.J. Langeveld.
  11.   *
  12.   *   SYNOPSIS:
  13.   *   =========
  14.   *
  15.   * index = rxhtable_index(name)
  16.   *
  17.   * int index the index of the function, -1 if not found.
  18.   * char *name name of function.
  19.   *
  20.   *   AUTHOR/DATE:  W.G.J. Langeveld, November 1987.
  21.   *   ============
  22.   *
  23.   *    CURRENT VERSION:
  24.   *
  25.   *    This version has been converted to SAS C 6.5 format. It has been modified
  26.   *    for modern definition sequences for ANSI compilation. This no longer works
  27.   *    with OS versions prior to 2.04.
  28.   *
  29.   *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  30.   *   ============
  31.   *
  32.   **/
  33.  
  34. #include <string.h>
  35. #include <ctype.h>
  36.  
  37.  
  38.  
  39. static int hash_table[] = 
  40. {
  41.     -1,  -1,   8,  -1,  17,  -1,  18,   7,  -1,   9,
  42.     6,  15,  10,  -1,   0,  -1,  11,  -1,  -1,  -1,
  43.     5,  12,  16,  14,  19,  13,  -1,  -1,  -1,   4,
  44.     1,   2,  -1,  -1,   3,  -1,  -1,  
  45. };
  46.  
  47.  
  48. int rxhtable_index(char *);
  49. static int hash(unsigned char *);
  50.  
  51.  
  52. int rxhtable_index( char *s )
  53. {
  54.     return(hash_table[hash(s)]);
  55. }
  56.  
  57.  
  58. static int hash( unsigned char *s )
  59. {
  60.     register int res;
  61.     register unsigned char *sp;
  62.     register unsigned int c;
  63.     
  64.     res = strlen(s);
  65.     
  66.     for (sp = s; *sp; sp++ ) 
  67.     {
  68.         c = toupper(*sp);
  69.         res = ((res * 23 + c ) & 0x7ff);
  70.     }
  71.     return(res % 37);
  72. }
  73.