我为unrorderd_map定义了自己的哈希函数.但是我无法使用find函数在容器中搜索.我尝试使用散列函数中的print语句进行调试,并生成插入键/值时生成的相同散列值.如果有人可以指出错误,那就太好了.我在Windows上使用Eclipse IDE,我正在使用-std = c ++ 11进行编译
typedef struct tree node;
struct tree
{
int id;
node *left;
node *right;
};
class OwnHash
{
public:
std::size_t operator() (const node *c) const
{
cout << "Inside_OwnHash: " <<std::hash<int>()(c->id) + std::hash<node *>()(c->left) + std::hash<node *>()(c->right) << endl;
return std::hash<int>()(c->id) + std::hash<node *>()(c->left) + std::hash<node *>()(c->right);
}
};
int main()
{
std::unordered_map<node *,node *,OwnHash> ut;
node * one = new node;
one->id = -1;
one->left = nullptr;
one->right = nullptr;
ut.insert({one,one});
node * zero …Run Code Online (Sandbox Code Playgroud)