Skip to content

Commit 367b358

Browse files
committed
Add conversion functions between Maps and Sets
Closes #87.
1 parent 369a30f commit 367b358

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Data/HashSet.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,15 @@ module Data.HashSet
6060
-- * Filter
6161
, filter
6262

63+
-- * Conversions
64+
6365
-- ** Lists
6466
, toList
6567
, fromList
68+
69+
-- * HashMaps
70+
, toMap
71+
, fromMap
6672
) where
6773

6874
import Control.DeepSeq (NFData(..))
@@ -148,6 +154,14 @@ singleton :: Hashable a => a -> HashSet a
148154
singleton a = HashSet (H.singleton a ())
149155
{-# INLINABLE singleton #-}
150156

157+
-- | /O(1)/ Convert to the equivalent 'HashMap'.
158+
toMap :: HashSet a -> HashMap a ()
159+
toMap = asMap
160+
161+
-- | /O(1)/ Convert from the equivalent 'HashMap'.
162+
fromMap :: HashMap a () -> HashSet a
163+
fromMap = HashSet
164+
151165
-- | /O(n+m)/ Construct a set containing all elements from both sets.
152166
--
153167
-- To obtain good performance, the smaller set must be presented as

0 commit comments

Comments
 (0)