1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 21:52:59 +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 { 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 // nominate the best edge to continue along
if let compareHere = recur(a[i], b[j]) { if let compareHere = recur(a[i], b[j]) {
let (best, diff, _) = min( let (best, diff, _) = min(
(diagonal, compareHere, costOfStream(diagonal)), (diagonal, compareHere, costOfStream(diagonal)),
(right, Diff.Pure(Patch.Delete(a[i])), costOfStream(right)), right,
(down, Diff.Pure(Patch.Insert(b[j])), costOfStream(down))) { $0.2 < $1.2 } down) { $0.2 < $1.2 }
return cons(diff, rest: best) return cons(diff, rest: best)
} else { } else {
let (best, diff, _) = min( let (best, diff, _) = min(
(right, Diff.Pure(Patch.Delete(a[i])), costOfStream(right)), right,
(down, Diff.Pure(Patch.Insert(b[j])), costOfStream(down))) { $0.2 < $1.2 } down) { $0.2 < $1.2 }
return cons(diff, rest: best) return cons(diff, rest: best)
} }
} }