For strings of 10-50 characters:
double hash(const std::string & str)
{
double result = 0;
int n=str.length();
for(int i=0;i<n;i++)
{
result += (str[i] - '@')*pow(256.0,i);
}
return result;
}
can this be used in a production code?
- increasing total throughput of hashing when used with std::hash by ILP
- correctness/uniqueness
- scalability
new version by comments:
double hash(const std::string & str)
{
double result = 0;
int n=str.length();
// maybe using multiple adders to do concurrently multiple chars
// since they are not dependent
for(int i=0;i<n;i++)
{
result += lookupCharDoubleType[str[i]]*lookupPow[i];
}
return result;
}
another version by another comment:
double hash(const std::string & str)
{
double result = 0;
int n=str.length();
for(int i=0;i<n;i++)
{
result = result * 256.0 + lookupCharDoubleType[str[i]];
}
return result;
}