mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
Extract a common handler for the selection of the diagonal.
This commit is contained in:
parent
93116b7f26
commit
99b07c3483
@ -118,18 +118,18 @@ decompose myers = let ?callStack = popCallStack callStack in case myers of
|
|||||||
<*> for [negate d, negate d + 2 .. d] (searchAlongK graph (EditDistance d) Reverse . Diagonal)
|
<*> for [negate d, negate d + 2 .. d] (searchAlongK graph (EditDistance d) Reverse . Diagonal)
|
||||||
|
|
||||||
SearchAlongK graph (EditDistance d) direction@Forward (Diagonal k) -> do
|
SearchAlongK graph (EditDistance d) direction@Forward (Diagonal k) -> do
|
||||||
forwardEndpoint <- findDPath graph (EditDistance d) direction (Diagonal k)
|
forwardEndpoint <- findDPath graph (EditDistance d) direction (diagonalFor direction k)
|
||||||
backwardV <- gets backward
|
backwardV <- gets backward
|
||||||
let reverseEndpoint = let x = backwardV `at` k in Endpoint x (x - k)
|
let reverseEndpoint = let x = backwardV `at` diagonalFor direction k in Endpoint x (x - k)
|
||||||
if odd delta && k `inInterval` diagonalInterval direction d && overlaps graph forwardEndpoint reverseEndpoint then
|
if odd delta && k `inInterval` diagonalInterval direction d && overlaps graph forwardEndpoint reverseEndpoint then
|
||||||
return (done reverseEndpoint forwardEndpoint (editDistance direction d))
|
return (done reverseEndpoint forwardEndpoint (editDistance direction d))
|
||||||
else
|
else
|
||||||
continue
|
continue
|
||||||
|
|
||||||
SearchAlongK graph (EditDistance d) direction@Reverse (Diagonal k) -> do
|
SearchAlongK graph (EditDistance d) direction@Reverse (Diagonal k) -> do
|
||||||
reverseEndpoint <- findDPath graph (EditDistance d) direction (Diagonal (k + delta))
|
reverseEndpoint <- findDPath graph (EditDistance d) direction (diagonalFor direction k)
|
||||||
forwardV <- gets forward
|
forwardV <- gets forward
|
||||||
let forwardEndpoint = let x = forwardV `at` (k + delta) in Endpoint x (x - k)
|
let forwardEndpoint = let x = forwardV `at` diagonalFor direction k in Endpoint x (x - k)
|
||||||
if even delta && (k + delta) `inInterval` diagonalInterval direction d && overlaps graph forwardEndpoint reverseEndpoint then
|
if even delta && (k + delta) `inInterval` diagonalInterval direction d && overlaps graph forwardEndpoint reverseEndpoint then
|
||||||
return (done reverseEndpoint forwardEndpoint (editDistance direction d))
|
return (done reverseEndpoint forwardEndpoint (editDistance direction d))
|
||||||
else
|
else
|
||||||
@ -138,8 +138,8 @@ decompose myers = let ?callStack = popCallStack callStack in case myers of
|
|||||||
FindDPath _ (EditDistance d) Forward (Diagonal k) -> do
|
FindDPath _ (EditDistance d) Forward (Diagonal k) -> do
|
||||||
v <- gets forward
|
v <- gets forward
|
||||||
eq <- getEq
|
eq <- getEq
|
||||||
let prev = v `at` pred k
|
let prev = v `at` Diagonal (pred k)
|
||||||
let next = v `at` succ k
|
let next = v `at` Diagonal (succ k)
|
||||||
let x = if k == negate d || k /= d && prev < next
|
let x = if k == negate d || k /= d && prev < next
|
||||||
then next
|
then next
|
||||||
else succ prev
|
else succ prev
|
||||||
@ -150,8 +150,8 @@ decompose myers = let ?callStack = popCallStack callStack in case myers of
|
|||||||
FindDPath _ (EditDistance d) Reverse (Diagonal k) -> do
|
FindDPath _ (EditDistance d) Reverse (Diagonal k) -> do
|
||||||
v <- gets backward
|
v <- gets backward
|
||||||
eq <- getEq
|
eq <- getEq
|
||||||
let prev = v `at` pred k
|
let prev = v `at` Diagonal (pred k)
|
||||||
let next = v `at` succ k
|
let next = v `at` Diagonal (succ k)
|
||||||
let x = if k == negate d || k /= d && prev < next
|
let x = if k == negate d || k /= d && prev < next
|
||||||
then next
|
then next
|
||||||
else succ prev
|
else succ prev
|
||||||
@ -166,11 +166,14 @@ decompose myers = let ?callStack = popCallStack callStack in case myers of
|
|||||||
delta = n - m
|
delta = n - m
|
||||||
maxD = (m + n) `ceilDiv` 2
|
maxD = (m + n) `ceilDiv` 2
|
||||||
|
|
||||||
at v k = v ! maxD + k
|
at v (Diagonal k) = v ! maxD + k
|
||||||
|
|
||||||
diagonalInterval Forward d = (delta - pred d, delta + pred d)
|
diagonalInterval Forward d = (delta - pred d, delta + pred d)
|
||||||
diagonalInterval Reverse d = (negate d, d)
|
diagonalInterval Reverse d = (negate d, d)
|
||||||
|
|
||||||
|
diagonalFor Forward k = Diagonal k
|
||||||
|
diagonalFor Reverse k = Diagonal (k + delta)
|
||||||
|
|
||||||
done (Endpoint x y) uv d = Just (Snake (Endpoint (n - x) (m - y)) uv, EditDistance d)
|
done (Endpoint x y) uv d = Just (Snake (Endpoint (n - x) (m - y)) uv, EditDistance d)
|
||||||
editDistance Forward d = 2 * d - 1
|
editDistance Forward d = 2 * d - 1
|
||||||
editDistance Reverse d = 2 * d
|
editDistance Reverse d = 2 * d
|
||||||
|
Loading…
Reference in New Issue
Block a user