| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.PrimitiveArray.Index.Set
Description
Set with and without interfaces. We provide instances for sets, and
sets with one or two interfaces. The First and Last annotation is
purely cosmetical (apart from introducing type safety).
- newtype Interface t = Iter {}
- data First
- data Last
- data Any
- newtype BitSet t = BitSet {}
- bitSetI :: Int -> BitSet I
- bitSetO :: Int -> BitSet O
- bitSetC :: Int -> BitSet C
- data BS1 i t = BS1 !(BitSet t) !(Interface i)
- data BS2 i j t = BS2 !(BitSet t) !(Interface i) !(Interface j)
- class SetPredSucc s where
- type family Mask s :: *
- data Fixed t = Fixed {
- getFixedMask :: Mask t
- getFixed :: !t
- class ApplyMask s where
- streamUpBsMk :: (Monad m, Ord a) => a -> a -> t -> m (t, Maybe a)
- streamUpBsStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamDownBsMk :: (Monad m, Ord a) => a -> a -> t -> m (t, Maybe a)
- streamDownBsStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamUpBsIMk :: Monad m => BS1 a i -> BS1 b i -> z -> m (z, Maybe (BS1 c i))
- streamUpBsIStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamDownBsIMk :: Monad m => BS1 a i -> BS1 b i -> z -> m (z, Maybe (BS1 c i))
- streamDownBsIStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamUpBsIiMk :: Monad m => BS2 a b i -> BS2 c d i -> z -> m (z, Maybe (BS2 e f i))
- streamUpBsIiStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamDownBsIiMk :: Monad m => BS2 a b i -> BS2 c d i -> z -> m (z, Maybe (BS2 e f i))
- streamDownBsIiStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- testBsS :: BitSet t -> Maybe (Fixed (BitSet t))
- arbitraryBitSetMax :: Integer
newtypes, data types, classes.
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
| Vector Vector (Interface t) Source | |
| MVector MVector (Interface t) Source | |
| Eq (Interface t) Source | |
| Num (Interface t) Source | |
| Ord (Interface t) Source | |
| Show (Interface t) Source | |
| Generic (Interface t) Source | |
| ToJSON (Interface t) Source | |
| FromJSON (Interface t) Source | |
| Binary (Interface t) Source | |
| Serialize (Interface t) Source | |
| NFData (Interface t) Source | |
| Hashable (Interface t) Source | |
| Unbox (Interface t) Source | |
| Index (Interface i) Source | |
| data MVector s0 (Interface t0) = MV_Interface (MVector s Int) Source | |
| type Rep (Interface t) Source | |
| data Vector (Interface t0) = V_Interface (Vector Int) Source |
Newtype for a bitset. We'd use Words but that requires more shape
instances.
TODO can we use Words now?
Instances
A bitset with one interface.
Instances
| SetPredSucc (Fixed (BS1 i t)) Source | |
| Show (BS1 i t) Source | |
| Arbitrary (BS1 i t) Source | |
| IndexStream z => IndexStream ((:.) z (BS1 i C)) Source | |
| IndexStream z => IndexStream ((:.) z (BS1 i O)) Source | |
| IndexStream z => IndexStream ((:.) z (BS1 i I)) Source | |
| IndexStream ((:.) Z (BS1 i t)) => IndexStream (BS1 i t) Source | |
| Index (BS1 i t) Source | |
| ApplyMask (BS1 i t) Source | |
| SetPredSucc (BS1 i t) Source | |
| type Mask (BS1 i t) = BitSet t Source |
A bitset with two interfaces.
Instances
| SetPredSucc (Fixed (BS2 i j t)) Source | |
| IndexStream z => IndexStream ((:.) z (BS2 i j C)) Source | |
| IndexStream z => IndexStream ((:.) z (BS2 i j O)) Source | |
| IndexStream z => IndexStream ((:.) z (BS2 i j I)) Source | |
| Show (BS2 i j t) Source | |
| Arbitrary (BS2 i j t) Source | |
| IndexStream ((:.) Z (BS2 i j t)) => IndexStream (BS2 i j t) Source | |
| Index (BS2 i j t) Source | |
| ApplyMask (BS2 i j t) Source | |
| SetPredSucc (BS2 i j t) Source | |
| type Mask (BS2 i j t) = BitSet t Source |
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.
Methods
setSucc :: s -> s -> 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 :: s -> s -> 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 (Fixed (BS2 i j t)) Source | |
| SetPredSucc (Fixed (BS1 i t)) Source | |
| SetPredSucc (Fixed (BitSet t)) Source | |
| SetPredSucc (BitSet t) Source | |
| SetPredSucc (BS1 i t) Source | |
| SetPredSucc (BS2 i j t) 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.
The mask is lazy, this allows us to have undefined for l and h.
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
Constructors
| Fixed | |
Fields
| |
Instances
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.
Instances
streamUpBsMk :: (Monad m, Ord a) => a -> a -> t -> m (t, Maybe a) Source
streamUpBsStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source
streamDownBsMk :: (Monad m, Ord a) => a -> a -> t -> m (t, Maybe a) Source
streamDownBsStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source
BS1
streamUpBsIStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source
streamDownBsIStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source
BS2
streamUpBsIiStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source
streamDownBsIiStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source