I am trying to write an implementation for a hash map, I am not allowed to use anything from stdlib except iostream, string and cassert.
It should be general, so the values that fill the buckets can be of any type. I need templates for this, but I just can’t pass the hash function. This will be the header file:
template<typename Value, typename hashFunction>
class hashTable{
public:
hashTable(int size){
}
define(Value v){
loads value in Vector[hashFunction(v)];
}
...
private:
Vector with all the elements
}
Note. I don’t think I need key templates, do I?
I cannot define a hash function inside my class because I would have to create one that works with all types (string from int, int to int, double to int, etc.). Therefore, I assume that the only solution is to pass the function as an argument in my main one. That would be the main thing.
int hashF(int v){return v}
int main(){
hashTable<int,int,hashF> table(5);
}
, g++ " , hashF". , , , . ?