@@ -283,7 +283,7 @@ singleton a = HashSet (H.singleton a ())
283
283
-- >>> HashSet.toMap (HashSet.singleton 1)
284
284
-- fromList [(1,())]
285
285
--
286
- -- __Complexity:__ /O(1)/
286
+ -- /Complexity:/ /O(1)/
287
287
toMap :: HashSet a -> HashMap a ()
288
288
toMap = asMap
289
289
@@ -292,7 +292,7 @@ toMap = asMap
292
292
-- >>> HashSet.fromMap (HashMap.singleton 1 ())
293
293
-- fromList [1]
294
294
--
295
- -- __Complexity:__ /O(1)/
295
+ -- /Complexity:/ /O(1)/
296
296
fromMap :: HashMap a () -> HashSet a
297
297
fromMap = HashSet
298
298
@@ -301,7 +301,7 @@ fromMap = HashSet
301
301
-- >>> HashSet.keysSet (HashMap.fromList [(1, "a"), (2, "b")]
302
302
-- fromList [1,2]
303
303
--
304
- -- __Complexity:__ /O(n)/
304
+ -- /Complexity:/ /O(n)/
305
305
--
306
306
-- @since 0.2.10.0
307
307
keysSet :: HashMap k a -> HashSet k
@@ -346,7 +346,8 @@ null = H.null . asMap
346
346
-- >>> HashSet.size (HashSet.fromList [1,2,3])
347
347
-- 3
348
348
--
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.
350
351
size :: HashSet a -> Int
351
352
size = H. size . asMap
352
353
{-# INLINE size #-}
@@ -468,7 +469,7 @@ foldl f z0 = foldlWithKey g z0 . asMap
468
469
-- | Filter this set by retaining only elements satisfying a
469
470
-- predicate.
470
471
--
471
- -- __Complexity:__ /O(n)/
472
+ -- /Complexity:/ /O(n)/
472
473
filter :: (a -> Bool ) -> HashSet a -> HashSet a
473
474
filter p = HashSet . H. filterWithKey q . asMap
474
475
where q k _ = p k
@@ -477,14 +478,14 @@ filter p = HashSet . H.filterWithKey q . asMap
477
478
-- | Return a list of this set's elements. The list is
478
479
-- produced lazily.
479
480
--
480
- -- __Complexity:__ /O(n)/
481
+ -- /Complexity:/ /O(n)/
481
482
toList :: HashSet a -> [a ]
482
483
toList t = build (\ c z -> foldrWithKey ((const . ) c) z (asMap t))
483
484
{-# INLINE toList #-}
484
485
485
486
-- | Construct a set from a list of elements.
486
487
--
487
- -- __Complexity:__ /O(n*min(W, n))/
488
+ -- /Complexity:/ /O(n*min(W, n))/
488
489
fromList :: (Eq a , Hashable a ) => [a ] -> HashSet a
489
490
fromList = HashSet . List. foldl' (\ m k -> H. insert k () m) H. empty
490
491
{-# INLINE fromList #-}
0 commit comments