I am creating a HashTable class via a template. Although, I can't seem to find a way to keep the template nature when dealing with strings or any numerical datatype (more-so just integers). This is the code that I have that works as long as HashKey is of type string.
template<typename HashKey>
size_t HashTable<HashKey>::myhash(const HashKey & x) const
{
unsigned int hashVal = 0;
for (unsigned int i = 0; i < x; i++)
hashVal = (hashVal << 5) ^ x[i] ^ hashVal;
return hashVal % hashTable.size();
};
Would there be any way to allow it to work using something like
unsigned int hashVal = 0;
hashVal = (hashVal << 5) ^ x ^ hashVal;
return hashVal % hashTable.size();
Any help here?