BKDR Hash

BKDR is a simple hash function using a strange set of possible seeds which all constitute a pattern of 31....31...31 etc.



									unsigned int BKDRHash(char* str, unsigned int length) {
	unsigned int seed = 131;
	unsigned int hash = 0;
	unsigned int i = 0;

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

	return hash;
}
								


Example

									char* data = "jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^";
unsigned int value = BKDRHash(data, 40);
								


Output

									3255416723