1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

Merge branch 'master' into patch-costs-are-proportional-to-the-size-of-their-trees

This commit is contained in:
Rob Rix 2015-10-15 09:48:15 -04:00
commit dfa34aa13c
8 changed files with 0 additions and 293 deletions

View File

@ -27,8 +27,6 @@
D432D4711BA9AC0B00F3FABC /* SESTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D432D4701BA9AC0B00F3FABC /* SESTests.swift */; };
D4413FEF1BB06D4C00E3C3C1 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4413FEE1BB06D4C00E3C3C1 /* Dictionary.swift */; };
D4413FF11BB08FDC00E3C3C1 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4413FF01BB08FDC00E3C3C1 /* JSON.swift */; };
D45A36C91BBC667D00BE3DDE /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = D45A36C81BBC667D00BE3DDE /* Category.swift */; settings = {ASSET_TAGS = (); }; };
D45A36CD1BBC75DF00BE3DDE /* Info.swift in Sources */ = {isa = PBXBuildFile; fileRef = D45A36CC1BBC75DF00BE3DDE /* Info.swift */; settings = {ASSET_TAGS = (); }; };
D49FCBC41BBEF98E00C5E9C3 /* Free.swift in Sources */ = {isa = PBXBuildFile; fileRef = D49FCBC31BBEF98E00C5E9C3 /* Free.swift */; settings = {ASSET_TAGS = (); }; };
D49FCBC61BBF214300C5E9C3 /* Patch.swift in Sources */ = {isa = PBXBuildFile; fileRef = D49FCBC51BBF214300C5E9C3 /* Patch.swift */; settings = {ASSET_TAGS = (); }; };
D49FCBC81BBF2C4300C5E9C3 /* Algorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = D49FCBC71BBF2C4300C5E9C3 /* Algorithm.swift */; settings = {ASSET_TAGS = (); }; };
@ -38,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 = (); }; };
@ -69,8 +66,6 @@
D435B7521BB31BBC000902F6 /* BoundsCheckedArray.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoundsCheckedArray.swift; sourceTree = "<group>"; };
D4413FEE1BB06D4C00E3C3C1 /* Dictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = "<group>"; };
D4413FF01BB08FDC00E3C3C1 /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = "<group>"; };
D45A36C81BBC667D00BE3DDE /* Category.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = "<group>"; };
D45A36CC1BBC75DF00BE3DDE /* Info.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Info.swift; sourceTree = "<group>"; };
D49FCBC31BBEF98E00C5E9C3 /* Free.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Free.swift; sourceTree = "<group>"; };
D49FCBC51BBF214300C5E9C3 /* Patch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Patch.swift; sourceTree = "<group>"; };
D49FCBC71BBF2C4300C5E9C3 /* Algorithm.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Algorithm.swift; sourceTree = "<group>"; };
@ -83,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; };
@ -161,9 +155,6 @@
D4413FEE1BB06D4C00E3C3C1 /* Dictionary.swift */,
D4413FF01BB08FDC00E3C3C1 /* JSON.swift */,
D40B89C31BC319070078E098 /* Matrix.swift */,
D4D7F3161BBB22E500AAB0C0 /* Hash.swift */,
D45A36C81BBC667D00BE3DDE /* Category.swift */,
D45A36CC1BBC75DF00BE3DDE /* Info.swift */,
D49FCBC31BBEF98E00C5E9C3 /* Free.swift */,
D42F097B1BCE914A00B95610 /* Cofree.swift */,
D49FCBC51BBF214300C5E9C3 /* Patch.swift */,
@ -346,9 +337,7 @@
files = (
D4AAE5471B5AE2D0004E581F /* Optional.swift in Sources */,
D4413FEF1BB06D4C00E3C3C1 /* Dictionary.swift in Sources */,
D4D7F3171BBB22E500AAB0C0 /* Hash.swift in Sources */,
D42F097E1BCEAEDA00B95610 /* Operation.swift in Sources */,
D45A36C91BBC667D00BE3DDE /* Category.swift in Sources */,
D4DF96ED1BC46B630040F41F /* SES.swift in Sources */,
D42F09801BCECB7900B95610 /* TermType.swift in Sources */,
D4AAE5401B5AE2D0004E581F /* RangeReplaceableCollectionType.swift in Sources */,
@ -356,7 +345,6 @@
D42F097C1BCE914A00B95610 /* Cofree.swift in Sources */,
D4AAE54A1B5AE2D0004E581F /* Syntax.swift in Sources */,
D49FCBC61BBF214300C5E9C3 /* Patch.swift in Sources */,
D45A36CD1BBC75DF00BE3DDE /* Info.swift in Sources */,
D49FCBC81BBF2C4300C5E9C3 /* Algorithm.swift in Sources */,
D4DF970C1BC5DF9E0040F41F /* BoundsCheckedArray.swift in Sources */,
D40B89C41BC319070078E098 /* Matrix.swift in Sources */,

View File

@ -1,52 +0,0 @@
public enum Category: AlgebraicHashable, Comparable, CustomDebugStringConvertible, CustomJSONConvertible {
case Tag(String)
public var tag: String {
switch self {
case let .Tag(s):
return s
}
}
// MARK: AlgebraicHashable
public var hash: Hash {
return Hash("Tag", Hash(tag))
}
// MARK: CustomDebugStringConvertible
public var debugDescription: String {
switch self {
case let .Tag(s):
return ".Tag(\(s))"
}
}
// MARK: CustomJSONConvertible
public var JSON: Doubt.JSON {
switch self {
case let .Tag(s):
return [ "tag": .String(s) ]
}
}
}
// MARK: - Equatable
public func == (left: Category, right: Category) -> Bool {
return left.tag == right.tag
}
// MARK: - Comparable
public func < (left: Category, right: Category) -> Bool {
return left.tag < right.tag
}

View File

@ -76,21 +76,6 @@ public func == <A: Equatable, B: Equatable> (left: Cofree<A, B>, right: Cofree<A
}
// MARK: - Hashing
extension Cofree {
public func hash(annotation annotation: B -> 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 {

View File

@ -144,22 +144,6 @@ public func == <A: Equatable, B: Equatable> (left: Free<A, B>, right: Free<A, B>
}
// 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 {

View File

@ -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)
}
}

View File

@ -1,56 +0,0 @@
/// Source info & categorization for nodes in a syntax tree.
public enum Info: AlgebraicHashable, CustomDebugStringConvertible, CustomJSONConvertible {
case Literal(String, Set<Category>)
public var categories: Set<Category> {
switch self {
case let .Literal(_, c):
return c
}
}
// MARK: AlgebraicHashable
public var hash: Hash {
switch self {
case let .Literal(source, categories):
return Hash("Literal", Hash(source), Hash(categories))
}
}
// MARK: CustomDebugStringConvertible
public var debugDescription: String {
switch self {
case let .Literal(s, c) where c.isEmpty:
return s
case let .Literal(s, c):
return s + " (" + c.sort().map { String(reflecting: $0) }.joinWithSeparator(", ") + ")"
}
}
// MARK: CustomJSONConvertible
public var JSON: Doubt.JSON {
switch self {
case let .Literal(source, categories):
return [
"source": .String(source),
"categories": .Array(categories.map { $0.JSON }),
]
}
}
}
// MARK: - Equality
public func == (left: Info, right: Info) -> Bool {
switch (left, right) {
case let (.Literal(s1, c1), .Literal(s2, c2)):
return s1 == s2 && c1 == c2
}
}

View File

@ -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 {

View File

@ -71,28 +71,6 @@ public func == <F: Equatable, A: Equatable> (left: Syntax<F, A>, right: Syntax<F
}
// MARK: - Hashing
extension Syntax {
public func hash(ifLeaf ifLeaf: A -> 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 {