zoukankan      html  css  js  c++  java
  • swift Hashable Equatable

    /// You can use any type that conforms to the `Hashable` protocol in a set or

    /// as a dictionary key. Many types in the standard library conform to

    /// `Hashable`: Strings, integers, floating-point and Boolean values, and even

    /// sets provide a hash value by default. Your own custom types can be

    /// hashable as well.

    public protocol Hashable : Equatable {

        public var hashValue: Int { get }

    }

    /// A hash value, provided by a type's `hashValue` property, is an integer that

    /// is the same for any two instances that compare equally. That is, for two

    /// instances `a` and `b` of the same type, if `a == b`, then

    /// `a.hashValue == b.hashValue`. The reverse is not true: Two instances with

    /// equal hash values are not necessarily equal to each other.

    public protocol Equatable {

        public static func == (lhs: Self, rhs: Self) -> Bool

    }

    extension Equatable {

        public static func != (lhs: Self, rhs: Self) -> Bool

    }

    public func === (lhs: Swift.AnyObject?, rhs: Swift.AnyObject?) -> Bool

    public func !== (lhs: Swift.AnyObject?, rhs: Swift.AnyObject?) -> Bool

    ///     let a = IntegerRef(100)

    ///     let b = IntegerRef(100)

    ///

    ///     print(a == a, a == b, separator: ", ")

    ///     // Prints "true, true"

    ///     class StreetAddress {

    ///         let number: String

    ///         let street: String

    ///         let unit: String?

    ///

    ///         init(_ number: String, _ street: String, unit: String? = nil) {

    ///             self.number = number

    ///             self.street = street

    ///             self.unit = unit

    ///         }

    ///     }

    ///     extension StreetAddress: Equatable {

    ///         static func == (lhs: StreetAddress, rhs: StreetAddress) -> Bool {

    ///             return

    ///                 lhs.number == rhs.number &&

    ///                 lhs.street == rhs.street &&

    ///                 lhs.unit == rhs.unit

    ///         }

    ///     }

    public protocol Comparable : Equatable{

    public static func < (lhs: Self, rhs: Self) -> Bool

    }

  • 相关阅读:
    MapReduce编程:数字排序
    MapReduce编程:平均成绩
    线性回归(linear regression)
    pip安装第三方库镜像源选择
    malloc/free 和 new/delete
    strcpy函数解析
    牛客-数据库SQL实战
    Numpy学习
    花式饺子
    MapReduce编程:单词去重
  • 原文地址:https://www.cnblogs.com/feng9exe/p/9647193.html
Copyright © 2011-2022 走看看