When I try to call the create hash function from the following lines of code I receive the error no matching function for call
myHash.create("5", "Data");
checkTest("testSimpleIntHash #1", "Data", myHash.retrieve("5"));
The idea is that create receives the key from the KeyValuePair class and then the method would hash the key, go to that bucket, and then insert the key value pair. I believe I am receiving this error because I am not outputting to string. However, I can not figure out the syntax to properly output the key value pair to string with the create method. (I am using std::list
, and my KeyValuePair
class is functioning properly)
template<typename T> class HashTable
{
public:
static const unsigned int NUM_BUCKETS = 100000;
HashTable create(const string& key, const T& item)
{
int temp = hash(key);
arr[NUM_BUCKETS].push_back(KeyValuePair<T>(temp, item));
}
private:
int hash(const string& key) const;
//Make an array of linked lists of KeyValuePair objects.
list<KeyValuePair<T>> arr[NUM_BUCKETS];
};
template <typename T>
int HashTable<T>::hash(const string& key) const {
int temp = 0;
for (int i = key.length(); i >= 0; i--) {
temp = (13 * temp + key[i]) % NUM_BUCKETS;
}
return temp;
}