PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/ghc-7.0.4/compiler/utils/UniqSet.lhs

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