33-- |
44-- | Qualified import is encouraged, so as to avoid name clashes with other modules.
55
6- module Data.Set
7- ( Set (),
8- empty ,
9- isEmpty ,
10- singleton ,
11- checkValid ,
12- insert ,
13- member ,
14- delete ,
15- toList ,
16- fromList ,
17- size ,
18- union ,
19- unions ,
20- difference
6+ module Data.Set
7+ ( Set ()
8+ , empty
9+ , isEmpty
10+ , singleton
11+ , checkValid
12+ , insert
13+ , member
14+ , delete
15+ , toList
16+ , fromList
17+ , size
18+ , union
19+ , unions
20+ , difference
2121 ) where
22-
22+
2323import Prelude
24-
25- import qualified Data.Map as M
2624
27- import Data.Maybe
28- import Data.Monoid
29- import Data.Tuple
3025import Data.Foldable (Foldable , foldMap , foldl , foldr )
31-
3226import Data.List (List (..))
33-
27+ import Data.Monoid (Monoid )
28+ import Data.Tuple (fst )
29+ import qualified Data.Map as M
30+
3431-- | `Set a` represents a set of values of type `a`
35- data Set a = Set (M.Map a Unit )
32+ data Set a = Set (M.Map a Unit )
3633
3734instance eqSet :: (Eq a ) => Eq (Set a ) where
3835 eq (Set m1) (Set m2) = m1 == m2
@@ -67,7 +64,7 @@ singleton :: forall a. a -> Set a
6764singleton a = Set (M .singleton a unit)
6865
6966-- | Check whether the underlying tree satisfies the 2-3 invariant
70- -- |
67+ -- |
7168-- | This function is provided for internal use.
7269checkValid :: forall a . Set a -> Boolean
7370checkValid (Set m) = M .checkValid m
@@ -79,11 +76,11 @@ member a (Set m) = a `M.member` m
7976-- | Insert a value into a set
8077insert :: forall a . (Ord a ) => a -> Set a -> Set a
8178insert a (Set m) = Set (M .insert a unit m)
82-
79+
8380-- | Delete a value from a set
8481delete :: forall a . (Ord a ) => a -> Set a -> Set a
8582delete a (Set m) = Set (a `M.delete` m)
86-
83+
8784-- | Convert a set to a list
8885toList :: forall a . Set a -> List a
8986toList (Set m) = map fst (M .toList m)
@@ -97,7 +94,7 @@ size :: forall a. Set a -> Int
9794size (Set m) = M .size m
9895
9996-- | Form the union of two sets
100- -- |
97+ -- |
10198-- | Running time: `O(n * log(m))`
10299union :: forall a . (Ord a ) => Set a -> Set a -> Set a
103100union (Set m1) (Set m2) = Set (m1 `M.union` m2)
0 commit comments