PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/compiler/utils/UniqSet.lhs

http://github.com/ilyasergey/GHC-XAppFix
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. Based on @UniqFMs@ (as you would expect).
  7. Basically, the things need to be in class @Uniquable@.
  8. \begin{code}
  9. {-# OPTIONS -fno-warn-tabs #-}
  10. -- The above warning supression flag is a temporary kludge.
  11. -- While working on this module you are encouraged to remove it and
  12. -- detab the module (please do the detabbing in a separate patch). See
  13. -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
  14. -- for details
  15. module UniqSet (
  16. -- * Unique set type
  17. UniqSet, -- type synonym for UniqFM a
  18. -- ** Manipulating these sets
  19. emptyUniqSet,
  20. unitUniqSet,
  21. mkUniqSet,
  22. addOneToUniqSet, addOneToUniqSet_C, addListToUniqSet,
  23. delOneFromUniqSet, delOneFromUniqSet_Directly, delListFromUniqSet,
  24. unionUniqSets, unionManyUniqSets,
  25. minusUniqSet,
  26. intersectUniqSets,
  27. foldUniqSet,
  28. mapUniqSet,
  29. elementOfUniqSet,
  30. elemUniqSet_Directly,
  31. filterUniqSet,
  32. sizeUniqSet,
  33. isEmptyUniqSet,
  34. lookupUniqSet,
  35. uniqSetToList,
  36. ) where
  37. import UniqFM
  38. import Unique
  39. \end{code}
  40. %************************************************************************
  41. %* *
  42. \subsection{The signature of the module}
  43. %* *
  44. %************************************************************************
  45. \begin{code}
  46. emptyUniqSet :: UniqSet a
  47. unitUniqSet :: Uniquable a => a -> UniqSet a
  48. mkUniqSet :: Uniquable a => [a] -> UniqSet a
  49. addOneToUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
  50. addOneToUniqSet_C :: Uniquable a => (a -> a -> a) -> UniqSet a -> a -> UniqSet a
  51. addListToUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
  52. delOneFromUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
  53. delOneFromUniqSet_Directly :: Uniquable a => UniqSet a -> Unique -> UniqSet a
  54. delListFromUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
  55. unionUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
  56. unionManyUniqSets :: [UniqSet a] -> UniqSet a
  57. minusUniqSet :: UniqSet a -> UniqSet a -> UniqSet a
  58. intersectUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
  59. foldUniqSet :: (a -> b -> b) -> b -> UniqSet a -> b
  60. mapUniqSet :: (a -> b) -> UniqSet a -> UniqSet b
  61. elementOfUniqSet :: Uniquable a => a -> UniqSet a -> Bool
  62. elemUniqSet_Directly :: Unique -> UniqSet a -> Bool
  63. filterUniqSet :: (a -> Bool) -> UniqSet a -> UniqSet a
  64. sizeUniqSet :: UniqSet a -> Int
  65. isEmptyUniqSet :: UniqSet a -> Bool
  66. lookupUniqSet :: Uniquable a => UniqSet a -> a -> Maybe a
  67. uniqSetToList :: UniqSet a -> [a]
  68. \end{code}
  69. %************************************************************************
  70. %* *
  71. \subsection{Implementation using ``UniqFM''}
  72. %* *
  73. %************************************************************************
  74. \begin{code}
  75. type UniqSet a = UniqFM a
  76. emptyUniqSet = emptyUFM
  77. unitUniqSet x = unitUFM x x
  78. mkUniqSet = foldl addOneToUniqSet emptyUniqSet
  79. addOneToUniqSet set x = addToUFM set x x
  80. addOneToUniqSet_C f set x = addToUFM_C f set x x
  81. addListToUniqSet = foldl addOneToUniqSet
  82. delOneFromUniqSet = delFromUFM
  83. delOneFromUniqSet_Directly = delFromUFM_Directly
  84. delListFromUniqSet = delListFromUFM
  85. unionUniqSets = plusUFM
  86. unionManyUniqSets [] = emptyUniqSet
  87. unionManyUniqSets sets = foldr1 unionUniqSets sets
  88. minusUniqSet = minusUFM
  89. intersectUniqSets = intersectUFM
  90. foldUniqSet = foldUFM
  91. mapUniqSet = mapUFM
  92. elementOfUniqSet = elemUFM
  93. elemUniqSet_Directly = elemUFM_Directly
  94. filterUniqSet = filterUFM
  95. sizeUniqSet = sizeUFM
  96. isEmptyUniqSet = isNullUFM
  97. lookupUniqSet = lookupUFM
  98. uniqSetToList = eltsUFM
  99. \end{code}