module Data.EnumSet.PackedEnum
{-# DEPRECATED "use Data.FlagSet instead" #-}
(T(Cons), unpack, pack, clear, put, )
where
import qualified Data.EnumBitSet as ES
import qualified Data.Bits as B
import Data.Bits (Bits, (.&.), )
data T w a b = Cons w Int
unpack ::
(Integral w, Bits w, Enum a, Enum b) =>
T w a b -> ES.T w a -> b
unpack (Cons mask pos) =
toEnum . fromIntegral . (mask .&.) .
flip B.shiftR pos . ES.decons
pack ::
(Num w, Bits w, Enum a, Enum b) =>
T w a b -> b -> ES.T w a
pack (Cons mask pos) =
ES.Cons . flip B.shiftL pos .
(mask .&.) . fromIntegral . fromEnum
clear ::
(Bits w, Enum a, Enum b) =>
T w a b -> ES.T w a -> ES.T w a
clear (Cons mask pos) =
ES.Cons . (B.complement (B.shiftL mask pos) .&.) . ES.decons
put ::
(Num w, Bits w, Enum a, Enum b) =>
T w a b -> b -> ES.T w a -> ES.T w a
put set x =
(pack set x ES..|.) . clear set