DJB Hash
DJB is a hash function algorithm.
/*****Please include following header files*****/
// string
/***********************************************/
/*****Please use following namespaces*****/
// std
/*****************************************/
static unsigned int DJBHash(string str) {
unsigned int len = str.length();
unsigned int hash = 5381;
unsigned int i = 0;
for (i = 0; i < len; i++)
{
hash = ((hash << 5) + hash) + (str[i]);
}
return hash;
}
Example
string data = "jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^";
unsigned int value = DJBHash(data);
Output
2562861588