Algorithmic-Problems
Algorithmic-Problems copied to clipboard
It seems you can use NSHashTable instead of Set for LinkedLists/LoopDetection/Loop.swift
func hasLoopNodeHash() -> Node? {
var set = Set<Node>() // **Right here**
var temp: Node? = self
while let t = temp {
if set.contains(t) {
return t
} else {
set.insert(t)
}
temp = temp?.next
}
return nil
}
because Its members may use pointer identity for equality and hashing. So, you don't have to implement Comparable methods like:
public static func ==(lhs: Node, rhs: Node) -> Bool {
return lhs === rhs
}
var hashValue: Int {
return ObjectIdentifier(self).hashValue
}