shithub: asif

ref: c7839bab2449aedd1339b5fee09ed15a13f930bf
dir: /hash/djb.c/

View raw version
/* Daniel J. Bernstein hashing algorithm, retrieved from:
 * http://www.partow.net/programming/hashfunctions/index.html */

unsigned int djbhash(const char* str, unsigned int length)
{
	unsigned int hash	= 5381;
	unsigned int i		= 0;

	for (i = 0; i < length; ++str, ++i)
	{
		hash = ((hash << 5) + hash) + (*str);
	}

	return hash;
}