Basically, the things need to be in class @Uniquable@.
\begin{code}
-{-# OPTIONS -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
--- http://hackage.haskell.org/trac/ghc/wiki/CodingStyle#Warnings
--- for details
-
module UniqSet (
- UniqSet, -- abstract type: NOT
-
- mkUniqSet, uniqSetToList, emptyUniqSet, unitUniqSet,
- addOneToUniqSet, addListToUniqSet, delOneFromUniqSet, delListFromUniqSet,
- unionUniqSets, unionManyUniqSets, minusUniqSet,
- elementOfUniqSet, mapUniqSet, intersectUniqSets,
- isEmptyUniqSet, filterUniqSet, sizeUniqSet, foldUniqSet,
- elemUniqSet_Directly, lookupUniqSet, hashUniqSet
+ -- * Unique set type
+ UniqSet, -- abstract type: NOT
+
+ -- ** Manipulating these sets
+ mkUniqSet, uniqSetToList, emptyUniqSet, unitUniqSet,
+ addOneToUniqSet, addListToUniqSet, addOneToUniqSet_C,
+ delOneFromUniqSet, delListFromUniqSet, delOneFromUniqSet_Directly,
+ unionUniqSets, unionManyUniqSets, minusUniqSet,
+ elementOfUniqSet, mapUniqSet, intersectUniqSets,
+ isEmptyUniqSet, filterUniqSet, sizeUniqSet, foldUniqSet,
+ elemUniqSet_Directly, lookupUniqSet, hashUniqSet
) where
-#include "HsVersions.h"
-
-import Maybes ( maybeToBool )
+import Maybes
import UniqFM
-import Unique ( Unique, Uniquable(..) )
+import Unique
#if ! OMIT_NATIVE_CODEGEN
#define IF_NCG(a) a
\end{code}
%************************************************************************
-%* *
+%* *
\subsection{The @UniqSet@ type}
-%* *
+%* *
%************************************************************************
We use @UniqFM@, with a (@getUnique@-able) @Unique@ as ``key''
uniqSetToList (MkUniqSet set) = eltsUFM set
foldUniqSet :: (a -> b -> b) -> b -> UniqSet a -> b
-foldUniqSet k z (MkUniqSet set) = foldUFM k z set
+foldUniqSet k z (MkUniqSet set) = foldUFM k z set
mkUniqSet :: Uniquable a => [a] -> UniqSet a
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)
unionUniqSets (MkUniqSet set1) (MkUniqSet set2) = MkUniqSet (plusUFM set1 set2)
unionManyUniqSets :: [UniqSet a] -> UniqSet a
- -- = foldr unionUniqSets emptyUniqSet ss
-unionManyUniqSets [] = emptyUniqSet
-unionManyUniqSets [s] = s
+-- = foldr unionUniqSets emptyUniqSet ss
+unionManyUniqSets [] = emptyUniqSet
+unionManyUniqSets [s] = s
unionManyUniqSets (s:ss) = s `unionUniqSets` unionManyUniqSets ss
minusUniqSet :: UniqSet a -> UniqSet a -> UniqSet a
isEmptyUniqSet :: UniqSet a -> Bool
isEmptyUniqSet (MkUniqSet set) = isNullUFM set {-SLOW: sizeUFM set == 0-}
+-- | Invariant: the mapping function doesn't change the unique
mapUniqSet :: (a -> a) -> UniqSet a -> UniqSet a
- -- VERY IMPORTANT: *assumes* that the function doesn't change the unique
mapUniqSet f (MkUniqSet set) = MkUniqSet (mapUFM f set)
\end{code}
\begin{code}
-#if __GLASGOW_HASKELL__
+#ifdef __GLASGOW_HASKELL__
{-# SPECIALIZE
addOneToUniqSet :: UniqSet Unique -> Unique -> UniqSet Unique
#-}
{- SPECIALIZE
elementOfUniqSet :: Name -> UniqSet Name -> Bool
- , Unique -> UniqSet Unique -> Bool
+ , Unique -> UniqSet Unique -> Bool
-}
{- SPECIALIZE
mkUniqSet :: [Name] -> UniqSet Name
{- SPECIALIZE
unitUniqSet :: Name -> UniqSet Name
- , Unique -> UniqSet Unique
+ , Unique -> UniqSet Unique
-}
#endif
\end{code}