1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 16:33:03 +03:00

Merge branch 'master' into tree-sitter-ffi

This commit is contained in:
Rob Rix 2015-11-25 10:39:18 -05:00
commit 67d231056e

View File

@ -12,18 +12,18 @@ type Cost a annotation = Diff a annotation -> Integer
ses :: Compare a annotation -> Cost a annotation -> [Term a annotation] -> [Term a annotation] -> [Diff a annotation]
ses _ _ [] b = (Pure . Insert) <$> b
ses _ _ a [] = (Pure . Delete) <$> a
ses recur cost (a : as) (b : bs) = case recur a b of
ses diffTerms cost (a : as) (b : bs) = case diffTerms a b of
Just f | deleteCost < insertCost && deleteCost < copyCost -> delete
| insertCost < copyCost -> insert
| otherwise -> copy
where
copy = f : ses recur cost as bs
copy = f : ses diffTerms cost as bs
copyCost = sumCost copy
Nothing | deleteCost < insertCost -> delete
| otherwise -> insert
where
delete = (Pure . Delete $ a) : ses recur cost as (b : bs)
insert = (Pure . Insert $ b) : ses recur cost (a : as) bs
delete = (Pure . Delete $ a) : ses diffTerms cost as (b : bs)
insert = (Pure . Insert $ b) : ses diffTerms cost (a : as) bs
deleteCost = sumCost delete
insertCost = sumCost insert
sumCost a = sum $ cost <$> a