我正在使用unordered_set來實現散列表。我無法弄清楚如何使用find函數。運行此代碼時,我不斷收到seg錯誤。我知道它是因爲find()沒有找到一個元素,但它應該。我的問題是我如何正確使用我提供的自定義散列函數的查找?unordered_set中的散列函數
unordered_set<Play*, Play::Hash> hashedData
unordered_set<Play*>::iterator got;
for (int i = 0; i < 10; ++i) {
got = hashedData.find(data[i]);
cout << (*got)->getSummary() << endl << endl;
}
數據僅僅是一個
vector<Play*>
和我的散列函數看起來像這樣
struct Hash {
size_t operator()(Play* const &x) const {
size_t t = 0;
static int hash = 0;
string u = x->getOffense();
string v = x->getDefence();
string w = x->getPlayDesc();
t = u.length() + v.length() + w.length();
t += hash;
++hash;
return t;
}
};