mirror of
https://github.com/github/semantic.git
synced 2025-01-02 20:41:38 +03:00
Consolidate the diagonal to check the interval of.
This commit is contained in:
parent
60316fe28e
commit
52ea386c5b
@ -119,14 +119,14 @@ decompose myers = let ?callStack = popCallStack callStack in case myers of
|
||||
|
||||
SearchAlongK graph d direction@Forward (Diagonal k) -> do
|
||||
(forwardEndpoint, reverseEndpoint) <- endpointsFor graph d direction k
|
||||
if odd delta && k `inInterval` diagonalInterval direction d && overlaps graph forwardEndpoint reverseEndpoint then
|
||||
if odd delta && diagonalFor direction k `inInterval` diagonalInterval direction d && overlaps graph forwardEndpoint reverseEndpoint then
|
||||
return (done reverseEndpoint forwardEndpoint (editDistance direction d))
|
||||
else
|
||||
continue
|
||||
|
||||
SearchAlongK graph d direction@Reverse (Diagonal k) -> do
|
||||
(forwardEndpoint, reverseEndpoint) <- endpointsFor graph d direction k
|
||||
if even delta && (k + delta) `inInterval` diagonalInterval direction d && overlaps graph forwardEndpoint reverseEndpoint then
|
||||
if even delta && diagonalFor direction k `inInterval` diagonalInterval direction d && overlaps graph forwardEndpoint reverseEndpoint then
|
||||
return (done reverseEndpoint forwardEndpoint (editDistance direction d))
|
||||
else
|
||||
continue
|
||||
@ -150,6 +150,8 @@ decompose myers = let ?callStack = popCallStack callStack in case myers of
|
||||
delta = n - m
|
||||
maxD = (m + n) `ceilDiv` 2
|
||||
|
||||
inInterval (Diagonal k) (lower, upper) = k >= lower && k <= upper
|
||||
|
||||
diagonalInterval Forward (EditDistance d) = (delta - pred d, delta + pred d)
|
||||
diagonalInterval Reverse (EditDistance d) = (negate d, d)
|
||||
|
||||
@ -238,9 +240,6 @@ setBackward v = modify (\ s -> s { backward = v })
|
||||
overlaps :: EditGraph a -> Endpoint -> Endpoint -> Bool
|
||||
overlaps (EditGraph as _) (Endpoint x y) (Endpoint u v) = x - y == u - v && x <= length as - u
|
||||
|
||||
inInterval :: Ord a => a -> (a, a) -> Bool
|
||||
inInterval k (lower, upper) = k >= lower && k <= upper
|
||||
|
||||
for :: [a] -> (a -> Myers c (Maybe b)) -> Myers c (Maybe b)
|
||||
for all run = foldr (\ a b -> (<|>) <$> run a <*> b) (return Nothing) all
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user