1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 06:41:45 +03:00

Filter the sets of candidates by comparability.

This commit is contained in:
Rob Rix 2017-10-23 12:20:22 -04:00
parent 3462892131
commit 0fb84d5ff3

View File

@ -159,16 +159,15 @@ findNearestNeighbourTo canCompare kdTreeA kdTreeB term@(UnmappedTerm j _ b) = do
(previous, unmappedA, unmappedB) <- get (previous, unmappedA, unmappedB) <- get
fromMaybe (insertion previous unmappedA unmappedB term) $ do fromMaybe (insertion previous unmappedA unmappedB term) $ do
-- Look up the nearest unmapped term in `unmappedA`. -- Look up the nearest unmapped term in `unmappedA`.
foundA@(UnmappedTerm i _ a) <- nearestUnmapped canCompare (termsWithinMoveBoundsFrom previous unmappedA) kdTreeA term foundA@(UnmappedTerm i _ a) <- nearestUnmapped canCompare (IntMap.filterWithKey (\ k (UnmappedTerm _ _ a) -> isInMoveBounds previous k && canCompareTerms canCompare a b) unmappedA) kdTreeA term
-- Look up the nearest `foundA` in `unmappedB` -- Look up the nearest `foundA` in `unmappedB`
UnmappedTerm j' _ _ <- nearestUnmapped (flip canCompare) (termsWithinMoveBoundsFrom (pred j) unmappedB) kdTreeB foundA UnmappedTerm j' _ _ <- nearestUnmapped (flip canCompare) (IntMap.filterWithKey (\ k (UnmappedTerm _ _ b) -> isInMoveBounds (pred j) k && canCompareTerms canCompare a b) unmappedB) kdTreeB foundA
-- Return Nothing if their indices don't match -- Return Nothing if their indices don't match
guard (j == j') guard (j == j')
guard (canCompareTerms canCompare a b) guard (canCompareTerms canCompare a b)
pure $! do pure $! do
put (i, IntMap.delete i unmappedA, IntMap.delete j unmappedB) put (i, IntMap.delete i unmappedA, IntMap.delete j unmappedB)
pure (These i j, These a b) pure (These i j, These a b)
where termsWithinMoveBoundsFrom bound = IntMap.filterWithKey (\ k _ -> isInMoveBounds bound k)
isInMoveBounds :: Int -> Int -> Bool isInMoveBounds :: Int -> Int -> Bool
isInMoveBounds previous i = previous < i && i < previous + defaultMoveBound isInMoveBounds previous i = previous < i && i < previous + defaultMoveBound