title: Generating a unique Hashcode based on Doubles with several decimal places
body: <p>I have a custom object that we'll call "MyObject" It has three major properties called X,Y, and Z that determine whether it's unique or not. I have a HashSet containing 400,000 "MyObject"s in a HashSet. My original solution for generating a unique hashcode was simple and fast. </p>
  
  <pre><code>return Convert.ToInt32(X * 76 + Y * 100 + Z * 23);
  </code></pre>
  
  <p>However, the integer generated from this was not unique enough. With the current HashCode, these two points match, even though the Y is slightly different. </p>
  
  <p>X: 392598.200000000190 Y: 4935367.900000000400</p>
  
  <p>X: 392598.200000000190 Y: 4935367.900580000100</p>
  
  <p><strong>What I've tried:</strong></p>
  
  <pre><code>double value = (X * 101 + Y * 89 + Z * 56);
  return value.GetHashCode();
  </code></pre>
  
  <ul>
  <li>Extremely accurate, with 1 - 10,000 records, it only takes a few seconds to compute the differences. However, with 400,000 records, it bogs down hard. I let it run for 17 hours, and it still hadn't returned my results.</li>
  <li>Converting to a string, then getting hashcode of the string. Precise, but uselessly slow.</li>
  <li><p>Increasing the multipliers of X, Y and Z. The number generated becomes too large. I tried using the method used here: <a href="http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx</a> </p>
  
  <pre><code>return ((int)value ^ (int)(value &gt;&gt; 32));
  </code></pre></li>
  </ul>
  
  <p>However it doesn't allow for anymore integers. I also worry that even if I increase the size, it may becomes uselessly slow like my other solutions.</p>
  
  <p><strong>I can't do additional checks if it matches, since 390,000 of 400,000 records will likely match</strong> </p>
  
  <p>What is the best solution? Or is there a way to make my two already precise operations significantly faster? I was thinking about removing all zeros from the values after the decimal place until it meets a non-zero, and then using my original logic, ie (45.0002030 would become 45.2030)</p>