hash is necessary

This commit is contained in:
Quentin Jin 2019-04-06 19:06:48 +08:00
parent 6df23ae87e
commit ffd0fccb13
1 changed files with 7 additions and 2 deletions

View File

@ -5,17 +5,22 @@ private let _default = TaskCenter()
extension TaskCenter { extension TaskCenter {
private class TaskBox: Hashable { private class TaskBox: Hashable {
weak var task: Task? weak var task: Task?
// Used to find slot in dictionary/set
let hash: Int
init(_ task: Task) { init(_ task: Task) {
self.task = task self.task = task
self.hash = task.hashValue
} }
func hash(into hasher: inout Hasher) { func hash(into hasher: inout Hasher) {
hasher.combine(task) hasher.combine(hash)
} }
// Used to find task in a slot in dictionary/set
static func == (lhs: TaskBox, rhs: TaskBox) -> Bool { static func == (lhs: TaskBox, rhs: TaskBox) -> Bool {
return lhs.task == rhs.task return lhs.task == rhs.task
} }