From 0d22eabf5bf9ddd0a904586062e8b9a0a34cf376 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 21 Jun 2017 11:31:38 -0400 Subject: [PATCH] Store Endpoints in the state. This uses a word of extra space but saves some time moving things around. --- src/SES/Myers.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SES/Myers.hs b/src/SES/Myers.hs index 83517d16c..a87ff96f2 100644 --- a/src/SES/Myers.hs +++ b/src/SES/Myers.hs @@ -24,7 +24,7 @@ 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 (Map.singleton 0 (0, []))) + | otherwise = reverse (searchUpToD 0 (Map.singleton 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') @@ -33,7 +33,7 @@ ses eq as' bs' let endpoints = searchAlongK <$> [ k | k <- [negate d, negate d + 2 .. d], inRange (negate m, n) k ] in case find isComplete endpoints of Just (Endpoint _ _ script) -> script - _ -> searchUpToD (succ d) (Map.fromList ((\ (Endpoint x y script) -> (x - y, (x, script))) <$> endpoints)) + _ -> searchUpToD (succ d) (Map.fromList ((\ e@(Endpoint x y _) -> (x - y, e)) <$> endpoints)) 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. @@ -53,7 +53,7 @@ ses eq as' bs' else -- The upper/right extent of the search region or edit graph, whichever is smaller. moveRightFrom prev - where getK k = let (x, script) = v Map.! k in Endpoint x (x - k) script + where getK k = v Map.! k prev = getK (pred k) next = getK (succ k)