PageRenderTime 163ms CodeModel.GetById 121ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/compiler/utils/UniqSet.lhs

https://bitbucket.org/carter/ghc
Haskell | 122 lines | 91 code | 23 blank | 8 comment | 1 complexity | 823366f92adda0a58e5d4fcba24e99eb MD5 | raw file
  1%
  2% (c) The University of Glasgow 2006
  3% (c) The AQUA Project, Glasgow University, 1994-1998
  4%
  5\section[UniqSet]{Specialised sets, for things with @Uniques@}
  6
  7Based on @UniqFMs@ (as you would expect).
  8
  9Basically, the things need to be in class @Uniquable@.
 10
 11\begin{code}
 12{-# OPTIONS -fno-warn-tabs #-}
 13-- The above warning supression flag is a temporary kludge.
 14-- While working on this module you are encouraged to remove it and
 15-- detab the module (please do the detabbing in a separate patch). See
 16--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
 17-- for details
 18
 19module UniqSet (
 20        -- * Unique set type
 21        UniqSet,    -- type synonym for UniqFM a
 22
 23        -- ** Manipulating these sets
 24        emptyUniqSet,
 25        unitUniqSet,
 26        mkUniqSet,
 27        addOneToUniqSet, addOneToUniqSet_C, addListToUniqSet,
 28        delOneFromUniqSet, delOneFromUniqSet_Directly, delListFromUniqSet,
 29        unionUniqSets, unionManyUniqSets,
 30        minusUniqSet,
 31        intersectUniqSets,
 32        foldUniqSet,
 33        mapUniqSet,
 34        elementOfUniqSet,
 35        elemUniqSet_Directly,
 36        filterUniqSet,
 37        sizeUniqSet,
 38        isEmptyUniqSet,
 39        lookupUniqSet,
 40        uniqSetToList,
 41    ) where
 42
 43import UniqFM
 44import Unique
 45
 46\end{code}
 47
 48%************************************************************************
 49%*									*
 50\subsection{The signature of the module}
 51%*									*
 52%************************************************************************
 53
 54\begin{code}
 55emptyUniqSet :: UniqSet a
 56unitUniqSet :: Uniquable a => a -> UniqSet a
 57mkUniqSet :: Uniquable a => [a]  -> UniqSet a
 58
 59addOneToUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
 60addOneToUniqSet_C :: Uniquable a => (a -> a -> a) -> UniqSet a -> a -> UniqSet a
 61addListToUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
 62
 63delOneFromUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
 64delOneFromUniqSet_Directly :: Uniquable a => UniqSet a -> Unique -> UniqSet a
 65delListFromUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
 66
 67unionUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
 68unionManyUniqSets :: [UniqSet a] -> UniqSet a
 69minusUniqSet  :: UniqSet a -> UniqSet a -> UniqSet a
 70intersectUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
 71
 72foldUniqSet :: (a -> b -> b) -> b -> UniqSet a -> b
 73mapUniqSet :: (a -> b) -> UniqSet a -> UniqSet b
 74elementOfUniqSet :: Uniquable a => a -> UniqSet a -> Bool
 75elemUniqSet_Directly :: Unique -> UniqSet a -> Bool
 76filterUniqSet :: (a -> Bool) -> UniqSet a -> UniqSet a
 77
 78sizeUniqSet :: UniqSet a -> Int
 79isEmptyUniqSet :: UniqSet a -> Bool
 80lookupUniqSet :: Uniquable a => UniqSet a -> a -> Maybe a
 81uniqSetToList :: UniqSet a -> [a]
 82\end{code}
 83%************************************************************************
 84%*                                                                      *
 85\subsection{Implementation using ``UniqFM''}
 86%*                                                                      *
 87%************************************************************************
 88
 89\begin{code}
 90
 91type UniqSet a = UniqFM a
 92
 93emptyUniqSet = emptyUFM
 94unitUniqSet x = unitUFM x x
 95mkUniqSet = foldl addOneToUniqSet emptyUniqSet
 96
 97addOneToUniqSet set x = addToUFM set x x
 98addOneToUniqSet_C f set x = addToUFM_C f set x x
 99addListToUniqSet = foldl addOneToUniqSet
100
101delOneFromUniqSet = delFromUFM
102delOneFromUniqSet_Directly = delFromUFM_Directly
103delListFromUniqSet = delListFromUFM
104
105unionUniqSets = plusUFM
106unionManyUniqSets [] = emptyUniqSet
107unionManyUniqSets sets = foldr1 unionUniqSets sets
108minusUniqSet = minusUFM
109intersectUniqSets = intersectUFM
110
111foldUniqSet = foldUFM
112mapUniqSet = mapUFM
113elementOfUniqSet = elemUFM
114elemUniqSet_Directly = elemUFM_Directly
115filterUniqSet = filterUFM
116
117sizeUniqSet = sizeUFM
118isEmptyUniqSet = isNullUFM
119lookupUniqSet = lookupUFM
120uniqSetToList = eltsUFM
121
122\end{code}