support.bitvector module

An implementation of an object that acts like a collection of on/off bits.

class whoosh.support.bitvector.BitVector(size, source=None, bits=None)

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.

clear(index)

Turns the bit at the given position off.

copy()

Returns a copy of this BitArray.

count()

Returns the number of “on” bits in the bit array.

set(index)

Turns the bit at the given position on.

set_from(iterable)

Takes an iterable of integers representing positions, and turns on the bits at those positions.

Previous topic

store module

Next topic

support.charset module

This Page