I'm practice building a hashtable that can accept different types using template
.
How do I implement hashFunction
not knowing the types at compile time?
template<class K, class V>
class HashTable {
public:
vector<vector<Bucket<K, V> > > table;
...
size_t hashFunction(const K &k) {
//can't implement without knowing the runtime types
}
}
I'm guessing I should do something similar like:
return hash<K>(k) % table.size();
Update:
Thanks for R Sahu's answer, now I know it's the Template Partial Specialization part that I wasn't clear of. See this question and this link for reference.