BSD-3-Clause licensed by Andrew Lelechenko, James Cook
Maintained by Andrew Lelechenko
This version can be pinned in stack with:bitvec-1.0.0.0@sha256:a962ab1ffcd05e968ed4ce085fb169d636f4dbe729b80ed53b97c0c163511c2f,3363

Module documentation for 1.0.0.0

Bit vectors library for Haskell.

The current vector package represents unboxed arrays of Bool allocating one byte per boolean, which might be considered wasteful. This library provides a newtype wrapper Data.Bit.Bit and a custom instance of unboxed Data.Vector.Unboxed.Vector, which packs booleans densely. It is a time-memory tradeoff: 8x less memory footprint at the price of moderate performance penalty (mostly, for random writes).

Thread safety

  • Data.Bit is faster, but thread-unsafe. This is because naive updates are not atomic operations: read the whole word from memory, modify a bit, write the whole word back.

  • Data.Bit.ThreadSafe is slower (up to 2x), but thread-safe.

Similar packages

  • bv and bv-little offer only immutable size-polymorphic bit vectors. bitvec provides an interface to mutable vectors as well.

  • array is memory-efficient for Bool, but lacks a handy Vector interface and is not thread-safe.

Changes

1.0.0.0

  • Redesign API from the scratch.
  • Add a thread-safe implementation.
  • Add ‘nthBitIndex’ function.

0.2.0.1

  • Fix ‘Read’ instance.

0.2.0.0

  • Remove hand-written ‘Num’, ‘Real’, ‘Integral’, ‘Bits’ instances.
  • Derive ‘Bits’ and ‘FiniteBits’ instances.
  • Expose ‘Bit’ constructor directly and remove ‘fromBool’ function.
  • Rename ‘toBool’ to ‘unBit’.

0.1.1.0

  • Fix bugs in MVector and Vector instances of Bit.
  • Speed up MVector and Vector instances of Bit.