1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Add doc to editDistanceUpTo

This commit is contained in:
joshvera 2016-09-07 19:46:23 -04:00
parent 4f3af677e6
commit 648b61a94f

View File

@ -82,10 +82,11 @@ rws compare as bs
deleteRemaining diffs (_, unmappedA, _) = foldl' (flip (List.insertBy (comparing fst))) diffs ((termIndex &&& deleting . term) <$> unmappedA)
-- | Return an edit distance as the sum of it's term sizes, given an cutoff and a syntax of terms 'f a'.
-- | Computes a constant-time approximation to the edit distance of a diff. This is done by comparing at most _m_ nodes, & assuming the rest are zero-cost.
editDistanceUpTo :: (Prologue.Foldable f, Functor f) => Integer -> Free (CofreeF f (Both a)) (Patch (Cofree f a)) -> Int
editDistanceUpTo m = diffSum (patchSum termSize) . cutoff m
where diffSum patchCost diff = sum $ fmap (maybe 0 patchCost) diff
where diffSum patchCost = sum . fmap (maybe 0 patchCost)
defaultD, defaultL, defaultP, defaultQ, defaultMoveBound :: Int
defaultD = 15