title: Order-independent Hash Algorithm
body: <p>I am currently working on a collection library for my custom programming language. I already have several data types (Collection, List, Map, Set) and implementations for them (mutable and immutable), but what I was missing so far was <code>hashCode</code> and <code>equals</code>. While these are no problem for Lists as they are ordered collections, the play a special role for Sets and Maps. Two Sets are considered equal if they have the same size and the same elements, and the order in which the Sets maintain them should not make a difference in their equality. Because of the equals-hashCode-contract, the <code>hashCode</code> implementation also has to reflect this behavior, meaning that two sets with the same elements but different ordering should have the same hash code. (The same applies for Maps, which are technically a Set of Key-Value-Pairs)</p>
  
  <p><strong>Example</strong> (Pseudocode):</p>
  
  <pre><code>let set1: Set&lt;String&gt; = [ "a", "b", "c" ]
  let set2: Set&lt;String&gt; = [ "b", "c", "a" ]
  set1 == set2       // should return true
  set1.hashCode == set2.hashCode // should also return true
  </code></pre>
  
  <p>How would I implement a reasonably good hash algorithm for which the <code>hashCode</code>s in the above example return the same value?</p>