Reputation: 2001
Looking through the hashable protocol, and to make a matrix location struct to conform:
struct MatrixLocation: Hashable {
let row: Int
let col: Int
var hashValue: Int { return row.hashValue ^ col.hashValue }
}
The hash value has the ^
operator.
What is the ^
operator in Swift?
Upvotes: 1
Views: 190
Reputation: 17050
^
is the XOR operator in Swift. Basically it compares the bits of the two operands, and for each bit, it sets the corresponding bit of the result to 1
if one of the two input bits is 1
, but the other is 0
. If both bits are 1
or both bits are 0
, it sets the bit in the result to 0
.
So if you have 0x49 ^ 0x13
, that would be 01001001 XOR 00010011, which would come out to 01011010, or 0x5a
.
Upvotes: 2