Skip to content

Instantly share code, notes, and snippets.

@natecook1000
Last active December 23, 2017 03:57
Show Gist options
  • Select an option

  • Save natecook1000/8d35ae66910e1f9de0d9c2b5a9650d10 to your computer and use it in GitHub Desktop.

Select an option

Save natecook1000/8d35ae66910e1f9de0d9c2b5a9650d10 to your computer and use it in GitHub Desktop.
// 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