mirror of
https://github.com/github/semantic.git
synced 2024-11-29 11:02:26 +03:00
Add unordered hashing.
This commit is contained in:
parent
cdd05ab556
commit
009920606b
@ -1,5 +1,6 @@
|
||||
public enum Hash: Hashable {
|
||||
case Ordered([Hash])
|
||||
case Unordered([Hash])
|
||||
case Label(String)
|
||||
case Raw(Int)
|
||||
|
||||
@ -38,6 +39,8 @@ public enum Hash: Hashable {
|
||||
hash ^= hash >> 11
|
||||
hash += hash << 15
|
||||
return hash
|
||||
case let .Unordered(s):
|
||||
return s.lazy.map { $0.hashValue }.reduce(0, combine: +)
|
||||
case let .Label(s):
|
||||
return s.hashValue
|
||||
case let .Raw(i):
|
||||
@ -50,6 +53,8 @@ public func == (left: Hash, right: Hash) -> Bool {
|
||||
switch (left, right) {
|
||||
case let (.Ordered(a), .Ordered(b)):
|
||||
return a == b
|
||||
case let (.Unordered(a), .Unordered(b)):
|
||||
return a == b
|
||||
case let (.Label(a), .Label(b)):
|
||||
return a == b
|
||||
case let (.Raw(a), .Raw(b)):
|
||||
|
Loading…
Reference in New Issue
Block a user