2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section{@VarSet@: Variable sets}
8 VarSet, IdSet, TyVarSet,
9 emptyVarSet, unitVarSet, mkVarSet,
10 extendVarSet, extendVarSet_C,
11 elemVarSet, varSetElems, subVarSet,
12 unionVarSet, unionVarSets,
13 intersectVarSet, intersectsVarSet,
14 isEmptyVarSet, delVarSet, delVarSetByKey,
15 minusVarSet, foldVarSet, filterVarSet,
16 lookupVarSet, mapVarSet, sizeVarSet, seqVarSet
19 #include "HsVersions.h"
21 import Var ( Var, Id, TyVar )
22 import Unique ( Unique )
24 import UniqFM ( delFromUFM_Directly, addToUFM_C )
27 %************************************************************************
29 \subsection{@VarSet@s}
31 %************************************************************************
34 type VarSet = UniqSet Var
35 type IdSet = UniqSet Id
36 type TyVarSet = UniqSet TyVar
39 intersectVarSet :: VarSet -> VarSet -> VarSet
40 unionVarSet :: VarSet -> VarSet -> VarSet
41 unionVarSets :: [VarSet] -> VarSet
42 varSetElems :: VarSet -> [Var]
43 unitVarSet :: Var -> VarSet
44 extendVarSet :: VarSet -> Var -> VarSet
45 elemVarSet :: Var -> VarSet -> Bool
46 delVarSet :: VarSet -> Var -> VarSet
47 minusVarSet :: VarSet -> VarSet -> VarSet
48 isEmptyVarSet :: VarSet -> Bool
49 mkVarSet :: [Var] -> VarSet
50 foldVarSet :: (Var -> a -> a) -> a -> VarSet -> a
51 lookupVarSet :: VarSet -> Var -> Maybe Var
52 -- Returns the set element, which may be
53 -- (==) to the argument, but not the same as
54 mapVarSet :: (Var -> Var) -> VarSet -> VarSet
55 sizeVarSet :: VarSet -> Int
56 filterVarSet :: (Var -> Bool) -> VarSet -> VarSet
57 extendVarSet_C :: (Var->Var->Var) -> VarSet -> Var -> VarSet
59 delVarSetByKey :: VarSet -> Unique -> VarSet
61 emptyVarSet = emptyUniqSet
62 unitVarSet = unitUniqSet
63 extendVarSet = addOneToUniqSet
64 intersectVarSet = intersectUniqSets
66 intersectsVarSet:: VarSet -> VarSet -> Bool -- True if non-empty intersection
67 -- (s1 `intersectsVarSet` s2) doesn't compute s2 if s1 is empty
68 subVarSet :: VarSet -> VarSet -> Bool -- True if first arg is subset of second
69 -- (s1 `subVarSet` s2) doesn't compute s2 if s1 is empty
71 unionVarSet = unionUniqSets
72 unionVarSets = unionManyUniqSets
73 varSetElems = uniqSetToList
74 elemVarSet = elementOfUniqSet
75 minusVarSet = minusUniqSet
76 delVarSet = delOneFromUniqSet
77 isEmptyVarSet = isEmptyUniqSet
79 foldVarSet = foldUniqSet
80 lookupVarSet = lookupUniqSet
81 mapVarSet = mapUniqSet
82 sizeVarSet = sizeUniqSet
83 filterVarSet = filterUniqSet
84 extendVarSet_C combine s x = addToUFM_C combine s x x
85 delVarSetByKey = delFromUFM_Directly -- Can't be bothered to add this to UniqSet
89 -- See comments with type signatures
90 intersectsVarSet s1 s2 = not (isEmptyVarSet (s1 `intersectVarSet` s2))
91 a `subVarSet` b = isEmptyVarSet (a `minusVarSet` b)
95 seqVarSet :: VarSet -> ()
96 seqVarSet s = sizeVarSet s `seq` ()