1 #ifndef lint 2 static char sccsid[] = "@(#)hash.c 1.2 (Berkeley) 09/28/87"; 3 #endif lint 4 5 #include "config.h" 6 7 /* 8 * Hash function. Used for pass 2 symbol table and string table, 9 * and structure/union name passing between passes. 10 * The hash function is a modular hash of 11 * the sum of the characters with the sum 12 * rotated before each successive character 13 * is added. 14 * Only 15 bits are used. 15 */ 16 #ifdef FLEXNAMES 17 hashstr(s) 18 #else 19 hashstr(s, n) 20 register n; 21 #endif 22 register char *s; 23 { 24 register i; 25 26 i = 0; 27 #ifdef FLEXNAMES 28 while (*s) 29 #else 30 while (n-- > 0 && *s) 31 #endif 32 i = (i << 3 | i >> 12 & 0x07) + *s++; 33 return i & 0x7fff; 34 } 35