PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/compiler/utils/UniqSet.lhs

http://github.com/ghc/ghc
Haskell | 118 lines | 94 code | 22 blank | 2 comment | 1 complexity | bb842dc35e7ec6c18c8c3df6626cfa2f MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, GPL-3.0
  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. module UniqSet (
  10. -- * Unique set type
  11. UniqSet, -- type synonym for UniqFM a
  12. -- ** Manipulating these sets
  13. emptyUniqSet,
  14. unitUniqSet,
  15. mkUniqSet,
  16. addOneToUniqSet, addOneToUniqSet_C, addListToUniqSet,
  17. delOneFromUniqSet, delOneFromUniqSet_Directly, delListFromUniqSet,
  18. unionUniqSets, unionManyUniqSets,
  19. minusUniqSet,
  20. intersectUniqSets,
  21. foldUniqSet,
  22. mapUniqSet,
  23. elementOfUniqSet,
  24. elemUniqSet_Directly,
  25. filterUniqSet,
  26. sizeUniqSet,
  27. isEmptyUniqSet,
  28. lookupUniqSet,
  29. uniqSetToList,
  30. partitionUniqSet
  31. ) where
  32. import UniqFM
  33. import Unique
  34. \end{code}
  35. %************************************************************************
  36. %* *
  37. \subsection{The signature of the module}
  38. %* *
  39. %************************************************************************
  40. \begin{code}
  41. emptyUniqSet :: UniqSet a
  42. unitUniqSet :: Uniquable a => a -> UniqSet a
  43. mkUniqSet :: Uniquable a => [a] -> UniqSet a
  44. addOneToUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
  45. addOneToUniqSet_C :: Uniquable a => (a -> a -> a) -> UniqSet a -> a -> UniqSet a
  46. addListToUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
  47. delOneFromUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
  48. delOneFromUniqSet_Directly :: Uniquable a => UniqSet a -> Unique -> UniqSet a
  49. delListFromUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
  50. unionUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
  51. unionManyUniqSets :: [UniqSet a] -> UniqSet a
  52. minusUniqSet :: UniqSet a -> UniqSet a -> UniqSet a
  53. intersectUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
  54. foldUniqSet :: (a -> b -> b) -> b -> UniqSet a -> b
  55. mapUniqSet :: (a -> b) -> UniqSet a -> UniqSet b
  56. elementOfUniqSet :: Uniquable a => a -> UniqSet a -> Bool
  57. elemUniqSet_Directly :: Unique -> UniqSet a -> Bool
  58. filterUniqSet :: (a -> Bool) -> UniqSet a -> UniqSet a
  59. partitionUniqSet :: (a -> Bool) -> UniqSet a -> (UniqSet a, UniqSet a)
  60. sizeUniqSet :: UniqSet a -> Int
  61. isEmptyUniqSet :: UniqSet a -> Bool
  62. lookupUniqSet :: Uniquable a => UniqSet a -> a -> Maybe a
  63. uniqSetToList :: UniqSet a -> [a]
  64. \end{code}
  65. %************************************************************************
  66. %* *
  67. \subsection{Implementation using ``UniqFM''}
  68. %* *
  69. %************************************************************************
  70. \begin{code}
  71. type UniqSet a = UniqFM a
  72. emptyUniqSet = emptyUFM
  73. unitUniqSet x = unitUFM x x
  74. mkUniqSet = foldl addOneToUniqSet emptyUniqSet
  75. addOneToUniqSet set x = addToUFM set x x
  76. addOneToUniqSet_C f set x = addToUFM_C f set x x
  77. addListToUniqSet = foldl addOneToUniqSet
  78. delOneFromUniqSet = delFromUFM
  79. delOneFromUniqSet_Directly = delFromUFM_Directly
  80. delListFromUniqSet = delListFromUFM
  81. unionUniqSets = plusUFM
  82. unionManyUniqSets [] = emptyUniqSet
  83. unionManyUniqSets sets = foldr1 unionUniqSets sets
  84. minusUniqSet = minusUFM
  85. intersectUniqSets = intersectUFM
  86. foldUniqSet = foldUFM
  87. mapUniqSet = mapUFM
  88. elementOfUniqSet = elemUFM
  89. elemUniqSet_Directly = elemUFM_Directly
  90. filterUniqSet = filterUFM
  91. partitionUniqSet = partitionUFM
  92. sizeUniqSet = sizeUFM
  93. isEmptyUniqSet = isNullUFM
  94. lookupUniqSet = lookupUFM
  95. uniqSetToList = eltsUFM
  96. \end{code}