1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 16:02:43 +03:00

Constant-time length and indexing of input lists.

This commit is contained in:
Rob Rix 2016-06-06 23:03:32 -04:00
parent 65064d03de
commit 0061d075f2

View File

@ -3,6 +3,7 @@ module SES where
import Control.Parallel.Strategies import Control.Parallel.Strategies
import Data.List ((!!)) import Data.List ((!!))
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Vector as Vector
import Patch import Patch
import Prologue import Prologue
import Unsafe import Unsafe
@ -53,7 +54,8 @@ diffAt diffTerms cost (i, j) as bs
ses' :: Applicative edit => Compare term (edit (Patch term)) -> Cost (edit (Patch term)) -> [term] -> [term] -> [edit (Patch term)] ses' :: Applicative edit => Compare term (edit (Patch term)) -> Cost (edit (Patch term)) -> [term] -> [term] -> [edit (Patch term)]
ses' diffTerms cost as bs = fst <$> diffAtMemo 0 0 ses' diffTerms cost as bs = fst <$> diffAtMemo 0 0
where diffAtMemo = fix (memoize2d (length as) (length bs) . diffAt' diffTerms cost (index as) (index bs)) where diffAtMemo = fix (memoize2d (length as) (length bs) . diffAt' diffTerms cost (index as) (index bs))
index elements i = if i < length elements then Just (elements !! i) else Nothing index list i = if i < length elements then Just (elements Vector.! i) else Nothing
where elements = Vector.fromList list
diffAt' :: Applicative edit => Compare term (edit (Patch term)) -> Cost (edit (Patch term)) -> (Int -> Maybe term) -> (Int -> Maybe term) -> (Int -> Int -> [(edit (Patch term), Integer)]) -> Int -> Int -> [(edit (Patch term), Integer)] diffAt' :: Applicative edit => Compare term (edit (Patch term)) -> Cost (edit (Patch term)) -> (Int -> Maybe term) -> (Int -> Maybe term) -> (Int -> Int -> [(edit (Patch term), Integer)]) -> Int -> Int -> [(edit (Patch term), Integer)]
diffAt' diffTerms cost as bs recur i j diffAt' diffTerms cost as bs recur i j