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