mirror of
https://github.com/github/semantic.git
synced 2024-11-23 16:37:50 +03:00
Use minimal Arrays for the state.
This commit is contained in:
parent
0d22eabf5b
commit
30b9e85ed3
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user