mirror of
https://github.com/github/semantic.git
synced 2024-11-25 11:04:00 +03:00
Remove Hash.
This commit is contained in:
parent
77a32f9e8d
commit
48234b71c2
@ -36,7 +36,6 @@
|
||||
D4AAE5471B5AE2D0004E581F /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53C1B5AE2D0004E581F /* Optional.swift */; };
|
||||
D4AAE5491B5AE2D0004E581F /* StringLiteralConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */; };
|
||||
D4AAE54A1B5AE2D0004E581F /* Syntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AAE53F1B5AE2D0004E581F /* Syntax.swift */; };
|
||||
D4D7F3171BBB22E500AAB0C0 /* Hash.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4D7F3161BBB22E500AAB0C0 /* Hash.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
D4DF96ED1BC46B630040F41F /* SES.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4DF96EC1BC46B630040F41F /* SES.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
D4DF970A1BC5DF800040F41F /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4DF97091BC5DF800040F41F /* main.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
D4DF970C1BC5DF9E0040F41F /* BoundsCheckedArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = D435B7521BB31BBC000902F6 /* BoundsCheckedArray.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
@ -79,7 +78,6 @@
|
||||
D4AAE53C1B5AE2D0004E581F /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = "<group>"; };
|
||||
D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringLiteralConvertible.swift; sourceTree = "<group>"; };
|
||||
D4AAE53F1B5AE2D0004E581F /* Syntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Syntax.swift; sourceTree = "<group>"; };
|
||||
D4D7F3161BBB22E500AAB0C0 /* Hash.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Hash.swift; sourceTree = "<group>"; };
|
||||
D4DF96EC1BC46B630040F41F /* SES.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SES.swift; sourceTree = "<group>"; };
|
||||
D4DF96F01BC54C970040F41F /* Doubt.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = Doubt.modulemap; sourceTree = "<group>"; };
|
||||
D4DF96FB1BC5DF050040F41F /* doubt-json.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "doubt-json.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@ -157,7 +155,6 @@
|
||||
D4413FEE1BB06D4C00E3C3C1 /* Dictionary.swift */,
|
||||
D4413FF01BB08FDC00E3C3C1 /* JSON.swift */,
|
||||
D40B89C31BC319070078E098 /* Matrix.swift */,
|
||||
D4D7F3161BBB22E500AAB0C0 /* Hash.swift */,
|
||||
D49FCBC31BBEF98E00C5E9C3 /* Free.swift */,
|
||||
D42F097B1BCE914A00B95610 /* Cofree.swift */,
|
||||
D49FCBC51BBF214300C5E9C3 /* Patch.swift */,
|
||||
@ -340,7 +337,6 @@
|
||||
files = (
|
||||
D4AAE5471B5AE2D0004E581F /* Optional.swift in Sources */,
|
||||
D4413FEF1BB06D4C00E3C3C1 /* Dictionary.swift in Sources */,
|
||||
D4D7F3171BBB22E500AAB0C0 /* Hash.swift in Sources */,
|
||||
D42F097E1BCEAEDA00B95610 /* Operation.swift in Sources */,
|
||||
D4DF96ED1BC46B630040F41F /* SES.swift in Sources */,
|
||||
D42F09801BCECB7900B95610 /* TermType.swift in Sources */,
|
||||
|
@ -1,108 +0,0 @@
|
||||
/// An algebraic representation of a non-cryptographic hash.
|
||||
public enum Hash: AlgebraicHashable {
|
||||
/// An ordered sequence of sub-hashes to mix.
|
||||
case Ordered([Hash])
|
||||
|
||||
/// An unordered collection of sub-hashes to mix. These will be mixed with an associative, commutative operation.
|
||||
case Unordered([Hash])
|
||||
|
||||
/// A label, e.g. for an enum case or a dictionary key.
|
||||
case Label(String)
|
||||
|
||||
/// The embedding of a raw hash value into an algebraic hash.
|
||||
case Raw(Int)
|
||||
|
||||
/// The empty hash.
|
||||
///
|
||||
/// This is the right and left unit for Unordered.
|
||||
case Empty
|
||||
|
||||
public init(_ label: String, _ hashes: Hash...) {
|
||||
self = .Ordered([ Hash(label) ] + hashes)
|
||||
}
|
||||
|
||||
public init(_ string: String) {
|
||||
self = .Label(string)
|
||||
}
|
||||
|
||||
public init(_ raw: Int) {
|
||||
self = .Raw(raw)
|
||||
}
|
||||
|
||||
public init<A: AlgebraicHashable>(_ hashable: A) {
|
||||
self = hashable.hash
|
||||
}
|
||||
|
||||
public init<A: Hashable>(_ hashable: A) {
|
||||
self = .Raw(hashable.hashValue)
|
||||
}
|
||||
|
||||
|
||||
public var hash: Hash {
|
||||
return self
|
||||
}
|
||||
|
||||
public var hashValue: Int {
|
||||
switch self {
|
||||
case let .Ordered(s):
|
||||
// Bob Jenkins’ one-at-a-time hash: https://en.wikipedia.org/wiki/Jenkins_hash_function
|
||||
var hash = 0
|
||||
for each in s {
|
||||
hash += each.hashValue
|
||||
hash += hash << 10
|
||||
hash ^= hash >> 6
|
||||
}
|
||||
hash += hash << 3
|
||||
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):
|
||||
return i.hashValue
|
||||
case .Empty:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)):
|
||||
return a == b
|
||||
case (.Empty, .Empty):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public protocol AlgebraicHashable: Hashable {
|
||||
var hash: Hash { get }
|
||||
}
|
||||
|
||||
extension AlgebraicHashable {
|
||||
public var hashValue: Int {
|
||||
return hash.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
extension RawRepresentable where RawValue: Hashable {
|
||||
public var hash: Hash {
|
||||
return Hash(rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
extension RawRepresentable where RawValue: AlgebraicHashable {
|
||||
public var hash: Hash {
|
||||
return Hash(rawValue)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user