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

Diagonals.

This commit is contained in:
Rob Rix 2015-11-18 10:36:19 -08:00
parent ad0c9ca4b2
commit 7e75c662dc

View File

@ -11,8 +11,13 @@ ses :: Compare a -> [Term a Info] -> [Term a Info] -> [Diff a]
ses _ [] b = (Pure . Insert) <$> b
ses _ a [] = (Pure . Delete) <$> a
ses recur (a : as) (b : bs) = case recur a b of
Just f -> f : ses recur as bs
Nothing -> if SES.cost delete < SES.cost insert then delete else insert where
Just f | SES.cost delete < SES.cost insert && SES.cost delete < SES.cost copy -> delete
| SES.cost insert < SES.cost copy -> insert
| otherwise -> copy
where
copy = f : ses recur as bs
Nothing -> if SES.cost delete < SES.cost insert then delete else insert
where
delete = (Pure . Delete $ a) : ses recur as (b : bs)
insert = (Pure . Insert $ b) : ses recur (a : as) bs