This is what I have so far:
struct pairhash {
public:
inline std::size_t operator()(const std::pair<int, int> &c) const
{
int x = c.first;
int y = c.second;
return ((x+y)*(x+y+1)/2 + y); // Cantor's enumeration of pairs
}
};
I need to use this a hash function so that I can place the pair of ints in an unordered_set like this:
std::unordered_set< std::pair<int, int>, pairhash> mySet;
EDIT: Forgot to get the coords from the pair. Updated the code. EDIT: Removed the template code - added it by mistake.
EDIT: Changed the function based on another similar answer on SO, related to Cantor's enumeration of pairs: hash function providing unique uint from an integer coordinate pair
EDIT: Collision free is not a requirement (Thanks Petr).