1
1
mirror of https://github.com/github/semantic.git synced 2024-11-25 11:04:00 +03:00

Use the patch constructors in SES.

This commit is contained in:
Rob Rix 2015-10-15 11:19:14 -04:00
parent 298a37c444
commit fed0d91d30

View File

@ -4,8 +4,8 @@
public func SES<Term, A>(a: [Term], _ b: [Term], recur: (Term, Term) -> Free<A, Patch<Term>>?) -> [Free<A, Patch<Term>>] {
typealias Diff = Free<A, Patch<Term>>
if a.isEmpty { return b.map { Diff.Pure(Patch.Insert($0)) } }
if b.isEmpty { return a.map { Diff.Pure(Patch.Delete($0)) } }
if a.isEmpty { return b.map { .Insert($0) } }
if b.isEmpty { return a.map { .Delete($0) } }
func cost(diff: Diff) -> Int {
return diff.map(const(1)).iterate { syntax in
@ -46,8 +46,8 @@ public func SES<Term, A>(a: [Term], _ b: [Term], recur: (Term, Term) -> Free<A,
let diagonal = matrix[i + 1, j + 1]
if let right = right, down = down, diagonal = diagonal {
let right = (right, Diff.Pure(Patch.Delete(a[i])), costOfStream(right))
let down = (down, Diff.Pure(Patch.Insert(b[j])), costOfStream(down))
let right = (right, Diff.Delete(a[i]), costOfStream(right))
let down = (down, Diff.Insert(b[j]), costOfStream(down))
let diagonal = recur(a[i], b[j]).map { (diagonal, $0, costOfStream(diagonal)) }
// nominate the best edge to continue along, not considering diagonal if `recur` returned `nil`.
let (best, diff, _) = diagonal