次のコード行から create hash 関数を呼び出そうとすると、no matching function for call というエラーが表示されます
myHash.create("5", "Data");
checkTest("testSimpleIntHash #1", "Data", myHash.retrieve("5"));
create が KeyValuePair クラスからキーを受け取り、メソッドがキーをハッシュし、そのバケットに移動して、キーと値のペアを挿入するという考え方です。文字列に出力していないため、このエラーが発生していると思います。しかし、create メソッドでキーと値のペアを文字列に正しく出力するための構文がわかりません。(私は を使用してstd::list
おり、私のKeyValuePair
クラスは適切に機能しています)
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;
}