Created
January 27, 2017 20:32
-
-
Save grantjbutler/d566019d7198643d2782346e6ee66b1c 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
// 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: - |
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
// 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: - |
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
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