Safe Haskell | None |
---|---|
Language | Haskell2010 |
Agda.Utils.Word
Synopsis
- uncheckedBitWord# :: Int# -> Word#
- uncheckedClearBitWord# :: Word# -> Int# -> Word#
- uncheckedSetBitWord# :: Word# -> Int# -> Word#
- uncheckedTestBitWord# :: Word# -> Int# -> Int#
- highestBitWord# :: Word# -> Word#
- lowestBitWord# :: Word# -> Word#
- disjointWord# :: Word# -> Word# -> Int#
- andNot# :: Word# -> Word# -> Word#
- uncheckedWordOnes# :: Int# -> Word#
- wordFoldrBits# :: (Int -> a -> a) -> a -> Word# -> a
- wordFoldlBits# :: (a -> Int -> a) -> a -> Word# -> a
- wordFoldrBitsOffset# :: Int# -> (Int -> a -> a) -> a -> Word# -> a
- wordFoldlBitsOffset# :: Int# -> (a -> Int -> a) -> a -> Word# -> a
- wordFoldrBitsStrict# :: (Int -> a -> a) -> a -> Word# -> a
- wordFoldlBitsStrict# :: (a -> Int -> a) -> a -> Word# -> a
- wordFoldrBitsOffsetStrict# :: Int# -> (Int -> a -> a) -> a -> Word# -> a
- wordFoldlBitsOffsetStrict# :: Int# -> (a -> Int -> a) -> a -> Word# -> a
Bitwise operations
uncheckedBitWord# :: Int# -> Word# Source #
Create a Word#
with the i
th bit set.
The result of uncheckedBitWord#
is undefined when i
is not in the range [0..64]
.
uncheckedClearBitWord# :: Word# -> Int# -> Word# Source #
Clear a single bit in an unboxed word.
The result of uncheckedClearBitWord#
is undefined when i
is not in the range [0..64]
.
uncheckedSetBitWord# :: Word# -> Int# -> Word# Source #
Set a single bit in an unboxed word.
The result of uncheckedSetBitWord#
is undefined when i
is not in the range [0..64]
.
uncheckedTestBitWord# :: Word# -> Int# -> Int# Source #
Test a single bit in an unboxed word.
The result of uncheckedTestBitWord#
is undefined when i
is not in the range [0..64]
.
highestBitWord# :: Word# -> Word# Source #
Get the bit-index of the highest set bit.
lowestBitWord# :: Word# -> Word# Source #
Get the bit-index of the lowest set bit.
andNot# :: Word# -> Word# -> Word# Source #
Take the bitwise AND of the first argument with the complement of the second.
uncheckedWordOnes# :: Int# -> Word# Source #
Create a Word#
where the first n
bits are 1.
The result of uncheckedWordOnes#
is undefined when i
is not in the range [0..64]
.
Folds
As usual, there is an ambiguity in left/right folds for folding over the bits of a
Word#
. We opt to use the convention where we treat the 0th bit as the "head" of
a Word#
, so a right fold like wordFoldrBits# f x 0b1011
would give f 0 (f 1 (f 3 x))
.
We also provide hand-rolled versions of folds that offset the bit index by a static value:
this pattern comes up quite often when folding over ByteArray#
and the like. This can
save some allocations when compared to wordFoldrBits# (i acc -> f (i + offset) acc) a
.
wordFoldrBits# :: (Int -> a -> a) -> a -> Word# -> a Source #
wordFoldrBits# f a w
performs a lazy right fold over the bits of w
.
wordFoldlBits# :: (a -> Int -> a) -> a -> Word# -> a Source #
wordFoldlBits# f a w
performs a lazy left fold over the bits of w
.
wordFoldrBitsOffset# :: Int# -> (Int -> a -> a) -> a -> Word# -> a Source #
wordFoldrBitsOffset# offset f a w
performs a right fold over the bits of w
,
with every bit index passed to f
offset by offset
.
wordFoldlBitsOffset# :: Int# -> (a -> Int -> a) -> a -> Word# -> a Source #
wordFoldlBitsOffset# offset f a w
performs a lazy left fold over the bits of w
,
with every bit index passed to f
offset by offset
.
Strict folds
wordFoldrBitsStrict# :: (Int -> a -> a) -> a -> Word# -> a Source #
wordFoldrBitsStrict# f a w
performs a strict right fold over the bits of w
.
wordFoldlBitsStrict# :: (a -> Int -> a) -> a -> Word# -> a Source #
wordFoldlBitsStrict# f a w
performs a strict left fold over the bits of w
.