I'm attempting to create a simple generic node class that conforms to the Comparable protocol so that I can easily compare nodes without accessing their key. When I attempt to write the < and == functions, however, the compiler doesn't seem to like it. The < and == functions expect a type when defining the Node parameters. This was simple in Java where you defined equality and < internally to the class. Swift asks for it globally. Any thoughts ?
Example:
func < (lhs:Node<E:Comparable>, rhs:Node<E:Comparable>) -> Bool {
return lhs.key < rhs.key
}
func == (lhs:Node<E:Comparable>, rhs:Node<E:Comparable>) -> Bool {
return lhs.key == rhs.key
}
class Node<D:Comparable>: Comparable {
var key: D!
var next:Node?
var prev:Node?
init( key:D ) {
self.key = key
}
}