-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Sets of enumeration values represented by machine words -- -- With this package you can create a type safe interface to flag sets. -- It is intended for interfacing to C libraries via FFI, where Word8, -- Word16, or Word32 types are commonly used to store bit vectors. E.g. -- the type EnumSet Word16 Ordering represents a flag set stored -- in a Word16 that supports the flags LT, EQ, -- GT. -- -- This package is similar to the bitset package and the -- Data.Edison.Coll.EnumSet module in the edison -- package, however our implementation allows you to choose the embedding -- type and thus the maximum size of the set. @package enumset @version 0.0.3 -- | A bit vector that represents a record in a bit-packed way. module Data.FlagSet -- | The basic bit vector data type. It does not provide a lot of -- functionality, since that could not be done in a safe way. -- -- The type a identifies the maintained flags. It may be an -- empty type but it may also be an enumeration of record fields with -- concrete values. In the latter case you are encouraged to define an -- Enum instance for this enumeration. Be aware that it is -- different from Enum of Prelude. newtype T word a Cons :: word -> T word a decons :: T word a -> word fromMaskedValue :: MaskedValue w a -> T w a match :: Bits w => T w a -> MaskedValue w a -> Bool class Enum a fromEnum :: (Enum a, Bits w) => a -> MaskedValue w a -- | Compose a flag set from a list of flags. However you may prefer to -- assemble flags using mconcat or mappend on -- MaskedValues. compose :: (Enum a, Enum a, Bits w) => [a] -> T w a -- | Decompose a flag set into flags. The flags are generated using the -- Bounded and Enum instance. We do not recommend to use -- the result list for further processing, since testing of flags is much -- faster using match. However you may find it useful to -- show the list. decompose :: (Bounded a, Enum a, Enum a, Bits w) => T w a -> [a] -- | Mask w a b describes a field of a T w a that has -- type Value w b. On the machine level a Mask value is a -- vector of bits, where set bits represent the bits belonging to one -- record field. There must be only one mask value for every pair of -- types (a,b). newtype Mask w a b Mask :: w -> Mask w a b unmask :: Mask w a b -> w maskValue :: Mask w a b -> Value w b -> MaskedValue w a -- | The type parameter w is the type of the underlying bit -- vector. The type parameter b is a phantom type, that is -- specific for a certain range of bits. newtype Value w b Value :: w -> Value w b unvalue :: Value w b -> w -- | Combines a mask with a value, that matches this mask. In -- MaskedValue mask value, value must be a subset of -- mask. data MaskedValue w a MaskedValue :: w -> w -> MaskedValue w a get :: (Enum a, Bits w) => Mask w a b -> T w a -> Value w b -- | All bits in Value must be contained in the mask. This condition is not -- checked by put. -- -- According to names in Data.Accessor it should be called -- set, but in Data.Bits and thus Data.EnumSet -- this is already used in the pair set/clear. -- put/get resembles the pair in -- Control.Monad.State in the mtl package. put :: (Enum a, Bits w) => Mask w a b -> Value w b -> T w a -> T w a accessor :: (Enum a, Bits w) => Mask w a b -> T (T w a) (Value w b) instance Eq word => Eq (T word a) instance Eq w => Eq (Mask w a b) instance Show w => Show (Mask w a b) instance Eq w => Eq (Value w b) instance Show w => Show (Value w b) instance Eq w => Eq (MaskedValue w a) instance Show w => Show (MaskedValue w a) instance Bits w => Monoid (MaskedValue w a) instance Storable w => Storable (T w a) module Data.FlagSet.PackedRecord getIntByMask :: (Bits w, Integral w, Integral i) => Mask w a b -> T w a -> i putIntByMask :: (Bits w, Integral w, Integral i) => Mask w a b -> i -> T w a -> T w a accessorIntByMask :: (Bits w, Integral w, Integral i) => Mask w a b -> T (T w a) i getIntByRange :: (Bits w, Integral w, Integral i) => Int -> Int -> T w a -> i putIntByRange :: (Bits w, Integral w, Integral i) => Int -> Int -> i -> T w a -> T w a accessorIntByRange :: (Bits w, Integral w, Integral i) => Int -> Int -> T (T w a) i -- | Similar to Data.Edison.Coll.EnumSet but it allows to choose the -- underlying type for bit storage. This is really a low-level module for -- type-safe foreign function interfaces. -- -- The integer representation of the enumeration type is the bit position -- of the flag within the bitvector. module Data.EnumSet newtype T word index Cons :: word -> T word index decons :: T word index -> word fromEnum :: (Enum a, Bits w) => a -> T w a fromEnums :: (Enum a, Bits w) => [a] -> T w a toEnums :: (Enum a, Bits w) => T w a -> [a] intToEnums :: (Enum a, Integral w) => T w a -> [a] -- | floor of binary logarithm - Intended for getting the position of a -- single set bit. This in turn is intended for implementing an -- Enum instance if you only know masks but no bit positions. mostSignificantPosition :: (Bits w, Storable w) => T w a -> Int -- | set a bit - Intended for implementing an Enum instance if you -- only know masks but no bit positions. singletonByPosition :: Bits w => Int -> T w a null :: (Enum a, Bits w) => T w a -> Bool empty :: (Enum a, Bits w) => T w a singleton :: (Enum a, Bits w) => a -> T w a disjoint :: (Enum a, Bits w) => T w a -> T w a -> Bool -- | subset a b is True if a is a subset of -- b. subset :: (Enum a, Bits w) => T w a -> T w a -> Bool (.&., xor, .|., .-.) :: (Enum a, Bits w) => T w a -> T w a -> T w a unions :: (Enum a, Bits w) => [T w a] -> T w a -- | could also be named member like in Set or -- elem as in '[]' get :: (Enum a, Bits w) => a -> T w a -> Bool put :: (Enum a, Bits w) => a -> Bool -> T w a -> T w a accessor :: (Enum a, Bits w) => a -> T (T w a) Bool -- | could also be named insert like in Set set :: (Enum a, Bits w) => a -> T w a -> T w a -- | could also be named delete like in Set clear :: (Enum a, Bits w) => a -> T w a -> T w a flip :: (Enum a, Bits w) => a -> T w a -> T w a fromBool :: (Enum a, Bits w) => a -> Bool -> T w a instance Eq word => Eq (T word index) instance (Enum a, Bits w) => Monoid (T w a) instance (Enum a, Storable w) => Storable (T w a) -- | Extract and inject an Enum value into an EnumSet. module Data.EnumSet.PackedEnum -- | T w a b describes a contiguous set of bit indices into the -- word type w where the indices are of type a and the -- set of indices represent a value of type b. data T w a b Cons :: w -> Int -> T w a b -- | Extract an enumeration value from the specified index set. unpack :: (Integral w, Bits w, Enum a, Enum b) => T w a b -> T w a -> b -- | Create an enumeration set, where an value of type b is placed -- at the specified indices. pack :: (Bits w, Enum a, Enum b) => T w a b -> b -> T w a -- | Clear all bits at the specified indices. clear :: (Bits w, Enum a, Enum b) => T w a b -> T w a -> T w a -- | Overwrite an enumset at the specified indices with the value of type -- b. put :: (Bits w, Enum a, Enum b) => T w a b -> b -> T w a -> T w a