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