X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FUniqSet.lhs;h=6d39e00e40b7f00d279b5c1d777122106f3b0c8b;hb=9aad47f1162666431deee99884c523b1ff69cf98;hp=08d35758a58c8260d2dd2264cf59506f2fcc4fdb;hpb=206b4dec78250efef3cd927d64dc6cbc54a16c3d;p=ghc-hetmet.git diff --git a/compiler/utils/UniqSet.lhs b/compiler/utils/UniqSet.lhs index 08d3575..6d39e00 100644 --- a/compiler/utils/UniqSet.lhs +++ b/compiler/utils/UniqSet.lhs @@ -10,11 +10,13 @@ Basically, the things need to be in class @Uniquable@. \begin{code} module UniqSet ( + -- * Unique set type UniqSet, -- abstract type: NOT + -- ** Manipulating these sets mkUniqSet, uniqSetToList, emptyUniqSet, unitUniqSet, - addOneToUniqSet, addListToUniqSet, - delOneFromUniqSet, delListFromUniqSet, + addOneToUniqSet, addListToUniqSet, addOneToUniqSet_C, + delOneFromUniqSet, delListFromUniqSet, delOneFromUniqSet_Directly, unionUniqSets, unionManyUniqSets, minusUniqSet, elementOfUniqSet, mapUniqSet, intersectUniqSets, isEmptyUniqSet, filterUniqSet, sizeUniqSet, foldUniqSet, @@ -65,9 +67,17 @@ mkUniqSet xs = MkUniqSet (listToUFM [ (x, x) | x <- xs]) addOneToUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a addOneToUniqSet (MkUniqSet set) x = MkUniqSet (addToUFM set x x) +addOneToUniqSet_C :: Uniquable a + => (a -> a -> a) -> UniqSet a -> a -> UniqSet a +addOneToUniqSet_C f (MkUniqSet set) x = MkUniqSet (addToUFM_C f set x x) + delOneFromUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a delOneFromUniqSet (MkUniqSet set) x = MkUniqSet (delFromUFM set x) +delOneFromUniqSet_Directly :: Uniquable a => UniqSet a -> Unique -> UniqSet a +delOneFromUniqSet_Directly (MkUniqSet set) u + = MkUniqSet (delFromUFM_Directly set u) + delListFromUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a delListFromUniqSet (MkUniqSet set) xs = MkUniqSet (delListFromUFM set xs) @@ -110,8 +120,8 @@ hashUniqSet (MkUniqSet set) = hashUFM set isEmptyUniqSet :: UniqSet a -> Bool isEmptyUniqSet (MkUniqSet set) = isNullUFM set {-SLOW: sizeUFM set == 0-} -mapUniqSet :: (a -> a) -> UniqSet a -> UniqSet a - -- VERY IMPORTANT: *assumes* that the function doesn't change the unique +-- | Invariant: the mapping function doesn't change the unique +mapUniqSet :: (a -> b) -> UniqSet a -> UniqSet b mapUniqSet f (MkUniqSet set) = MkUniqSet (mapUFM f set) \end{code}