From 30b9e85ed31fa7eb104ea78f8d968788d96693e0 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 21 Jun 2017 11:36:26 -0400 Subject: [PATCH] Use minimal Arrays for the state. --- src/SES/Myers.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/SES/Myers.hs b/src/SES/Myers.hs index a87ff96f2..e9be5bb91 100644 --- a/src/SES/Myers.hs +++ b/src/SES/Myers.hs @@ -6,7 +6,6 @@ module SES.Myers import Data.Array ((!)) import qualified Data.Array as Array -import qualified Data.IntMap.Lazy as Map import Data.Ix import Data.These import GHC.Show hiding (show) @@ -24,7 +23,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 (Endpoint 0 0 []))) + | otherwise = reverse (searchUpToD 0 (Array.array (0, 0) [(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 +32,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 ((\ e@(Endpoint x y _) -> (x - y, e)) <$> endpoints)) + _ -> searchUpToD (succ d) (Array.array (negate d, d) ((\ 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 +52,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 = v Map.! k + where getK k = v ! k prev = getK (pred k) next = getK (succ k)