An implementation of an object that acts like a collection of on/off bits.
Implements a memory-efficient array of bits.
>>> bv = BitVector(10)
>>> bv
<BitVector 0000000000>
>>> bv[5] = True
>>> bv
<BitVector 0000010000>
You can initialize the BitVector using an iterable of integers representing bit positions to turn on.
>>> bv2 = BitVector(10, [2, 4, 7])
>>> bv2
<BitVector 00101001000>
>>> bv[2]
True
BitVector supports bit-wise logic operations & (and), | (or), and ^ (xor) between itself and another BitVector of equal size, or itself and a collection of integers (usually a set() or frozenset()).
>>> bv | bv2
<BitVector 00101101000>
Note that BitVector.__len__() returns the number of “on” bits, not the size of the bit array. This is to make BitVector interchangeable with a set()/frozenset() of integers. To get the size, use BitVector.size.