SipHashable
public protocol SipHashable: Hashable
A variant of Hashable that makes it simpler to generate good hash values.
Instead of hashValue, you need to implement addHashes, adding
data that should contribute to the hash to the supplied hasher.
The hasher takes care of blending the supplied data together.
Example implementation:
struct Book: SipHashable {
var title: String
var pageCount: Int
func appendHashes(to hasher: inout SipHasher) {
hasher.append(title)
hasher.append(pageCount)
}
static func ==(left: Book, right: Book) -> Bool {
return left.title == right.title && left.pageCount == right.pageCount
}
}
-
Add components of
selfthat should contribute to hashing tohash.Declaration
Swift
func appendHashes(to hasher: inout SipHasher)
-
hashValueExtension methodThe hash value, calculated using
addHashes.Hash values are not guaranteed to be equal across different executions of your program. Do not save hash values to use during a future execution.
Declaration
Swift
public var hashValue: Int
View on GitHub
Install in Dash
SipHashable Protocol Reference