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

Don’t pass the k-d maps to findNearestNeighbourTo'.

This commit is contained in:
Rob Rix 2017-10-23 21:07:45 -04:00
parent 65f7490809
commit 4e5e142381

View File

@ -177,14 +177,12 @@ findNearestNeighbourTo canCompare kdTreeA kdTreeB term@(UnmappedTerm j _ b) = do
findNearestNeighbourTo' :: (Foldable syntax, Functor syntax, GAlign syntax) findNearestNeighbourTo' :: (Foldable syntax, Functor syntax, GAlign syntax)
=> ComparabilityRelation syntax ann1 ann2 -- ^ A relation determining whether two terms can be compared. => ComparabilityRelation syntax ann1 ann2 -- ^ A relation determining whether two terms can be compared.
-> KdMap Double FeatureVector (UnmappedTerm syntax ann1)
-> KdMap Double FeatureVector (UnmappedTerm syntax ann2)
-> [UnmappedTerm syntax ann1] -> [UnmappedTerm syntax ann1]
-> [UnmappedTerm syntax ann2] -> [UnmappedTerm syntax ann2]
-> [MappedDiff syntax ann1 ann2] -> [MappedDiff syntax ann1 ann2]
findNearestNeighbourTo' _ _ _ as [] = This . (termIndex &&& term) <$> as findNearestNeighbourTo' _ as [] = This . (termIndex &&& term) <$> as
findNearestNeighbourTo' _ _ _ [] bs = That . (termIndex &&& term) <$> bs findNearestNeighbourTo' _ [] bs = That . (termIndex &&& term) <$> bs
findNearestNeighbourTo' canCompare kdTreeA kdTreeB as bs = go (termIndex (head as)) as bs findNearestNeighbourTo' canCompare as bs = go (termIndex (head as)) as bs
where go _ as [] = This . (termIndex &&& term) <$> as where go _ as [] = This . (termIndex &&& term) <$> as
go _ [] bs = That . (termIndex &&& term) <$> bs go _ [] bs = That . (termIndex &&& term) <$> bs
go previous unmappedA@(UnmappedTerm minA _ _ : _) (termB@(UnmappedTerm j _ b) : restUnmappedB) = go previous unmappedA@(UnmappedTerm minA _ _ : _) (termB@(UnmappedTerm j _ b) : restUnmappedB) =
@ -198,6 +196,7 @@ findNearestNeighbourTo' canCompare kdTreeA kdTreeB as bs = go (termIndex (head a
pure $! pure $!
let (deleted, _ : restUnmappedA) = span ((< i) . termIndex) unmappedA in let (deleted, _ : restUnmappedA) = span ((< i) . termIndex) unmappedA in
(This . (termIndex &&& term) <$> deleted) <> (These (i, a) (j, b) : go i restUnmappedA restUnmappedB) (This . (termIndex &&& term) <$> deleted) <> (These (i, a) (j, b) : go i restUnmappedA restUnmappedB)
(kdTreeA, kdTreeB) = (toKdMap as, toKdMap bs)
isNearAndComparableTo :: ComparabilityRelation syntax ann1 ann2 -> Int -> Term syntax ann2 -> UnmappedTerm syntax ann1 -> Bool isNearAndComparableTo :: ComparabilityRelation syntax ann1 ann2 -> Int -> Term syntax ann2 -> UnmappedTerm syntax ann1 -> Bool
isNearAndComparableTo canCompare index term (UnmappedTerm k _ term') = inRange (succ index, index + defaultMoveBound) k && canCompareTerms canCompare term' term isNearAndComparableTo canCompare index term (UnmappedTerm k _ term') = inRange (succ index, index + defaultMoveBound) k && canCompareTerms canCompare term' term
@ -248,7 +247,7 @@ mapContiguous canCompare = go 0 0 id id
These a b -> mapChunk (ls []) (rs []) <> (These (i, a) (j, b) : go (succ i) (succ j) id id rest) These a b -> mapChunk (ls []) (rs []) <> (These (i, a) (j, b) : go (succ i) (succ j) id id rest)
mapChunk ls [] = This . (termIndex &&& term) <$> ls mapChunk ls [] = This . (termIndex &&& term) <$> ls
mapChunk [] rs = That . (termIndex &&& term) <$> rs mapChunk [] rs = That . (termIndex &&& term) <$> rs
mapChunk ls rs = findNearestNeighbourTo' canCompare (toKdMap ls) (toKdMap rs) ls rs mapChunk ls rs = findNearestNeighbourTo' canCompare ls rs
genFeaturizedTermsAndDiffs :: Functor syntax genFeaturizedTermsAndDiffs :: Functor syntax