Created
August 6, 2017 22:19
-
-
Save thelbane/dfc94e6a8a37ae0ba004f6c2914e30d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| enum ColumnSelection<Item> where Item: Hashable { | |
| case viewAll | |
| case selection(item: Item) | |
| } | |
| extension ColumnSelection: Hashable { | |
| // MARK: - Hashable | |
| var hashValue: Int { | |
| switch self { | |
| case .viewAll: return 0 | |
| case .selection(let item): return item.hashValue + 1 | |
| } | |
| } | |
| // MARK: - Equatable | |
| static func ==(lhs: ColumnSelection<Item>, rhs: ColumnSelection<Item>) -> Bool { | |
| return lhs.hashValue == rhs.hashValue | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gross. I thought I was being clever with the
item.hashValue + 1in line 17 to avoid a hash collision with.viewAll. However,hashValueis anInt(notUInt) therefore I could still collide with a hash value of -1.