Skip to content

Commit 76f6d3c

Browse files
committed
Re #8392: extended haddocks of new utility hasElem
1 parent 1784dfb commit 76f6d3c

File tree

1 file changed

+6
-1
lines changed
  • cabal-install/src/Distribution/Client

1 file changed

+6
-1
lines changed

cabal-install/src/Distribution/Client/Utils.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,13 @@ safeRead s
480480
| [(x, "")] <- reads s = Just x
481481
| otherwise = Nothing
482482

483-
484483
-- | @hasElem xs x = elem x xs@ except that @xs@ is turned into a 'Set' first.
485484
-- Use underapplied to speed up subsequent lookups, e.g. @filter (hasElem xs) ys@.
485+
-- Only amortized when used several times!
486+
--
487+
-- Time complexity \(O((n+m) \log(n))\) for \(m\) lookups in a list of length \(n\).
488+
-- (Compare this to 'elem''s \(O(nm)\).)
489+
--
490+
-- This is [Agda.Utils.List.hasElem](https://hackage.haskell.org/package/Agda-2.6.2.2/docs/Agda-Utils-List.html#v:hasElem).
486491
hasElem :: Ord a => [a] -> a -> Bool
487492
hasElem xs = (`Set.member` Set.fromList xs)

0 commit comments

Comments
 (0)