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

Nominate the best interior edge using compare-parametric min.

This commit is contained in:
Rob Rix 2015-10-07 13:13:32 -04:00
parent 47dec5546d
commit c2b00c2230

View File

@ -55,19 +55,11 @@ 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 costs = (right: costOfStream(right), down: costOfStream(down), diagonal: costOfStream(diagonal))
// nominate the best edge to continue along
let best: Memo<Stream<(Diff, Int)>>
let diff: Diff
if costs.diagonal < costs.down {
(best, diff) = costs.diagonal < costs.right
? (diagonal, recur(a[i], b[j]))
: (right, Diff.Pure(Patch.Delete(a[i])))
} else {
(best, diff) = costs.down < costs.right
? (down, Diff.Pure(Patch.Insert(b[j])))
: (right, Diff.Pure(Patch.Delete(a[i])))
}
let (best, diff, _) = min(
(diagonal, recur(a[i], b[j]), costOfStream(diagonal)),
(right, Diff.Pure(Patch.Delete(a[i])), costOfStream(right)),
(down, Diff.Pure(Patch.Insert(b[j])), costOfStream(down))) { $0.2 < $1.2 }
return cons(diff, rest: best)
}