title: Good hash function for a 2d index
body: <p>I have a struct called Point. Point is pretty simple:</p>
  
  <pre><code>struct Point
  {
      Row row;
      Column column;
  
      // some other code for addition and subtraction of points is there too
  }
  </code></pre>
  
  <p><code>Row</code> and <code>Column</code> are basically glorified <code>int</code>s, but I got sick of accidentally transposing the input arguments to functions and gave them each a wrapper class.</p>
  
  <p>Right now I use a <code>set</code> of points, but repeated lookups are really slowing things down. I want to switch to an <code>unordered_set</code>.</p>
  
  <p>So, I want to have an <code>unordered_set</code> of <code>Point</code>s. Typically this set might contain, for example, every point on a 80x24 terminal = 1920 points. I need a good hash function. I just came up with the following:</p>
  
  <pre><code>struct PointHash : public std::unary_function&lt;Point, std::size_t&gt;
  {
      result_type operator()(const argument_type&amp; val) const
      {
          return val.row.value() * 1000 + val.col.value();
      }
  };
  </code></pre>
  
  <p>However, I'm not sure that this is really a good hash function. I wanted something fast, since I need to do many lookups very quickly. Is there a better hash function I can use, or is this OK?</p>