1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00

Replace Extent with Endpoint.

This commit is contained in:
Rob Rix 2017-06-21 11:07:53 -04:00
parent 9308e7f64a
commit 105cd7b1ec

View File

@ -58,12 +58,12 @@ runSES eq (EditGraph as bs)
searchUpToD (d:ds) v = searchUpToD (d:ds) v =
let extents = searchAlongK v . Diagonal <$> [ k | k <- [negate d, negate d + 2 .. d], inRange (negate m, n) k ] in let extents = searchAlongK v . Diagonal <$> [ k | k <- [negate d, negate d + 2 .. d], inRange (negate m, n) k ] in
case find isComplete extents of case find isComplete extents of
Just (Extent _ _ script) -> script Just (Endpoint _ _ script) -> script
_ -> searchUpToD ds (Map.fromList ((k' &&& (x' &&& script')) <$> extents)) _ -> searchUpToD ds (Map.fromList ((\ (Endpoint x y script) -> (x - y, (x, script))) <$> extents))
where isComplete (Extent k x _) = x >= n && (x - k) >= m where isComplete (Endpoint x y _) = x >= n && y >= m
-- 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. -- 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 v (Diagonal k) = toExtent k . slideFrom $! searchAlongK v (Diagonal k) = slideFrom $!
if d == 0 || k < negate m || k > n then if d == 0 || k < negate m || k > n then
-- The top-left corner, or otherwise out-of-bounds. -- The top-left corner, or otherwise out-of-bounds.
Endpoint 0 0 [] Endpoint 0 0 []
@ -89,8 +89,6 @@ runSES eq (EditGraph as bs)
-- | Move rightward from a given vertex, deleting the element for the corresponding column. -- | Move rightward from a given vertex, deleting the element for the corresponding column.
moveRightFrom (Endpoint x y script) = Endpoint (succ x) y (if x < n 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)
toExtent k (Endpoint x _ script) = Extent k x script
-- | Slide down any diagonal edges from a given vertex. -- | Slide down any diagonal edges from a given vertex.
slideFrom (Endpoint x y script) slideFrom (Endpoint x y script)
| x >= 0, x < n | x >= 0, x < n
@ -101,8 +99,6 @@ runSES eq (EditGraph as bs)
| otherwise = (Endpoint x y script) | otherwise = (Endpoint x y script)
data Extent a b = Extent { k' :: {-# UNPACK #-} !Int, x' :: {-# UNPACK #-} !Int, script' :: !(EditScript a b) }
-- Implementation details -- Implementation details
-- | The state stored by Myers algorithm; an array of m + n + 1 values indicating the maximum x-index reached and path taken along each diagonal. -- | The state stored by Myers algorithm; an array of m + n + 1 values indicating the maximum x-index reached and path taken along each diagonal.