mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Constant-time length and indexing of input lists.
This commit is contained in:
parent
65064d03de
commit
0061d075f2
@ -3,6 +3,7 @@ module SES where
|
||||
import Control.Parallel.Strategies
|
||||
import Data.List ((!!))
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Vector as Vector
|
||||
import Patch
|
||||
import Prologue
|
||||
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' diffTerms cost as bs = fst <$> diffAtMemo 0 0
|
||||
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' diffTerms cost as bs recur i j
|
||||
|
Loading…
Reference in New Issue
Block a user