我正在使用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;
}
};