/* NAME:
 *	hash - simple hash routine
 *
 * SYNOPSIS:
 *      long	Hash(const char *s)
 *
 * DESCRIPTION:
 *      Provide a convenient numeric representation of a string.  We use at
 *      most sizeof (long) chars from the string.  If a set of data deliver
 *      non-unique hash values then the hash() algorithm must be updated. The
 *      current one should do for now.
 *
 * AUTHOR:
 *	Simon J. Gerraty <sjg@quick.com.au>
 */
/*
 *      @(#)Copyright (c) 1994, Simon J. Gerraty.
 *      
 *      This is free software.  It comes with NO WARRANTY.
 *      Permission to use, modify and distribute this source code 
 *      is granted subject to the following conditions.
 *      1/ that the above copyright notice and this notice 
 *      are preserved in all copies and that due credit be given 
 *      to the author.  
 *      2/ that any changes to this code are clearly commented 
 *      as such so that the author does not get blamed for bugs 
 *      other than his own.
 *      
 *      Please send copies of changes and bug-fixes to:
 *      sjg@quick.com.au
 */

#ifndef lint
static char RCSid[] = "$Id: hash.c,v 1.2 1997/02/08 07:10:50 sjg Exp $";
#endif

#include <ctype.h>
#include <sys/cdefs.h>

long
HashN(s, n)
	const char *s;
	int n;
{
	register int i;
	long val = 0;

	for (i = 0; s[i] && i < n; i++)
	{
		val += s[i] * (s[i] << i);
	}
	val &= 0x7fffff;
	return val;
}

long
Hash(s)
	const char *s;
{
	return HashN(s, 31);
}
