Skip to content

Commit a0bfd80

Browse files
committed
Merge pull request #44 from siyusong/fix-comparison-hashvalue
Do not use hashValue in comparison
2 parents a4a5698 + 77bbf39 commit a0bfd80

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

Sources/EventType.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,22 @@ public func == <E: EventType>(lhs: Event<E>, rhs: Event<E>) -> Bool
6363

6464
public func == <E: EventType>(lhs: Event<E>, rhs: E) -> Bool
6565
{
66-
return lhs.hashValue == rhs.hashValue
66+
switch lhs {
67+
case .Some(let x):
68+
return x == rhs
69+
case .Any:
70+
return false
71+
}
6772
}
6873

6974
public func == <E: EventType>(lhs: E, rhs: Event<E>) -> Bool
7075
{
71-
return lhs.hashValue == rhs.hashValue
76+
switch rhs {
77+
case .Some(let x):
78+
return x == lhs
79+
case .Any:
80+
return false
81+
}
7282
}
7383

7484
// MARK: NoEvent

Sources/StateType.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,34 @@ extension State: RawRepresentable
5151

5252
public func == <S: StateType>(lhs: State<S>, rhs: State<S>) -> Bool
5353
{
54-
return lhs.hashValue == rhs.hashValue
54+
switch (lhs, rhs) {
55+
case let (.Some(x1), .Some(x2)) where x1 == x2:
56+
return true
57+
case (.Any, .Any):
58+
return true
59+
default:
60+
return false
61+
}
5562
}
5663

5764
public func == <S: StateType>(lhs: State<S>, rhs: S) -> Bool
5865
{
59-
return lhs.hashValue == rhs.hashValue
66+
switch lhs {
67+
case .Some(let x):
68+
return x == rhs
69+
case .Any:
70+
return false
71+
}
6072
}
6173

6274
public func == <S: StateType>(lhs: S, rhs: State<S>) -> Bool
6375
{
64-
return lhs.hashValue == rhs.hashValue
76+
switch rhs {
77+
case .Some(let x):
78+
return x == lhs
79+
case .Any:
80+
return false
81+
}
6582
}
6683

6784
// MARK: Private

Sources/Transition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public struct Transition<S: StateType>: Hashable
4545
// for Transition Equatable
4646
public func == <S: StateType>(left: Transition<S>, right: Transition<S>) -> Bool
4747
{
48-
return left.hashValue == right.hashValue
48+
return left.fromState == right.fromState && left.toState == right.toState
4949
}
5050

5151
//--------------------------------------------------

0 commit comments

Comments
 (0)