1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 04:41:47 +03:00

📝 constantTimeEditDistance.

This commit is contained in:
Rob Rix 2016-08-18 12:35:24 -04:00
parent ffad7170f0
commit 3832a7b90f

View File

@ -62,6 +62,7 @@ rws compare as bs
-- cf §4.2 of RWS-Diff
nearestUnmapped unmapped tree key = getFirst $ foldMap (First . Just) (sortOn (constantTimeEditDistance key) (intersectBy ((==) `on` termIndex) unmapped (KdTree.kNearest tree 2 key)))
-- | 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.
constantTimeEditDistance key a = fromMaybe (maxBound :: Int) $ diffCostOfMaybes . cutoff 10 <$> compare (term key) (term a)
insertion previous unmappedA unmappedB kv@(UnmappedTerm _ _ b) = do