#include "HsVersions.h"
module UniqSet (
- UniqSet(..), -- abstract type: NOT
+ SYN_IE(UniqSet), -- abstract type: NOT
mkUniqSet, uniqSetToList, emptyUniqSet, unitUniqSet,
- addOneToUniqSet,
+ addOneToUniqSet, addListToUniqSet,
unionUniqSets, unionManyUniqSets, minusUniqSet,
elementOfUniqSet, mapUniqSet, intersectUniqSets,
- isEmptyUniqSet
+ isEmptyUniqSet, filterUniqSet, sizeUniqSet
) where
-import Ubiq{-uitous-}
+IMPORT_DELOOPER( SpecLoop )
-import Maybes ( maybeToBool, Maybe )
+import Maybes ( maybeToBool )
import UniqFM
import Unique ( Unique )
---import Outputable ( Outputable(..), ExportFlag )
import SrcLoc ( SrcLoc )
-import Pretty ( Pretty(..), PrettyRep )
+import Outputable ( Outputable(..) )
+import Pretty ( Doc )
import PprStyle ( PprStyle )
import Util ( Ord3(..) )
mkUniqSet xs = MkUniqSet (listToUFM [ (x, x) | x <- xs])
addOneToUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
-addOneToUniqSet set x = set `unionUniqSets` unitUniqSet x
+addOneToUniqSet (MkUniqSet set) x = MkUniqSet (addToUFM set x x)
+
+addListToUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
+addListToUniqSet (MkUniqSet set) xs = MkUniqSet (addListToUFM set [(x,x) | x<-xs])
unionUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
unionUniqSets (MkUniqSet set1) (MkUniqSet set2) = MkUniqSet (plusUFM set1 set2)
minusUniqSet :: UniqSet a -> UniqSet a -> UniqSet a
minusUniqSet (MkUniqSet set1) (MkUniqSet set2) = MkUniqSet (minusUFM set1 set2)
+filterUniqSet :: (a -> Bool) -> UniqSet a -> UniqSet a
+filterUniqSet pred (MkUniqSet set) = MkUniqSet (filterUFM pred set)
+
intersectUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
intersectUniqSets (MkUniqSet set1) (MkUniqSet set2) = MkUniqSet (intersectUFM set1 set2)
elementOfUniqSet :: Uniquable a => a -> UniqSet a -> Bool
elementOfUniqSet x (MkUniqSet set) = maybeToBool (lookupUFM set x)
+sizeUniqSet :: UniqSet a -> Int
+sizeUniqSet (MkUniqSet set) = sizeUFM set
+
isEmptyUniqSet :: UniqSet a -> Bool
isEmptyUniqSet (MkUniqSet set) = isNullUFM set {-SLOW: sizeUFM set == 0-}
| thing <- eltsUFM set ])
\end{code}
-%************************************************************************
-%* *
-\subsection{The @IdSet@ and @TyVarSet@ specialisations for sets of Ids/TyVars}
-%* *
-%************************************************************************
-
-@IdSet@ is a specialised version, optimised for sets of Ids.
-
\begin{code}
---type NameSet = UniqSet Name
---type GenTyVarSet flexi = UniqSet (GenTyVar flexi)
---type GenIdSet ty = UniqSet (GenId ty)
-
-#if ! OMIT_NATIVE_CODEGEN
---type RegSet = UniqSet Reg
-#endif
-
-#if 0
#if __GLASGOW_HASKELL__
{-# SPECIALIZE
- unitUniqSet :: GenId ty -> GenIdSet ty,
- GenTyVar flexi -> GenTyVarSet flexi,
- Name -> NameSet
- IF_NCG(COMMA Reg -> RegSet)
+ addOneToUniqSet :: UniqSet Unique -> Unique -> UniqSet Unique
#-}
-
{-# SPECIALIZE
- mkUniqSet :: [GenId ty] -> GenIdSet ty,
- [GenTyVar flexi] -> GenTyVarSet flexi,
- [Name] -> NameSet
- IF_NCG(COMMA [Reg] -> RegSet)
+ elementOfUniqSet :: Name -> UniqSet Name -> Bool
+ , Unique -> UniqSet Unique -> Bool
#-}
-
{-# SPECIALIZE
- elementOfUniqSet :: GenId ty -> GenIdSet ty -> Bool,
- GenTyVar flexi -> GenTyVarSet flexi -> Bool,
- Name -> NameSet -> Bool
- IF_NCG(COMMA Reg -> RegSet -> Bool)
+ mkUniqSet :: [Name] -> UniqSet Name
#-}
{-# SPECIALIZE
- mapUniqSet :: (GenId ty -> GenId ty) -> GenIdSet ty -> GenIdSet ty,
- (GenTyVar flexi -> GenTyVar flexi) -> GenTyVarSet flexi -> GenTyVarSet flexi,
- (Name -> Name) -> NameSet -> NameSet
- IF_NCG(COMMA (Reg -> Reg) -> RegSet -> RegSet)
+ unitUniqSet :: Name -> UniqSet Name
+ , Unique -> UniqSet Unique
#-}
#endif
-#endif
\end{code}