Skip to content

Commit 40b6f55

Browse files
committed
Improved Hashing implementation
1 parent c281e73 commit 40b6f55

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/NaiveDate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct NaiveDate: Equatable, Hashable, Comparable, LosslessStringConverti
2121
// MARK: Equatable, Hashable, Comparable
2222

2323
public var hashValue: Int {
24-
return year ^ month ^ day
24+
return year << 10 ^ month << 5 ^ day
2525
}
2626

2727
public static func ==(lhs: NaiveDate, rhs: NaiveDate) -> Bool {
@@ -78,7 +78,7 @@ public struct NaiveTime: Equatable, Hashable, Comparable, LosslessStringConverti
7878
}
7979

8080
public var hashValue: Int {
81-
return hour ^ minute ^ second
81+
return hour << 10 ^ minute << 5 ^ second
8282
}
8383

8484
/// Initializes a naive time with a given time interval. E.g.
@@ -160,7 +160,7 @@ public struct NaiveDateTime: Equatable, Hashable, Comparable, LosslessStringConv
160160
// MARK: Equatable, Hashable, Comparable
161161

162162
public var hashValue: Int {
163-
return date.hashValue ^ time.hashValue
163+
return date.hashValue << 10 ^ time.hashValue
164164
}
165165

166166
public static func ==(lhs: NaiveDateTime, rhs: NaiveDateTime) -> Bool {

0 commit comments

Comments
 (0)