@@ -283,7 +283,7 @@ singleton a = HashSet (H.singleton a ())
283283-- >>> HashSet.toMap (HashSet.singleton 1)
284284-- fromList [(1,())]
285285--
286- -- __Complexity:__ /O(1)/
286+ -- /Complexity:/ /O(1)/
287287toMap :: HashSet a -> HashMap a ()
288288toMap = asMap
289289
@@ -292,7 +292,7 @@ toMap = asMap
292292-- >>> HashSet.fromMap (HashMap.singleton 1 ())
293293-- fromList [1]
294294--
295- -- __Complexity:__ /O(1)/
295+ -- /Complexity:/ /O(1)/
296296fromMap :: HashMap a () -> HashSet a
297297fromMap = HashSet
298298
@@ -301,7 +301,7 @@ fromMap = HashSet
301301-- >>> HashSet.keysSet (HashMap.fromList [(1, "a"), (2, "b")]
302302-- fromList [1,2]
303303--
304- -- __Complexity:__ /O(n)/
304+ -- /Complexity:/ /O(n)/
305305--
306306-- @since 0.2.10.0
307307keysSet :: HashMap k a -> HashSet k
@@ -346,7 +346,8 @@ null = H.null . asMap
346346-- >>> HashSet.size (HashSet.fromList [1,2,3])
347347-- 3
348348--
349- -- __Complexity:__ /O(n)/
349+ -- __Complexity:__ /O(n)/ - The implementation of @HashSet@ does not save the
350+ -- size in a field so must traverse the entire data structure on each call.
350351size :: HashSet a -> Int
351352size = H. size . asMap
352353{-# INLINE size #-}
@@ -468,7 +469,7 @@ foldl f z0 = foldlWithKey g z0 . asMap
468469-- | Filter this set by retaining only elements satisfying a
469470-- predicate.
470471--
471- -- __Complexity:__ /O(n)/
472+ -- /Complexity:/ /O(n)/
472473filter :: (a -> Bool ) -> HashSet a -> HashSet a
473474filter p = HashSet . H. filterWithKey q . asMap
474475 where q k _ = p k
@@ -477,14 +478,14 @@ filter p = HashSet . H.filterWithKey q . asMap
477478-- | Return a list of this set's elements. The list is
478479-- produced lazily.
479480--
480- -- __Complexity:__ /O(n)/
481+ -- /Complexity:/ /O(n)/
481482toList :: HashSet a -> [a ]
482483toList t = build (\ c z -> foldrWithKey ((const . ) c) z (asMap t))
483484{-# INLINE toList #-}
484485
485486-- | Construct a set from a list of elements.
486487--
487- -- __Complexity:__ /O(n*min(W, n))/
488+ -- /Complexity:/ /O(n*min(W, n))/
488489fromList :: (Eq a , Hashable a ) => [a ] -> HashSet a
489490fromList = HashSet . List. foldl' (\ m k -> H. insert k () m) H. empty
490491{-# INLINE fromList #-}
0 commit comments