mirror of
https://github.com/github/semantic.git
synced 2024-12-11 08:45:48 +03:00
Index the elements, not the fold.
This commit is contained in:
parent
ce0866dc1b
commit
444f0b306c
@ -90,18 +90,18 @@ newtype DedupeKey = DedupeKey (T.Text, T.Text) deriving (Eq, Ord)
|
|||||||
-- identifiers) are in the list.
|
-- identifiers) are in the list.
|
||||||
-- Action: Combine them into a single Replaced entry.
|
-- Action: Combine them into a single Replaced entry.
|
||||||
dedupe :: [(Entry, Declaration)] -> [(Entry, Declaration)]
|
dedupe :: [(Entry, Declaration)] -> [(Entry, Declaration)]
|
||||||
dedupe = map snd . sortOn fst . Map.elems . snd . foldl' go (0, Map.empty)
|
dedupe = map snd . sortOn fst . Map.elems . foldl' go Map.empty . zip [0..]
|
||||||
where
|
where
|
||||||
go :: (Int, Map.Map DedupeKey (Int, (Entry, Declaration)))
|
go :: Map.Map DedupeKey (Int, (Entry, Declaration))
|
||||||
-> (Entry, Declaration)
|
-> (Int, (Entry, Declaration))
|
||||||
-> (Int, Map.Map DedupeKey (Int, (Entry, Declaration)))
|
-> Map.Map DedupeKey (Int, (Entry, Declaration))
|
||||||
go (index, m) (entry, decl)
|
go m (index, (entry, decl))
|
||||||
| Just (_, (_, similar)) <- Map.lookup (dedupeKey decl) m
|
| Just (_, (_, similar)) <- Map.lookup (dedupeKey decl) m
|
||||||
= (succ index,) $ if similar == decl then
|
= if similar == decl then
|
||||||
m
|
m
|
||||||
else
|
else
|
||||||
Map.insert (dedupeKey similar) (index, (Replaced, similar)) m
|
Map.insert (dedupeKey similar) (index, (Replaced, similar)) m
|
||||||
| otherwise = (succ index, Map.insert (dedupeKey decl) (index, (entry, decl)) m)
|
| otherwise = Map.insert (dedupeKey decl) (index, (entry, decl)) m
|
||||||
|
|
||||||
dedupeKey (Declaration kind ident _ _ _) = DedupeKey (toCategoryName kind, T.toLower ident)
|
dedupeKey (Declaration kind ident _ _ _) = DedupeKey (toCategoryName kind, T.toLower ident)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user