File:  [CSRG BSD Unix] / 43BSD / usr.bin / lint / hash.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:54 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43
BSD 4.3

#ifndef lint
static char sccsid[] = "@(#)hash.c	1.1	(Berkeley)	3/29/83";
#endif lint

/*
 * Hash function.  Used for pass 2 symbol table and string table,
 * and structure/union name passing between passes.
 * The hash function is a modular hash of
 * the sum of the characters with the sum
 * rotated before each successive character
 * is added.
 * Only 15 bits are used.
 */
#ifdef FLEXNAMES
hashstr(s)
#else
hashstr(s, n)
register n;
#endif
register char *s;
{
	register i;

	i = 0;
#ifdef FLEXNAMES
	while (*s)
#else
	while (n-- > 0 && *s)
#endif
		i = (i << 3 | i >> 12 & 0x07) + *s++;
	return i & 0x7fff;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.