bitvec

Mojo module 🡭

bitvec

Provides a growable bitfield.

Optimized for space (1 bit per element) and speed (O(1) operations). Offers set/clear/test/toggle and fast population count. The underlying storage grows automatically but does not shrink unless shrink_to_fit is called (not implemented yet).

Example:

    var bv = BitVec(length=128, fill=False) # 128-bit set, all clear
    bv.set(42)                  # Mark value 42 as present.
    if bv[42]:                  # Check membership, could use bv.test(42)
        print("hit")            # Prints "hit".
    bv.clear(42)                # Remove 42.
    print(bv.count_set_bits())  # Prints 0.

Structs

  • BitVec: A growable bitfield.