我需要在我的应用程序中实现一组集合.将QSet与自定义类一起使用需要提供一个qHash()函数和一个operator==.
代码如下:
class Custom{
int x;
int y;
//some other irrelevant here
}
inline uint qHash(Custom* c){
return (qHash(c->x) ^ qHash(c->y));
}
bool operator==(Custom &c1, Custom &c2){
return ((c1.x==c2.x) && (c1.y == c2.y));
}
//now I can use: QSet<Custom*>
Run Code Online (Sandbox Code Playgroud)
我该如何实现qHash(QSet<Custom*>),能够使用QSet< QSet<SomeClass*> >?
编辑:
附加问题:在我的应用程序中,"集合集"最多可包含15000套.每个子集最多25个Custom类指针.如何保证qHash(QSet<Custom*>)足够独特?