Safe Haskell | None |
---|---|
Language | Haskell2010 |
A collection of a number of data types and type classes shared by all bitset variants.
Synopsis
- newtype Boundary boundaryType ioc = Boundary {
- getBoundary :: Int
- pattern UndefBoundary :: Boundary boundaryType ioc
- streamUpBndMk :: Monad m => b -> p -> a -> m (a, b)
- streamUpBndStep :: forall k1 k2 m p a (boundaryType :: k1) (ioc :: k2). Monad m => p -> Int -> (a, Int) -> m (Step (a, Int) (a :. Boundary boundaryType ioc))
- streamDownBndMk :: Monad m => p -> b -> a -> m (a, b)
- streamDownBndStep :: forall k1 k2 m p a (boundaryType :: k1) (ioc :: k2). Monad m => Int -> p -> (a, Int) -> m (Step (a, Int) (a :. Boundary boundaryType ioc))
- data First
- data Last
- data Any
- class SetPredSucc s where
- type family Mask s :: *
- data FixedMask t = FixedMask {}
- class ApplyMask s where
- arbitraryBitSetMax :: Int
Boundaries, the interface(s) for bitsets.
newtype Boundary boundaryType ioc Source #
Certain sets have an interface, a particular element with special
meaning. In this module, certain `meanings'
are already provided.
These include a First
element and a Last
element. We phantom-type
these to reduce programming overhead.
Instances
pattern UndefBoundary :: Boundary boundaryType ioc Source #
Whenever we can not set the boundary we should have for a set, we use this
pattern. All legal boundaries are >=0
. We also need to set the undefined
boundary to 0
, since the linearIndex
will use this value to add, which
for empty sets would reduce to 0 - UndefBoundary === 0
.
streamUpBndMk :: Monad m => b -> p -> a -> m (a, b) Source #
streamUpBndStep :: forall k1 k2 m p a (boundaryType :: k1) (ioc :: k2). Monad m => p -> Int -> (a, Int) -> m (Step (a, Int) (a :. Boundary boundaryType ioc)) Source #
streamDownBndMk :: Monad m => p -> b -> a -> m (a, b) Source #
streamDownBndStep :: forall k1 k2 m p a (boundaryType :: k1) (ioc :: k2). Monad m => Int -> p -> (a, Int) -> m (Step (a, Int) (a :. Boundary boundaryType ioc)) Source #
Declare the interface to match anything.
TODO needed? want to use later in ADPfusion
Moving indices within sets.
class SetPredSucc s where Source #
Successor and Predecessor for sets. Designed as a class to accomodate sets with interfaces and without interfaces with one function.
The functions are not written recursively, as we currently only have three cases, and we do not want to "reset" while generating successors and predecessors.
Note that sets have a partial order. Within the group of element with
the same popCount
, we use popPermutation
which has the same stepping
order for both, setSucc
and setPred
.
setSucc :: Int -> Int -> s -> Maybe s Source #
Set successor. The first argument is the lower set limit, the second the upper set limit, the third the current set.
setPred :: Int -> Int -> s -> Maybe s Source #
Set predecessor. The first argument is the lower set limit, the second the upper set limit, the third the current set.
Instances
SetPredSucc (FixedMask (BitSet1 t ioc)) Source # | |
SetPredSucc (BitSet t) Source # | |
SetPredSucc (BitSet1 t ioc) Source # | |
type family Mask s :: * Source #
Masks are used quite often for different types of bitsets. We liberate them as a type family.
Fixed
allows us to fix some or all bits of a bitset, thereby
providing succ/pred
operations which are only partially free.
f = getFixedMask .&. getFixed
are the fixed bits.
n = getFixed .&. complement getFixedMask
are the free bits.
to = complement getFixed
is the to move mask
n' = popShiftR to n
yields the population after the move
p = popPermutation undefined n'
yields the new population permutation
p' = popShiftL to p
yields the population moved back
final = p' .|. f
class ApplyMask s where Source #
Assuming a bitset on bits [0 .. highbit]
, we can apply a mask that
stretches out those bits over [0 .. higherBit]
with highbit <=
higherBit
. Any active interfaces are correctly set as well.
arbitraryBitSetMax :: Int Source #
for Arbitrary