Safe Haskell | Trustworthy |
---|

- module Data.Bit
- wordSize :: Int
- wordLength :: MVector s Bit -> Int
- cloneFromWords :: PrimMonad m => Int -> MVector (PrimState m) Word -> m (MVector (PrimState m) Bit)
- cloneToWords :: PrimMonad m => MVector (PrimState m) Bit -> m (MVector (PrimState m) Word)
- readWord :: PrimMonad m => MVector (PrimState m) Bit -> Int -> m Word
- writeWord :: PrimMonad m => MVector (PrimState m) Bit -> Int -> Word -> m ()
- mapMInPlaceWithIndex :: PrimMonad m => (Int -> Word -> m Word) -> MVector (PrimState m) Bit -> m ()
- mapInPlaceWithIndex :: PrimMonad m => (Int -> Word -> Word) -> MVector (PrimState m) Bit -> m ()
- mapMInPlace :: PrimMonad m => (Word -> m Word) -> MVector (PrimState m) Bit -> m ()
- mapInPlace :: PrimMonad m => (Word -> Word) -> MVector (PrimState m) Bit -> m ()
- zipInPlace :: PrimMonad m => (Word -> Word -> Word) -> MVector (PrimState m) Bit -> Vector Bit -> m ()
- unionInPlace :: PrimMonad m => MVector (PrimState m) Bit -> Vector Bit -> m ()
- intersectionInPlace :: PrimMonad m => MVector (PrimState m) Bit -> Vector Bit -> m ()
- differenceInPlace :: PrimMonad m => MVector (PrimState m) Bit -> Vector Bit -> m ()
- symDiffInPlace :: PrimMonad m => MVector (PrimState m) Bit -> Vector Bit -> m ()
- invertInPlace :: PrimMonad m => MVector (PrimState m) Bit -> m ()
- selectBitsInPlace :: PrimMonad m => Vector Bit -> MVector (PrimState m) Bit -> m Int
- excludeBitsInPlace :: PrimMonad m => Vector Bit -> MVector (PrimState m) Bit -> m Int
- countBits :: PrimMonad m => MVector (PrimState m) Bit -> m Int
- listBits :: PrimMonad m => MVector (PrimState m) Bit -> m [Int]
- and :: PrimMonad m => MVector (PrimState m) Bit -> m Bool
- or :: PrimMonad m => MVector (PrimState m) Bit -> m Bool
- any :: PrimMonad m => (Bit -> Bool) -> MVector (PrimState m) Bit -> m Bool
- anyBits :: PrimMonad m => Bit -> MVector (PrimState m) Bit -> m Bool
- all :: PrimMonad m => (Bit -> Bool) -> MVector (PrimState m) Bit -> m Bool
- allBits :: PrimMonad m => Bit -> MVector (PrimState m) Bit -> m Bool
- reverseInPlace :: PrimMonad m => MVector (PrimState m) Bit -> m ()

# Documentation

module Data.Bit

wordLength :: MVector s Bit -> IntSource

Get the length of the vector that would be created by `cloneToWords`

cloneFromWords :: PrimMonad m => Int -> MVector (PrimState m) Word -> m (MVector (PrimState m) Bit)Source

Clone a specified number of bits from a vector of words into a new vector of bits (interpreting the words in little-endian order, as described at `indexWord`

). If there are not enough words for the number of bits requested, the vector will be zero-padded.

cloneToWords :: PrimMonad m => MVector (PrimState m) Bit -> m (MVector (PrimState m) Word)Source

clone a vector of bits to a new unboxed vector of words. If the bits don't completely fill the words, the last word will be zero-padded.

readWord :: PrimMonad m => MVector (PrimState m) Bit -> Int -> m WordSource

read a word at the given bit offset in little-endian order (i.e., the LSB will correspond to the bit at the given address, the 2's bit will correspond to the address + 1, etc.). If the offset is such that the word extends past the end of the vector, the result is zero-padded.

writeWord :: PrimMonad m => MVector (PrimState m) Bit -> Int -> Word -> m ()Source

write a word at the given bit offset in little-endian order (i.e., the LSB will correspond to the bit at the given address, the 2's bit will correspond to the address + 1, etc.). If the offset is such that the word extends past the end of the vector, the word is truncated and as many low-order bits as possible are written.

mapMInPlaceWithIndex :: PrimMonad m => (Int -> Word -> m Word) -> MVector (PrimState m) Bit -> m ()Source

Map a function over a bit vector one `Word`

at a time (`wordSize`

bits at a time). The function will be passed the bit index (which will always be `wordSize`

-aligned) and the current value of the corresponding word. The returned word will be written back to the vector. If there is a partial word at the end of the vector, it will be zero-padded when passed to the function and truncated when the result is written back to the array.

mapInPlaceWithIndex :: PrimMonad m => (Int -> Word -> Word) -> MVector (PrimState m) Bit -> m ()Source

mapMInPlace :: PrimMonad m => (Word -> m Word) -> MVector (PrimState m) Bit -> m ()Source

Same as `mapMInPlaceWithIndex`

but without the index.

zipInPlace :: PrimMonad m => (Word -> Word -> Word) -> MVector (PrimState m) Bit -> Vector Bit -> m ()Source

invertInPlace :: PrimMonad m => MVector (PrimState m) Bit -> m ()Source

Flip every bit in the given vector

countBits :: PrimMonad m => MVector (PrimState m) Bit -> m IntSource

return the number of ones in a bit vector

and :: PrimMonad m => MVector (PrimState m) Bit -> m BoolSource

Returns `True`

if all bits in the vector are set