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.



									/*****Please include following header files*****/
// string
/***********************************************/

/*****Please use following namespaces*****/
// std
/*****************************************/

static unsigned int BKDRHash(string str) {
	unsigned int seed = 131;
	unsigned int hash = 0;
	unsigned int i = 0;
	unsigned int len = str.length();

	for (i = 0; i < len; i++)
	{
		hash = (hash * seed) + (str[i]);
	}

	return hash;
}
								


Example

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


Output

									3255416723