diff --git a/prototype/Doubt.xcodeproj/project.pbxproj b/prototype/Doubt.xcodeproj/project.pbxproj index 511c288da..b0eef2662 100644 --- a/prototype/Doubt.xcodeproj/project.pbxproj +++ b/prototype/Doubt.xcodeproj/project.pbxproj @@ -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 = ""; }; D4AAE53E1B5AE2D0004E581F /* StringLiteralConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringLiteralConvertible.swift; sourceTree = ""; }; D4AAE53F1B5AE2D0004E581F /* Syntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Syntax.swift; sourceTree = ""; }; - D4D7F3161BBB22E500AAB0C0 /* Hash.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Hash.swift; sourceTree = ""; }; D4DF96EC1BC46B630040F41F /* SES.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SES.swift; sourceTree = ""; }; D4DF96F01BC54C970040F41F /* Doubt.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = Doubt.modulemap; sourceTree = ""; }; 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 */, diff --git a/prototype/Doubt/Cofree.swift b/prototype/Doubt/Cofree.swift index cef83c83f..7785bb2b5 100644 --- a/prototype/Doubt/Cofree.swift +++ b/prototype/Doubt/Cofree.swift @@ -76,21 +76,6 @@ public func == (left: Cofree, right: Cofree Hash, leaf: A -> Hash) -> Hash { - return .Ordered([ annotation(extract), unwrap.hash(ifLeaf: leaf, ifRecur: { $0.hash(annotation: annotation, leaf: leaf) }) ]) - } -} - -extension Cofree where A: Hashable, B: Hashable { - public var hash: Hash { - return hash(annotation: Hash.init, leaf: Hash.init) - } -} - - // MARK: - JSON extension Cofree { diff --git a/prototype/Doubt/Free.swift b/prototype/Doubt/Free.swift index afb4238e9..cd8cbe510 100644 --- a/prototype/Doubt/Free.swift +++ b/prototype/Doubt/Free.swift @@ -144,22 +144,6 @@ public func == (left: Free, right: Free } -// MARK: - Hashing - -extension Free { - public func hash(ifPure ifPure: B -> Hash, ifRoll: A -> Hash) -> Hash { - return analysis(ifPure: ifPure, ifRoll: { $0.hash(ifLeaf: ifRoll, ifRecur: { $0.hash(ifPure: ifPure, ifRoll: ifRoll) }) }) - } -} - - -extension Free where A: Hashable, B: Hashable { - public var hash: Hash { - return hash(ifPure: Hash.init, ifRoll: Hash.init) - } -} - - // MARK: - JSON extension Free { diff --git a/prototype/Doubt/Hash.swift b/prototype/Doubt/Hash.swift deleted file mode 100644 index 35b38791a..000000000 --- a/prototype/Doubt/Hash.swift +++ /dev/null @@ -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(_ hashable: A) { - self = hashable.hash - } - - public init(_ 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) - } -} diff --git a/prototype/Doubt/Patch.swift b/prototype/Doubt/Patch.swift index f133a67d2..28bcb3914 100644 --- a/prototype/Doubt/Patch.swift +++ b/prototype/Doubt/Patch.swift @@ -53,18 +53,6 @@ extension Patch { } -// MARK: - Hashing - -extension Patch { - public func hash(param: A -> Hash) -> Hash { - return Hash.Ordered([ - state.before.map(param) ?? Hash.Empty, - state.after.map(param) ?? Hash.Empty - ]) - } -} - - // MARK: - JSON extension Patch { diff --git a/prototype/Doubt/Syntax.swift b/prototype/Doubt/Syntax.swift index 2a7c47924..71718537f 100644 --- a/prototype/Doubt/Syntax.swift +++ b/prototype/Doubt/Syntax.swift @@ -71,28 +71,6 @@ public func == (left: Syntax, right: Syntax Hash, ifRecur: Recur -> Hash) -> Hash { - switch self { - case let .Leaf(n): - return Hash("Leaf", ifLeaf(n)) - case let .Indexed(x): - return Hash("Indexed", .Ordered(x.map(ifRecur))) - case let .Keyed(d): - return Hash("Keyed", .Ordered(d.keys.sort().map { Hash($0, ifRecur(d[$0]!)) })) - } - } -} - -extension Syntax where Recur: Hashable, A: Hashable { - public var hash: Hash { - return hash(ifLeaf: Hash.init, ifRecur: Hash.init) - } -} - - // MARK: - JSON extension Syntax {