BSD 4_2 release
[unix-history] / usr / src / usr.bin / lint / hash.c
CommitLineData
49531380 1#ifndef lint
0f4556f1 2static char sccsid[] = "@(#)hash.c 1.1 (Berkeley) 3/29/83";
49531380
EW
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
15hashstr(s)
16#else
17hashstr(s, n)
18register n;
19#endif
20register 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}