xref: /csrg-svn/old/pcc/lint/lpass1/hash.c (revision 32264)
111760Sedward #ifndef lint
2*32264Sbostic static char sccsid[] = "@(#)hash.c	1.2	(Berkeley)	09/28/87";
311760Sedward #endif lint
411760Sedward 
5*32264Sbostic #include "config.h"
6*32264Sbostic 
711760Sedward /*
811760Sedward  * Hash function.  Used for pass 2 symbol table and string table,
911760Sedward  * and structure/union name passing between passes.
1011760Sedward  * The hash function is a modular hash of
1111760Sedward  * the sum of the characters with the sum
1211760Sedward  * rotated before each successive character
1311760Sedward  * is added.
1411760Sedward  * Only 15 bits are used.
1511760Sedward  */
1611760Sedward #ifdef FLEXNAMES
hashstr(s)1711760Sedward hashstr(s)
1811760Sedward #else
1911760Sedward hashstr(s, n)
2011760Sedward register n;
2111760Sedward #endif
2211760Sedward register char *s;
2311760Sedward {
2411760Sedward 	register i;
2511760Sedward 
2611760Sedward 	i = 0;
2711760Sedward #ifdef FLEXNAMES
2811760Sedward 	while (*s)
2911760Sedward #else
3011760Sedward 	while (n-- > 0 && *s)
3111760Sedward #endif
3211760Sedward 		i = (i << 3 | i >> 12 & 0x07) + *s++;
3311760Sedward 	return i & 0x7fff;
3411760Sedward }
35