From 52ea386c5bfbb00fd5e9c9b5830588204aa02b4e Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 13 Mar 2017 18:15:09 -0400 Subject: [PATCH] Consolidate the diagonal to check the interval of. --- src/SES/Myers.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/SES/Myers.hs b/src/SES/Myers.hs index 85e80f9b7..d026d8f2e 100644 --- a/src/SES/Myers.hs +++ b/src/SES/Myers.hs @@ -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