public protocol Hashable : _Hashable, Equatable {
var hashValue: Int { get }
}
从源码可以看到 Hashable继承了 _Hashable Equatable
同时继承 Equatable 应该是为了确定 hashValue 和 equalTo方法同时得到了重新实现
extension _RuntimeHelpers {
@_silgen_name("swift_stdlib_Hashable_isEqual_indirect")
public static func Hashable_isEqual_indirect( _ lhs: UnsafePointer, _ rhs: UnsafePointer) -> Bool {
return lhs.pointee == rhs.pointee
}
@_silgen_name("swift_stdlib_Hashable_hashValue_indirect")
public static func Hashable_hashValue_indirect( _ value: UnsafePointer) -> Int {
return value.pointee.hashValue
}
}
以上是默认的实现 equalTo 默认比较之争 hashValue默认返回指针的hash值