Provide hash(into:) functions where the default implementation might be doing too much work.

This commit is contained in:
Brent Simmons
2024-05-26 11:53:36 -07:00
parent 401050465e
commit e275367664
11 changed files with 78 additions and 5 deletions

View File

@@ -17,7 +17,7 @@ public struct KeyboardConstant {
public static let spaceKey = " ".keyboardIntegerValue
}
public extension String {
extension String {
var keyboardIntegerValue: Int? {
if isEmpty {
@@ -65,6 +65,12 @@ public extension String {
}
return nil
}
// MARK: - Hashable
nonisolated public func hash(into hasher: inout Hasher) {
hasher.combine(key)
}
}
public struct KeyboardKey: Hashable, Sendable {
@@ -143,5 +149,12 @@ public struct KeyboardKey: Hashable, Sendable {
self.init(integerValue: integerValue, shiftKeyDown: shiftKeyDown, optionKeyDown: optionKeyDown, commandKeyDown: commandKeyDown, controlKeyDown: controlKeyDown)
}
// MARK: - Hashable
public func hash(into hasher: inout Hasher) {
hasher.combine(integerValue)
}
}
#endif