Hashable and Set in Swift

Issue #122

From Set

You can create a set with any element type that conforms to the Hashable protocol. By default, most types in the standard library are hashable, including strings, numeric and Boolean types, enumeration cases without associated values, and even sets themselves.

From Hashable

The Hashable protocol inherits from the Equatable protocol, so you must also add an equal-to operator (==) function for your custom type.

1
2
3
4
5
6
7
8
public protocol Hashable : Equatable {

/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
public var hashValue: Int { get }
}

Read more

Comments