Package ais :: Module BitVector :: Class BitVector
[hide private]
[frames] | no frames]

Class BitVector

source code

object --+
         |
        BitVector

Instance Methods [hide private]
  __init__(self, *args, **kwargs)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  _setbit(self, posn, val)
Set the bit at the designated position to the value shown
  _getbit(self, posn)
Get the bit from the designated position
  __xor__(self, other)
Take a bitwise 'xor' of the bit vector on which the method is invoked with the argument bit vector.
  __and__(self, other)
Take a bitwise 'and' of the bit vector on which the method is invoked with the argument bit vector.
  __or__(self, other)
Take a bitwise 'or' of the bit vector on which the method is invoked with the argument bit vector.
  __invert__(self)
Invert the bits in the bit vector on which the method is invoked and return the result as a new bit vector.
  __add__(self, other)
Concatenate the argument bit vector with the bit vector on which the method is invoked.
  _getsize(self)
Return the number of bits in a bit vector.
  read_bits_from_file(self, blocksize)
Read blocksize bits from a disk file and return a BitVector object containing the bits.
  read_bits_from_fileobject(self, fp)
This function is meant to read a bit string from a file like object.
  write_bits_to_fileobject(self, fp)
This function is meant to write a bit vector directly to a file like object.
  divide_into_two(self)
Divides an even-sized bit vector into two and returns the two halves as a list of two bit vectors.
  permute(self, permute_list)
Permute a bit vector according to the indices shown in the second argument list.
  unpermute(self, permute_list)
Unpermute the bit vector according to the permutation list supplied as the second argument.
  write_to_file(self, file_out)
(Contributed by Joe Davidson) Write the bitvector to the file object file_out.
  close_file_object(self)
For closing a file object that was used for reading the bits into one or more BitVector objects.
  intValue(self)
Return the integer value of a bitvector
  __lshift__(self, n)
For an in-place left circular shift by n bit positions
  __rshift__(self, n)
For an in-place right circular shift by n bit positions.
  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
  circular_rot_left(self)
This is merely another implementation of the method circular_rotate_left_by_one() shown above.
  circular_rot_right(self)
This is merely another implementation of the method circular_rotate_right_by_one() shown above.
  __getitem__(self, posn)
Get the bit from the designated position
  __setitem__(self, posn, val)
Set the bit at the designated position to the value shown
  __getslice__(self, i, j)
Allow slicing with [i:j], [:], etc.
  __len__(self)
Return the number of bits in a bit vector.
  __int__(self)
Return the integer value of a bitvector
  __iter__(self)
To allow iterations over a bit vector by supporting the 'for bit in bit_vector' syntax:
  __str__(self)
To create a print representation
  __eq__(self, other)
  __ne__(self, other)
  __lt__(self, other)
  __le__(self, other)
  __gt__(self, other)
  __ge__(self, other)
  _make_deep_copy(self)
Make a deep copy of a bit vector
  _resize_pad_from_left(self, n)
Resize a bit vector by padding with n 0's from the left.
  _resize_pad_from_right(self, n)
Resize a bit vector by padding with n 0's from the right.
  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
  __contains__(self, otherBitVec)
This supports 'if x in y' and 'if x not in y' syntax for bit vectors.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)

_setbit(self, posn, val)

source code 
Set the bit at the designated position to the value shown

_getbit(self, posn)

source code 
Get the bit from the designated position

__xor__(self, other)

source code 
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 zero's from the left.

__and__(self, other)
(And operator)

source code 
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 zero's from the left.

__or__(self, other)
(Or operator)

source code 
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.

__invert__(self)

source code 
Invert the bits in the bit vector on which the method is invoked and return the result as a new bit vector.

__add__(self, other)
(Addition operator)

source code 
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.

_getsize(self)

source code 
Return the number of bits in a bit vector.

read_bits_from_file(self, blocksize)

source code 
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)

source code 
This function is meant to read a bit string from a file like object.

write_bits_to_fileobject(self, fp)

source code 
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.

divide_into_two(self)

source code 
Divides an even-sized bit vector into two and returns the two halves as a list of two bit vectors.

permute(self, permute_list)

source code 
Permute a bit vector according to the indices shown in the second argument list. Return the permuted bit vector as a new bit vector.

unpermute(self, permute_list)

source code 
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_to_file(self, file_out)

source code 
(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).

close_file_object(self)

source code 
For closing a file object that was used for reading the bits into one or more BitVector objects.

intValue(self)

source code 
Return the integer value of a bitvector

__lshift__(self, n)

source code 
For an in-place left circular shift by n bit positions

__rshift__(self, n)

source code 
For an in-place right circular shift by n bit positions.

circular_rotate_left_by_one(self)

source code 
For a one-bit in-place left circular shift

circular_rotate_right_by_one(self)

source code 
For a one-bit in-place right circular shift

circular_rot_left(self)

source code 
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)

source code 
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.

__getitem__(self, posn)
(Indexing operator)

source code 
Get the bit from the designated position

__setitem__(self, posn, val)
(Index assignment operator)

source code 
Set the bit at the designated position to the value shown

__getslice__(self, i, j)
(Slicling operator)

source code 
Allow slicing with [i:j], [:], etc.

__len__(self)
(Length operator)

source code 
Return the number of bits in a bit vector.

__int__(self)

source code 
Return the integer value of a bitvector

__iter__(self)

source code 
To allow iterations over a bit vector by supporting the 'for bit in bit_vector' syntax:

__str__(self)
(Informal representation operator)

source code 
To create a print representation
Overrides: object.__str__

__eq__(self, other)
(Equality operator)

source code 
None

__ne__(self, other)

source code 
None

__lt__(self, other)
(Less-than operator)

source code 
None

__le__(self, other)
(Less-than-or-equals operator)

source code 
None

__gt__(self, other)
(Greater-than operator)

source code 
None

__ge__(self, other)
(Greater-than-or-equals operator)

source code 
None

_make_deep_copy(self)

source code 
Make a deep copy of a bit vector

_resize_pad_from_left(self, n)

source code 
Resize a bit vector by padding with n 0's from the left. Return the result as a new bit vector.

_resize_pad_from_right(self, n)

source code 
Resize a bit vector by padding with n 0's from the right. Return the result as a new bit vector.

pad_from_left(self, n)

source code 
Pad a bit vector with n zeros from the left

pad_from_right(self, n)

source code 
Pad a bit vector with n zeros from the right

__contains__(self, otherBitVec)
(In operator)

source code 
This supports 'if x in y' and 'if x not in y' syntax for bit vectors.