1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 00:42:33 +03:00

Revert "Simplify the search logic."

This reverts commit 008658c2bfb06da29d56278b4b48f5b76d0dd211.
This commit is contained in:
Rob Rix 2017-06-21 13:54:59 -04:00
parent c45b5a32b0
commit c736d2527c

View File

@ -23,13 +23,13 @@ ses :: (Foldable t, Foldable u) => (a -> b -> Bool) -> t a -> u b -> EditScript
ses eq as' bs'
| null bs = This <$> toList as
| null as = That <$> toList bs
| otherwise = reverse (searchUpToD 0 (Array.array (1, 1) [(1, Endpoint 0 (-1) [])]))
| otherwise = reverse (searchUpToD 0 (Array.array (0, 0) [(0, Endpoint 0 0 [])]))
where (as, bs) = (Array.listArray (0, pred n) (toList as'), Array.listArray (0, pred m) (toList bs'))
(n, m) = (length as', length bs')
-- Search an edit graph for the shortest edit script up to a given proposed edit distance, building on the results of previous searches.
searchUpToD d v =
let endpoints = searchAlongK <$> [ k | k <- [-d, -d + 2 .. d], inRange (-m, n) k ] in
let endpoints = searchAlongK <$> [ k | k <- [-d, -d + 2 .. d], inRange (negate m, n) k ] in
case find isComplete endpoints of
Just (Endpoint _ _ script) -> script
_ -> searchUpToD (succ d) (Array.array (-d, d) ((\ e@(Endpoint x y _) -> (x - y, e)) <$> endpoints))
@ -37,18 +37,30 @@ ses eq as' bs'
-- Search an edit graph for the shortest edit script along a specific diagonal, moving onto a given diagonal from one of its in-bounds adjacent diagonals (if any), and sliding down any diagonal edges eagerly.
searchAlongK k = slideFrom $!
if k == -d || k == -m || k /= d && k /= n && x left < x up then
if d == 0 then
-- The top-left corner.
Endpoint 0 0 []
else if k == -d || k == -m then
-- The lower/left extent of the search region or edit graph, whichever is smaller.
moveDownFrom up
else if k /= d && k /= n then
-- Somewhere in the interior of the search region and edit graph.
if x left < x up then
moveDownFrom up
else
moveRightFrom left
where left = v ! pred k
up = v ! succ k
else
-- The upper/right extent of the search region or edit graph, whichever is smaller.
moveRightFrom left
where getK k = v ! k
left = getK (pred k)
up = getK (succ k)
-- | Move downward from a given vertex, inserting the element for the corresponding row.
moveDownFrom (Endpoint x y script) = Endpoint x (succ y) (if inRange (Array.bounds bs) y then That (bs ! y) : script else script)
moveDownFrom (Endpoint x y script) = Endpoint x (succ y) (if y < m then That (bs ! y) : script else script)
-- | Move rightward from a given vertex, deleting the element for the corresponding column.
moveRightFrom (Endpoint x y script) = Endpoint (succ x) y (if inRange (Array.bounds as) x then This (as ! x) : script else script)
moveRightFrom (Endpoint x y script) = Endpoint (succ x) y (if x < n then This (as ! x) : script else script)
-- | Slide down any diagonal edges from a given vertex.
slideFrom (Endpoint x y script)