bitwise-1.0.0.1: fast multi-dimensional unboxed bit packed Bool arrays

Copyright | (c) Claude Heiland-Allen 2012
License | BSD3
Maintainer | claude@mathr.co.uk
Stability | unstable
Portability | portable
Safe Haskell | None
Language | Haskell2010

Data.Array.BitArray

Contents

- IArray-like interface.
- Constant arrays.
- Short-circuiting reductions.
- Aggregate operations.
- Bounds-checked indexing.
- Unsafe.

Description

Immutable unboxed packed bit arrays using bitwise operations to manipulate large chunks at a time much more quickly than individually unpacking and repacking bits would allow.

Synopsis

- data BitArray i
- bounds :: Ix i => BitArray i -> (i, i)
- array :: Ix i => (i, i) -> [(i, Bool)] -> BitArray i
- listArray :: Ix i => (i, i) -> [Bool] -> BitArray i
- accumArray :: Ix i => (Bool -> a -> Bool) -> Bool -> (i, i) -> [(i, a)] -> BitArray i
- (!) :: Ix i => BitArray i -> i -> Bool
- indices :: Ix i => BitArray i -> [i]
- elems :: Ix i => BitArray i -> [Bool]
- assocs :: Ix i => BitArray i -> [(i, Bool)]
- (//) :: Ix i => BitArray i -> [(i, Bool)] -> BitArray i
- accum :: Ix i => (Bool -> a -> Bool) -> BitArray i -> [(i, a)] -> BitArray i
- amap :: Ix i => (Bool -> Bool) -> BitArray i -> BitArray i
- ixmap :: (Ix i, Ix j) => (i, i) -> (i -> j) -> BitArray j -> BitArray i
- fill :: Ix i => (i, i) -> Bool -> BitArray i
- false :: Ix i => (i, i) -> BitArray i
- true :: Ix i => (i, i) -> BitArray i
- or :: Ix i => BitArray i -> Bool
- and :: Ix i => BitArray i -> Bool
- isUniform :: Ix i => BitArray i -> Maybe Bool
- elemIndex :: Bool -> BitArray Int -> Maybe Int
- fold :: Ix i => (Bool -> Bool -> Bool) -> BitArray i -> Maybe Bool
- map :: Ix i => (Bool -> Bool) -> BitArray i -> BitArray i
- zipWith :: Ix i => (Bool -> Bool -> Bool) -> BitArray i -> BitArray i -> BitArray i
- popCount :: Ix i => BitArray i -> Int
- (!?) :: Ix i => BitArray i -> i -> Maybe Bool
- (!!!) :: Ix i => BitArray i -> i -> Bool

# Documentation

data BitArray i Source #

The type of immutable bit arrays.

# IArray-like interface.

bounds :: Ix i => BitArray i -> (i, i) Source #

The bounds of an array.

array Source #

Arguments

:: Ix i |
=> (i, i) | bounds
-> [(i, Bool)] | assocs
-> BitArray i |

Create an array from a list of (index, element) pairs.

listArray Source #

Arguments

:: Ix i |
=> (i, i) | bounds
-> [Bool] | elems
-> BitArray i |

Create an array from a list of elements.

accumArray Source #

Arguments

:: Ix i |
=> (Bool -> a -> Bool) | operation
-> Bool | default
-> (i, i) | bounds
-> [(i, a)] | assocs
-> BitArray i |

Create an array by accumulating a list of (index, operand) pairs from a default seed with an operation.

(!) :: Ix i => BitArray i -> i -> Bool Source #

Bit array indexing.

indices :: Ix i => BitArray i -> [i] Source #

A list of all the valid indices for this array.

elems :: Ix i => BitArray i -> [Bool] Source #

A list of the elements in this array.

assocs :: Ix i => BitArray i -> [(i, Bool)] Source #

A list of the (index, element) pairs in this array.

(//) Source #

Arguments

:: Ix i |
=> BitArray i |
-> [(i, Bool)] | new assocs
-> BitArray i |

A new array with updated values at the supplied indices.

accum Source #

Arguments

:: Ix i |
=> (Bool -> a -> Bool) | operation
-> BitArray i | source
-> [(i, a)] | assocs
-> BitArray i |

Accumulate with an operation and a list of (index, operand).

amap :: Ix i => (Bool -> Bool) -> BitArray i -> BitArray i Source #

Alias for `map`.

ixmap Source #

Arguments

:: (Ix i, Ix j) |
=> (i, i) | new bounds
-> (i -> j) | index transformation
-> BitArray j | source array
-> BitArray i |

Create a new array by mapping indices into a source array..

# Constant arrays.

fill Source #

Arguments

:: Ix i |
=> (i, i) | bounds
-> Bool |
-> BitArray i |

A uniform array of bits.

false Source #

Arguments

:: Ix i |
=> (i, i) | bounds
-> BitArray i |

A uniform array of `False`.

true Source #

Arguments

:: Ix i |
=> (i, i) | bounds
-> BitArray i |

A uniform array of `True`.

# Short-circuiting reductions.

or :: Ix i => BitArray i -> Bool Source #

Short-circuit bitwise reduction: True if any bit is True.

and :: Ix i => BitArray i -> Bool Source #

Short-circuit bitwise reduction: False if any bit is False.

isUniform :: Ix i => BitArray i -> Maybe Bool Source #

Short-circuit bitwise reduction: Nothing if any bits differ.

elemIndex :: Bool -> BitArray Int -> Maybe Int Source #

Look up index of first matching bit.

Note that the index type is limited to Int because there is no `unindex` method in the `Ix` class.

# Aggregate operations.

fold :: Ix i => (Bool -> Bool -> Bool) -> BitArray i -> Maybe Bool Source #

Bitwise reduction with an associative commutative boolean operator. Implementation lifts from `Bool` to `Bits` and folds large chunks at a time. Each bit is used as a source exactly once.

map :: Ix i => (Bool -> Bool) -> BitArray i -> BitArray i Source #

Bitwise map. Implementation lifts from `Bool` to `Bits` and maps large chunks at a time.

zipWith :: Ix i => (Bool -> Bool -> Bool) -> BitArray i -> BitArray i -> BitArray i Source #

Bitwise zipWith. Implementation lifts from `Bool` to `Bits` and combines large chunks at a time.

The bounds of the source arrays must be identical.

popCount :: Ix i => BitArray i -> Int Source #

Count set bits.

# Bounds-checked indexing.

(!?) :: Ix i => BitArray i -> i -> Maybe Bool Source #

Bounds checking combined with array indexing.

# Unsafe.

(!!!) :: Ix i => BitArray i -> i -> Bool Source #

Bit array indexing without bounds checking. Unsafe.