-- | Sets of places
module PlaceSet
( PlaceSet
, listToPlaceSet
, placeSetToList
, singleton
, empty
, nullPS
, insert
, delete
, member
, size
, (\\)
, unions
, intersection
, disjunct
, isSubsetOf
-- * Useful functions
, places
) where
import Place
import qualified Data.IntSet as S
-------------
-- | Set of places.
type PlaceSet = S.IntSet
listToPlaceSet :: [Place] -> PlaceSet
listToPlaceSet = S.fromList . map hashPlace
placeSetToList :: PlaceSet -> [Place]
placeSetToList = map unHashPlace . S.toList
singleton :: Place -> PlaceSet
singleton = S.singleton . hashPlace
-- | The empty PlaceSet.
empty :: PlaceSet
empty = S.empty
insert :: Place -> PlaceSet -> PlaceSet
insert p ps = S.insert (hashPlace p) ps
delete :: Place -> PlaceSet -> PlaceSet
delete p ps = S.delete (hashPlace p) ps
-- | True if the PlaceSet is empty.
nullPS :: PlaceSet -> Bool
nullPS = S.null
member :: Place -> PlaceSet -> Bool
member p = S.member (hashPlace p)
size :: PlaceSet -> Int
size = S.size
-- | Difference.
(\\) :: PlaceSet -> PlaceSet -> PlaceSet
(\\) = (S.\\)
unions :: [PlaceSet] -> PlaceSet
unions = S.unions
disjunct :: PlaceSet -> PlaceSet -> Bool
disjunct a b = S.null (S.intersection a b)
intersection :: PlaceSet -> PlaceSet -> PlaceSet
intersection = S.intersection
isSubsetOf :: PlaceSet -> PlaceSet -> Bool
isSubsetOf = S.isSubsetOf
----------------------
-- | All places at a board.
places :: Size -> PlaceSet
places (xS, yS) = listToPlaceSet [p | x<-[1..xS], p <- placesInAColumn x (1, yS)]