I'm struggling to efficiently store information in pairs:
For instance I have two structs that represent (x,y) coords that i wish to calculate and store the distance between. Currently I am store all the values twice in a
unordered_map<pair<Struct1*,Struct2*,double>
My problem is that when searching I want the result <Struct1*,Struct2*>
to turn up the same value as <Struct2*,Struct1*>
that way I do not have to store information twice. I've thought about using a multimap but I think that std::hash<pair<pointer1,pointer2>>
will hash to the same value as pair<pointer2,pointer1>
any suggestions on how to do this?
Edit:
I've thought about doing a customer hash that simply adds the two hash values of the pointers using std::hash like:
size_t operator() (const pair<Location*,Location*> &key)
{
hash<Location*> hash1;
return (hash1(key.first) + hash1(key.second));
}
this works when I call find(struct1,struct2), however not when i call find(struct2,struct1)