2 % (c) The University of Glasgow 2006
3 % (c) The AQUA Project, Glasgow University, 1994-1998
5 \section[UniqSet]{Specialised sets, for things with @Uniques@}
7 Based on @UniqFMs@ (as you would expect).
9 Basically, the things need to be in class @Uniquable@.
14 UniqSet, -- type synonym for UniqFM a
16 -- ** Manipulating these sets
20 addOneToUniqSet, addOneToUniqSet_C, addListToUniqSet,
21 delOneFromUniqSet, delOneFromUniqSet_Directly, delListFromUniqSet,
22 unionUniqSets, unionManyUniqSets,
41 %************************************************************************
43 \subsection{The signature of the module}
45 %************************************************************************
48 emptyUniqSet :: UniqSet a
49 unitUniqSet :: Uniquable a => a -> UniqSet a
50 mkUniqSet :: Uniquable a => [a] -> UniqSet a
52 addOneToUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
53 addOneToUniqSet_C :: Uniquable a => (a -> a -> a) -> UniqSet a -> a -> UniqSet a
54 addListToUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
56 delOneFromUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
57 delOneFromUniqSet_Directly :: Uniquable a => UniqSet a -> Unique -> UniqSet a
58 delListFromUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
60 unionUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
61 unionManyUniqSets :: [UniqSet a] -> UniqSet a
62 minusUniqSet :: UniqSet a -> UniqSet a -> UniqSet a
63 intersectUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
65 foldUniqSet :: (a -> b -> b) -> b -> UniqSet a -> b
66 mapUniqSet :: (a -> b) -> UniqSet a -> UniqSet b
67 elementOfUniqSet :: Uniquable a => a -> UniqSet a -> Bool
68 elemUniqSet_Directly :: Unique -> UniqSet a -> Bool
69 filterUniqSet :: (a -> Bool) -> UniqSet a -> UniqSet a
71 sizeUniqSet :: UniqSet a -> Int
72 isEmptyUniqSet :: UniqSet a -> Bool
73 lookupUniqSet :: Uniquable a => UniqSet a -> a -> Maybe a
74 uniqSetToList :: UniqSet a -> [a]
76 %************************************************************************
78 \subsection{Implementation using ``UniqFM''}
80 %************************************************************************
84 type UniqSet a = UniqFM a
86 emptyUniqSet = emptyUFM
87 unitUniqSet x = unitUFM x x
88 mkUniqSet = foldl addOneToUniqSet emptyUniqSet
90 addOneToUniqSet set x = addToUFM set x x
91 addOneToUniqSet_C f set x = addToUFM_C f set x x
92 addListToUniqSet = foldl addOneToUniqSet
94 delOneFromUniqSet = delFromUFM
95 delOneFromUniqSet_Directly = delFromUFM_Directly
96 delListFromUniqSet = delListFromUFM
98 unionUniqSets = plusUFM
99 unionManyUniqSets [] = emptyUniqSet
100 unionManyUniqSets sets = foldr1 unionUniqSets sets
101 minusUniqSet = minusUFM
102 intersectUniqSets = intersectUFM
104 foldUniqSet = foldUFM
106 elementOfUniqSet = elemUFM
107 elemUniqSet_Directly = elemUFM_Directly
108 filterUniqSet = filterUFM
110 sizeUniqSet = sizeUFM
111 isEmptyUniqSet = isNullUFM
112 lookupUniqSet = lookupUFM
113 uniqSetToList = eltsUFM