/compiler/Eta/Utils/UniqDSet.hs

https://github.com/typelead/eta · Haskell · 106 lines · 69 code · 27 blank · 10 comment · 0 complexity · c1e894758bf67aee20c045c14f17cb9d MD5 · raw file

  1. -- (c) Bartosz Nitka, Facebook, 2015
  2. -- |
  3. -- Specialised deterministic sets, for things with @Uniques@
  4. --
  5. -- Based on @UniqDFMs@ (as you would expect).
  6. -- See Note [Deterministic UniqFM] in UniqDFM for explanation why we need it.
  7. --
  8. -- Basically, the things need to be in class @Uniquable@.
  9. module Eta.Utils.UniqDSet (
  10. -- * Unique set type
  11. UniqDSet, -- type synonym for UniqFM a
  12. -- ** Manipulating these sets
  13. delOneFromUniqDSet, delListFromUniqDSet,
  14. emptyUniqDSet,
  15. unitUniqDSet,
  16. mkUniqDSet,
  17. addOneToUniqDSet, addListToUniqDSet,
  18. unionUniqDSets, unionManyUniqDSets,
  19. minusUniqDSet, uniqDSetMinusUniqSet,
  20. intersectUniqDSets,
  21. intersectsUniqDSets, uniqDSetIntersectUniqSet,
  22. foldUniqDSet,
  23. elementOfUniqDSet,
  24. filterUniqDSet,
  25. sizeUniqDSet,
  26. isEmptyUniqDSet,
  27. lookupUniqDSet,
  28. uniqDSetToList,
  29. partitionUniqDSet
  30. ) where
  31. import Eta.Utils.UniqDFM
  32. import Eta.Utils.UniqSet
  33. import Eta.BasicTypes.Unique
  34. type UniqDSet a = UniqDFM a
  35. emptyUniqDSet :: UniqDSet a
  36. emptyUniqDSet = emptyUDFM
  37. unitUniqDSet :: Uniquable a => a -> UniqDSet a
  38. unitUniqDSet x = unitUDFM x x
  39. mkUniqDSet :: Uniquable a => [a] -> UniqDSet a
  40. mkUniqDSet = foldl addOneToUniqDSet emptyUniqDSet
  41. addOneToUniqDSet :: Uniquable a => UniqDSet a -> a -> UniqDSet a
  42. addOneToUniqDSet set x = addToUDFM set x x
  43. addListToUniqDSet :: Uniquable a => UniqDSet a -> [a] -> UniqDSet a
  44. addListToUniqDSet = foldl addOneToUniqDSet
  45. delOneFromUniqDSet :: Uniquable a => UniqDSet a -> a -> UniqDSet a
  46. delOneFromUniqDSet = delFromUDFM
  47. delListFromUniqDSet :: Uniquable a => UniqDSet a -> [a] -> UniqDSet a
  48. delListFromUniqDSet = delListFromUDFM
  49. unionUniqDSets :: UniqDSet a -> UniqDSet a -> UniqDSet a
  50. unionUniqDSets = plusUDFM
  51. unionManyUniqDSets :: [UniqDSet a] -> UniqDSet a
  52. unionManyUniqDSets [] = emptyUniqDSet
  53. unionManyUniqDSets sets = foldr1 unionUniqDSets sets
  54. minusUniqDSet :: UniqDSet a -> UniqDSet a -> UniqDSet a
  55. minusUniqDSet = minusUDFM
  56. uniqDSetMinusUniqSet :: UniqDSet a -> UniqSet a -> UniqDSet a
  57. uniqDSetMinusUniqSet xs ys = udfmMinusUFM xs (getUniqSet ys)
  58. intersectUniqDSets :: UniqDSet a -> UniqDSet a -> UniqDSet a
  59. intersectUniqDSets = intersectUDFM
  60. uniqDSetIntersectUniqSet :: UniqDSet a -> UniqSet b -> UniqDSet a
  61. uniqDSetIntersectUniqSet xs ys = xs `udfmIntersectUFM` getUniqSet ys
  62. intersectsUniqDSets :: UniqDSet a -> UniqDSet a -> Bool
  63. intersectsUniqDSets = intersectsUDFM
  64. foldUniqDSet :: (a -> b -> b) -> b -> UniqDSet a -> b
  65. foldUniqDSet = foldUDFM
  66. elementOfUniqDSet :: Uniquable a => a -> UniqDSet a -> Bool
  67. elementOfUniqDSet = elemUDFM
  68. filterUniqDSet :: (a -> Bool) -> UniqDSet a -> UniqDSet a
  69. filterUniqDSet = filterUDFM
  70. sizeUniqDSet :: UniqDSet a -> Int
  71. sizeUniqDSet = sizeUDFM
  72. isEmptyUniqDSet :: UniqDSet a -> Bool
  73. isEmptyUniqDSet = isNullUDFM
  74. lookupUniqDSet :: Uniquable a => UniqDSet a -> a -> Maybe a
  75. lookupUniqDSet = lookupUDFM
  76. uniqDSetToList :: UniqDSet a -> [a]
  77. uniqDSetToList = eltsUDFM
  78. partitionUniqDSet :: (a -> Bool) -> UniqDSet a -> (UniqDSet a, UniqDSet a)
  79. partitionUniqDSet = partitionUDFM