shithub: asif

ref: a0f5762d967c3c09e6d7303e238976c6c9835ed5
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;
}