optimize Names.contains

This commit is contained in:
Mitchell Rosen 2021-12-08 19:27:32 -05:00
parent 0f2fc7d15d
commit 0ae88ea47b

View File

@ -381,10 +381,13 @@ difference a b = Names (R.difference (terms a) (terms b))
(R.difference (types a) (types b))
contains :: Names -> Reference -> Bool
contains names r =
-- this check makes `contains` O(n) instead of O(log n)
(Set.member r . Set.map Referent.toReference . R.ran) (terms names)
|| R.memberRan r (types names)
contains names =
\r -> Set.member r termsReferences || R.memberRan r (types names)
where
-- this check makes `contains` O(n) instead of O(log n)
termsReferences :: Set Reference
termsReferences =
Set.map Referent.toReference (R.ran (terms names))
-- | filters out everything from the domain except what's conflicted
conflicts :: Names -> Names