| |
Methods defined here:
- __add__(self, other)
- Concatenate the argument bit vector with the bit vector on which
the method is invoked. Return the concatenated bit vector as a new
BitVector object.
- __and__(self, other)
- Take a bitwise 'and' of the bit vector on which the method is
invoked with the argument bit vector. Return the result as a new
bit vector. If the two bit vectors are not of the same size, pad
the shorter one with zeros from the left.
- __contains__(self, otherBitVec)
- This supports 'if x in y' and 'if x not in y' syntax for bit
vectors.
- __eq__(self, other)
- __ge__(self, other)
- __getitem__ = _getbit(self, posn)
- __getslice__(self, i, j)
- Allow slicing with [i:j], [:], etc.
- __gt__(self, other)
- __init__(self, *args, **kwargs)
- __int__ = intValue(self)
- __invert__(self)
- Invert the bits in the bit vector on which the method is invoked
and return the result as a new bit vector.
- __iter__(self)
- To allow iterations over a bit vector by supporting the 'for bit in
bit_vector' syntax:
- __le__(self, other)
- __len__ = _getsize(self)
- __lshift__(self, n)
- For an in-place left circular shift by n bit positions
- __lt__(self, other)
- __ne__(self, other)
- __or__(self, other)
- Take a bitwise 'or' of the bit vector on which the method is
invoked with the argument bit vector. Return the result as a new
bit vector. If the two bit vectors are not of the same size, pad
the shorter one with zero's from the left.
- __rshift__(self, n)
- For an in-place right circular shift by n bit positions.
- __setitem__(self, pos, item)
- This is needed for both slice assignments and for index
assignments. It checks the types of pos and item to see if the
call is for slice assignment. For slice assignment, pos must be of
type 'slice' and item of type BitVector. For index assignment, the
argument types are checked in the _setbit() method.
- __str__(self)
- To create a print representation
- __xor__(self, other)
- Take a bitwise 'xor' of the bit vector on which the method is
invoked with the argument bit vector. Return the result as a new
bit vector. If the two bit vectors are not of the same size, pad
the shorter one with zeros from the left.
- circular_rot_left(self)
- This is merely another implementation of the method
circular_rotate_left_by_one() shown above. This one does NOT use
map functions. This method carries out a one-bit left circular
shift of a bit vector.
- circular_rot_right(self)
- This is merely another implementation of the method
circular_rotate_right_by_one() shown above. This one does NOT use
map functions. This method does a one-bit right circular shift of
a bit vector.
- circular_rotate_left_by_one(self)
- For a one-bit in-place left circular shift
- circular_rotate_right_by_one(self)
- For a one-bit in-place right circular shift
- close_file_object(self)
- For closing a file object that was used for reading the bits into
one or more BitVector objects.
- count_bits(self)
- Return the number of bits set in a BitVector instance.
- count_bits_sparse(self)
- For sparse bit vectors, this method, contributed by Rhiannon, will
be much faster. She estimates that if a bit vector with over 2
millions bits has only five bits set, this will return the answer
in 1/18 of the time taken by the count_bits() method. Note
however, that count_bits() may work much faster for dense-packed
bit vectors. Rhianon's implementation is based on an algorithm
generally known as the Brian Kernighan's way, although its
antecedents predate its mention by Kernighan and Ritchie.
- divide_into_two(self)
- Divides an even-sized bit vector into two and returns the two
halves as a list of two bit vectors.
- gcd(self, other)
- Using Euclid's Algorithm, returns the greatest common divisor of
the integer value of the bit vector on which the method is invoked
and the integer value of the argument bit vector.
- hamming_distance(self, other)
- Computes the Hamming distance between two bit vectors
- intValue(self)
- Return the integer value of a bitvector
- isPowerOf2(self)
- Determines whether the integer value of a bit vector is a power of
2.
- isPowerOf2_sparse(self)
- Faster version of isPowerOf2() for sparse bit vectors
- jaccard_distance(self, other)
- Computes the Jaccard distance between two bit vectors
- jaccard_similarity(self, other)
- Computes the Jaccard similarity coefficient between two bit vectors
- multiplicative_inverse(self, modulus)
- Calculates the multiplicative inverse of a bit vector modulo the
bit vector that is supplied as the argument. Code based on the
Extended Euclid's Algorithm.
- next_set_bit(self, from_index=0)
- This method, contributed by Jason Allum, calculates the number of
bit positions from the current position index to the next set bit.
- pad_from_left(self, n)
- Pad a bit vector with n zeros from the left
- pad_from_right(self, n)
- Pad a bit vector with n zeros from the right
- permute(self, permute_list)
- Permute a bit vector according to the indices shown in the second
argument list. Return the permuted bit vector as a new bit vector.
- rank_of_bit_set_at_index(self, position)
- For a bit that is set at the argument 'position', this method
returns how many bits are set to the left of that bit. For
example, in the bit pattern 000101100100, a call to this method
with position set to 9 will return 4.
- read_bits_from_file(self, blocksize)
- Read blocksize bits from a disk file and return a BitVector object
containing the bits. If the file contains fewer bits than
blocksize, construct the BitVector object from however many bits
there are in the file. If the file contains zero bits, return a
BitVector object of size attribute set to 0.
- read_bits_from_fileobject(self, fp)
- This function is meant to read a bit string from a file like
object.
- reset(self, val)
- Resets a previously created BitVector to either all zeros or all
ones depending on the argument val. Returns self to allow for
syntax like
bv = bv1[3:6].reset(1)
or
bv = bv1[:].reset(1)
- reverse(self)
- Returns a new bit vector by reversing the bits in the bit vector on
which the method is invoked.
- setValue(self, *args, **kwargs)
- Changes the bit pattern associated with a previously constructed
BitVector instance. The allowable modes for chaning the internally
stored bit patten are the same as for the constructor.
- unpermute(self, permute_list)
- Unpermute the bit vector according to the permutation list supplied
as the second argument. If you first permute a bit vector by using
permute() and then unpermute() it using the same permutation list,
you will get back the original bit vector.
- write_bits_to_fileobject(self, fp)
- This function is meant to write a bit vector directly to a file
like object. Note that whereas 'write_to_file' method creates a
memory footprint that corresponds exactly to the bit vector, the
'write_bits_to_fileobject' actually writes out the 1's and 0's as
individual items to the file object. That makes this method
convenient for creating a string representation of a bit vector,
especially if you use the StringIO class, as shown in the test
code.
- write_to_file(self, file_out)
- (Contributed by Joe Davidson) Write the bitvector to the file
object file_out. (A file object is returned by a call to
open()). Since all file I/O is byte oriented, the bitvector must be
multiple of 8 bits. Each byte treated as MSB first (0th index).
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|