Skip to content

Instantly share code, notes, and snippets.

@grantjbutler
Created January 27, 2017 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantjbutler/d566019d7198643d2782346e6ee66b1c to your computer and use it in GitHub Desktop.
Save grantjbutler/d566019d7198643d2782346e6ee66b1c to your computer and use it in GitHub Desktop.
// Generated using Sourcery 0.5.3 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
// swiftlint:disable file_length
fileprivate func combineHashes(_ hashes: [Int]) -> Int {
var combinedHash = 5381
for itemHash in hashes {
combinedHash = ((combinedHash << 5) &+ combinedHash) &+ itemHash
}
return combinedHash
}
// MARK: - AutoHashable for classes, protocols, structs
// MARK: - SimpleStruct AutoHashable
extension SimpleStruct: Hashable {
internal var hashValue: Int {
return combineHashes([thing.hashValue, 0])
}
}
// MARK: - AutoHashable for Enums
// MARK: - AssociatedValueEnum AutoHashable
extension AssociatedValueEnum: Hashable {
internal var hashValue: Int {
switch self {
case .one:
return 1.hashValue
case .two(let data):
return combineHashes([2, data.0.hashValue, data.1.hashValue])
case .three(let data):
return combineHashes([3, data.hashValue])
}
}
}
// MARK: - SimpleEnum AutoHashable
extension SimpleEnum: Hashable {
internal var hashValue: Int {
switch self {
case .one:
return 1.hashValue
case .two:
return 2.hashValue
case .three:
return 3.hashValue
}
}
}
// MARK: -
// Generated using Sourcery 0.5.3 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
// swiftlint:disable file_length
fileprivate func combineHashes(hashes: [Int]) -> Int {
var combinedHash = 5381
for itemHash in hashes {
combinedHash = ((combinedHash << 5) &+ combinedHash) &+ itemHash
}
return combinedHash
}
// MARK: - AutoHashable for classes, protocols, structs
// MARK: - SimpleStruct AutoHashable
extension SimpleStruct: Hashable {
internal var hashValue: Int {
return combineHashes(thing.hashValue, 0)
}
}
// MARK: - AutoHashable for Enums
// MARK: - AssociatedValueEnum AutoHashable
extension AssociatedValueEnum: Hashable {
internal var hashValue: Int {
switch self {
case .one:
return combineHashes()
case .two(let data):
return combineHashes(data.0.hashValue, data.1.hashValue)
case .three(let data):
return data.hashValue
}
}
}
// MARK: - SimpleEnum AutoHashable
extension SimpleEnum: Hashable {
internal var hashValue: Int {
switch self {
case .one:
return combineHashes()
case .two:
return combineHashes()
case .three:
return combineHashes()
}
}
}
// MARK: -
protocol AutoHashable { }
struct SimpleStruct: AutoHashable {
let thing: String
}
enum SimpleEnum: AutoHashable {
case one
case two
case three
}
enum AssociatedValueEnum: AutoHashable {
case one
case two(Int, Int)
case three(() -> Void)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment