home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / diskutil / fdf / elib / hashpjw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-05  |  566 b   |  33 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #include "elib.h"
  6.  
  7.  
  8.  
  9. /*
  10.  * hashpjw
  11.  *
  12.  * hash function.  Used in P. J. Weinberger's portable C compiler and
  13.  * gotten from page 436 of the Dragon book on compilers (Compilers: Principles,
  14.  * Techniques and Tools, by Aho, Sethi and Ullman.  Copyright (c) 1986 by
  15.  * Bell Telephone Laboratories).
  16.  */
  17. int hashpjw(char *s)
  18.  
  19. {
  20.     char *p;
  21.     unsigned long h = 0, g;
  22.  
  23.     for (p = s; *p != EOS; p++) {
  24.         h = (h << 4) + (*p);
  25.         if (g = h&0xf0000000) {
  26.             h ^= (g >> 24);
  27.             h ^= g;
  28.         }
  29.     }
  30.  
  31.     return h % HASH_TAB_SIZE;
  32. }
  33.