bitvec-0.2.0.1: Unboxed bit vectors

Safe HaskellNone
LanguageHaskell2010

Data.Vector.Unboxed.Bit

Synopsis

Documentation

wordSize :: Int Source #

The number of Bits in a Word. A handy constant to have around when defining Word-based bulk operations on bit vectors.

fromWords :: Int -> Vector Word -> Vector Bit Source #

Given a number of bits and a vector of words, concatenate them to a 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.

toWords :: Vector Bit -> Vector Word Source #

Given a vector of bits, extract an unboxed vector of words. If the bits don't completely fill the words, the last word will be zero-padded.

indexWord :: Vector Bit -> Int -> Word Source #

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.

zipWords :: (Word -> Word -> Word) -> Vector Bit -> Vector Bit -> Vector Bit Source #

zipWords f xs ys = fromWords (min (length xs) (length ys)) (zipWith f (toWords xs) (toWords ys))

invert :: Vector Bit -> Vector Bit Source #

Flip every bit in the given vector

select :: (Vector v1 Bit, Vector v2 t) => v1 Bit -> v2 t -> [t] Source #

Given a vector of bits and a vector of things, extract those things for which the corresponding bit is set.

For example, select (V.map (fromBool . p) x) x == V.filter p x.

exclude :: (Vector v1 Bit, Vector v2 t) => v1 Bit -> v2 t -> [t] Source #

Given a vector of bits and a vector of things, extract those things for which the corresponding bit is unset.

For example, exclude (V.map (fromBool . p) x) x == V.filter (not . p) x.

countBits :: Vector Bit -> Int Source #

return the number of ones in a bit vector

and :: Vector Bit -> Bool Source #

True if all bits in the vector are set

or :: Vector Bit -> Bool Source #

True if any bit in the vector is set

any :: (Bit -> Bool) -> Vector Bit -> Bool Source #

all :: (Bit -> Bool) -> Vector Bit -> Bool Source #

first :: Bit -> Vector Bit -> Maybe Int Source #

Return the address of the first bit in the vector with the specified value, if any