Last active
December 23, 2017 03:57
-
-
Save natecook1000/8d35ae66910e1f9de0d9c2b5a9650d10 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
| // Test for uniqueness of hash values within a custom Hashable type | |
| // Closer to 1.0 == fewer key collisions in a set or dictionary | |
| extension Set { | |
| public var hashQuality: Double { | |
| let hashCount = Set<Int>(map({ $0.hashValue })).count | |
| return Double(hashCount) / Double(count) | |
| } | |
| } | |
| extension Dictionary { | |
| public var hashQuality: Double { | |
| let hashCount = Set(keys.map({ $0.hashValue })).count | |
| return Double(hashCount) / Double(count) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment