fast multi-dimensional unboxed bit packed Bool arrays

Version on this page:
LTS Haskell 22.29:
Stackage Nightly 2024-07-18:
Latest on Hackage:

See all snapshots bitwise appears in

BSD-3-Clause licensed by Claude Heiland-Allen
Maintained by [email protected]
This version can be pinned in stack with:bitwise-,3148

Module documentation for

Depends on 3 packages(full list with versions):
Used by 1 package in lts-3.22(full list with versions):

Unboxed multidimensional bit packed Bool arrays with fast aggregate operations based on lifting Bool operations to bitwise operations.

There are many other bit packed structures out there, but none met all of these requirements:

  1. unboxed bit packed Bool array,

  2. multi-dimensional indexing,

  3. fast (de)serialization, or interoperable with foreign code,

  4. fast aggregate operations (fold, map, zip).

Quick tour of the bitwise library:

Lift boolean operations on Bool to bitwise operations on Data.Bits.Bits.
Immutable bit arrays.
Mutable bit arrays in Control.Monad.ST.ST.
Mutable bit arrays in IO.
Portable bitmap monochrome 2D image format.

Very rough performance benchmarks:

  • immutable random access single bit reads: BitArray ix is about 40% slower than UArray ix Bool,

  • Control.Monad.ST.ST mutable random access single bit reads: STBitArray s ix is about the same as STUArray s ix Bool,

  • immutable map Bool -> Bool: BitArray ix is about 85x faster than UArray ix Bool,

  • immutable zipWith Bool -> Bool -> Bool: BitArray ix is about 1300x faster than UArray ix Bool.