1
1
mirror of https://github.com/github/semantic.git synced 2024-12-02 02:08:48 +03:00

Factor out right/down.

This commit is contained in:
Rob Rix 2015-10-13 17:50:22 -04:00
parent e09d46d109
commit 32bfdc6766

View File

@ -53,17 +53,19 @@ public func SES<A>(a: [Fix<A>], _ b: [Fix<A>], equals: (A, A) -> Bool, recur: (F
}
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))
// nominate the best edge to continue along
if let compareHere = recur(a[i], b[j]) {
let (best, diff, _) = min(
(diagonal, compareHere, costOfStream(diagonal)),
(right, Diff.Pure(Patch.Delete(a[i])), costOfStream(right)),
(down, Diff.Pure(Patch.Insert(b[j])), costOfStream(down))) { $0.2 < $1.2 }
right,
down) { $0.2 < $1.2 }
return cons(diff, rest: best)
} else {
let (best, diff, _) = min(
(right, Diff.Pure(Patch.Delete(a[i])), costOfStream(right)),
(down, Diff.Pure(Patch.Insert(b[j])), costOfStream(down))) { $0.2 < $1.2 }
right,
down) { $0.2 < $1.2 }
return cons(diff, rest: best)
}
}