title: How does Set ensure equatability in Swift?
body: <p>I'm reading <a href="https://developer.apple.com/documentation/swift/set" rel="nofollow noreferrer">Set</a></p>
  <blockquote>
  <p>You use a set instead of an array when you need to test efficiently for membership and you aren’t concerned with the order of the elements in the collection, or when you need to ensure that each element appears only once in a collection.</p>
  </blockquote>
  <p>Basically <code>Set</code> ensures uniqueness, it has some methods and relies on <code>Hashable</code></p>
  <blockquote>
  <p>Use the contains(_:) method to test whether a set contains a specific element.</p>
  <p>Use the subtracting(_:) method to create a new set with the elements of a set that are not also in another set or sequence</p>
  </blockquote>
  <p>But 2 different objects can have the same <code>hashValue</code>, like in this post <a href="https://useyourloaf.com/blog/swift-hashable/" rel="nofollow noreferrer">Swift Hashable</a></p>
  <blockquote>
  <p>Do not assume that two instances of a type with the same hash value are equal. Depending on how we compute the hash value we can get collisions where two different instances share the same hash value. The Hashable protocol only needs the reverse - two equal instances have the same hash value.</p>
  </blockquote>
  <p>So what if 2 objects have the same <code>hashValue</code>, and <code>Set</code> only saves 1, then we have the problem?</p>