Chemical Data Processing Library Python API - Version 1.4.0
Public Member Functions | Static Public Attributes | Properties | List of all members
CDPL.Util.BitSet Class Reference

Data structure for the storage and processing of variably sized bit sets. More...

+ Inheritance diagram for CDPL.Util.BitSet:

Public Member Functions

None __init__ ()
 Constructs a BitSet instance of size zero.
 
None __init__ (BitSet bs)
 Contructs a copy of the BitSet instance bs. More...
 
None __init__ (int num_bits, int value=0)
 Constructs a BitSet instance of size num_bits initialized to the bits in value. More...
 
None __init__ (str bit_str)
 Constructs a BitSet instance with size and bit values specified by the string bit_str. More...
 
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
None swap (BitSet bs)
 Swaps the contents of this bitset and the bitset bs. More...
 
BitSet assign (BitSet bs)
 Replaces the current state with a copy of the state of the BitSet instance bs. More...
 
None resize (int num_bits, bool value=False)
 Changes the number of bits to num_bits. More...
 
None clear ()
 Resizes the bitset to zero length.
 
None append (bool value)
 Increases the size of the bitset by one, and sets the value of the new most significant bit to value. More...
 
BitSet flip ()
 Toggles the value of every bit. More...
 
BitSet flip (int idx)
 Toggles the value of the bit at index idx. More...
 
BitSet set ()
 Sets all bits to True. More...
 
BitSet set (int idx, bool value=True)
 Sets the bit at index idx to value. More...
 
BitSet reset ()
 Sets all bits to False. More...
 
BitSet reset (int idx)
 Sets the bit at index idx to False. More...
 
bool test (int idx)
 Returns the value of the bit at index idx. More...
 
int findFirst ()
 Returns the index of the first set bit (if any). More...
 
int findNext (int idx)
 Returns the index of the first set bit after idx (if any). More...
 
bool isSubsetOf (BitSet bs)
 Checks whether this bitset is a subset of the bitset bs. More...
 
bool isProperSubsetOf (BitSet bs)
 Checks whether this bitset is a proper subset of the bitset bs. More...
 
bool isEmpty ()
 Checks whether this bitset has size zero. More...
 
int getCount ()
 Returns the number of set bits. More...
 
int getSize ()
 Returns the size of the bitset. More...
 
int getMaxSize ()
 Returns the maximum allowed bitset size. More...
 
bool hasAny ()
 Checks whether at least one bit is set. More...
 
bool hasNone ()
 Checks whether all bits are unset. More...
 
bool __getitem__ (int idx)
 Returns the value of the bit at index idx. More...
 
None __setitem__ (int idx, bool value)
 Sets the bit at index idx to value. More...
 
BitSet __and__ (BitSet bs)
 Performs a bitwise‐AND of this bitset and the bitset bs. More...
 
BitSet __or__ (BitSet bs)
 Performs a bitwise‐OR of this bitset and the bitset bs. More...
 
BitSet __xor__ (BitSet bs)
 Performs a bitwise‐XOR of this bitset and the bitset bs. More...
 
BitSet __sub__ (BitSet bs)
 Computes the set difference of this bitset and the bitset bs. More...
 
BitSet __iand__ (BitSet bs)
 Performs an in-place bitwise‐AND of this bitset and the bitset bs. More...
 
BitSet __ior__ (BitSet bs)
 Performs an in-place bitwise‐OR of this bitset and the bitset bs. More...
 
BitSet __ixor__ (BitSet bs)
 Performs an in-place bitwise‐XOR of this bitset and the bitset bs. More...
 
BitSet __isub__ (BitSet bs)
 Computes the in-place set difference of this bitset and the bitset bs. More...
 
int __long__ ()
 Returns the numeric value that corresponds to this bitset (0 if empty). More...
 
BitSet __ilshift__ (int num_bits)
 Shifts the bits to the left by num_bits positions. More...
 
BitSet __lshift__ (int num_bits)
 Shifts the bits in a copy of this bitset to the left by num_bits positions. More...
 
BitSet __irshift__ (int num_bits)
 Shifts the bits to the right by num_bits positions. More...
 
BitSet __rshift__ (int num_bits)
 Shifts the bits in a copy of this bitset to the right by num_bits positions. More...
 
BitSet __invert__ ()
 Toggles the value of every bit. More...
 
bool __eq__ (BitSet bs)
 Checks whether this bitset is equal to the bitset bs. More...
 
bool __ne__ (BitSet bs)
 Checks whether this bitset is not equal to the bitset bs. More...
 
bool __lt__ (BitSet bs)
 Checks whether this bitset is lexicographically less than the bitset bs. More...
 
bool __le__ (BitSet bs)
 Checks whether this bitset is lexicographically less or equal to the bitset bs. More...
 
bool __gt__ (BitSet bs)
 Checks whether this bitset is lexicographically greater than the bitset bs. More...
 
bool __ge__ (BitSet bs)
 Checks whether this bitset is lexicographically greater or equal to the bitset bs. More...
 
int __len__ ()
 Returns the size of the bitset. More...
 
bool __nonzero__ ()
 Checks whether at least one bit is set. More...
 
bool __bool__ ()
 Checks whether at least one bit is set. More...
 
str __str__ ()
 Returns a string representation of the BitSet instance. More...
 

Static Public Attributes

int npos = 18446744073709551615
 Specifies an invalid bit index.
 

Properties

 objectID = property(getObjectID)
 
 empty = property(isEmpty)
 
 count = property(getCount)
 
 size = property(getSize)
 
 maxSize = property(getMaxSize)
 
 any = property(hasAny)
 
 none = property(hasNone)
 

Detailed Description

Data structure for the storage and processing of variably sized bit sets.

For further information see [BDBS].

Constructor & Destructor Documentation

◆ __init__() [1/3]

None CDPL.Util.BitSet.__init__ ( BitSet  bs)

Contructs a copy of the BitSet instance bs.

Parameters
bsThe BitSet instance to copy.

◆ __init__() [2/3]

None CDPL.Util.BitSet.__init__ ( int  num_bits,
int   value = 0 
)

Constructs a BitSet instance of size num_bits initialized to the bits in value.

The first M bits (where M is the number of bits of the data type unsigned long) are initialized to the corresponding bits in value and all other bits, if any, to zero.

Parameters
num_bitsThe size of the bitset.
valueThe value to initialize the bitset from.

◆ __init__() [3/3]

None CDPL.Util.BitSet.__init__ ( str  bit_str)

Constructs a BitSet instance with size and bit values specified by the string bit_str.

The value of bit i is specified by the character '1' (= on) or '0' (= off) at index i of bit_str.

Parameters
bit_strThe string specifying the desired bit values.

Member Function Documentation

◆ getObjectID()

int CDPL.Util.BitSet.getObjectID ( )

Returns the numeric identifier (ID) of the wrapped C++ class instance.

Different Python BitSet instances may reference the same underlying C++ class instance. The commonly used Python expression a is not b thus cannot tell reliably whether the two BitSet instances a and b reference different C++ objects. The numeric identifier returned by this method allows to correctly implement such an identity test via the simple expression a.getObjectID() != b.getObjectID().

Returns
The numeric ID of the internally referenced C++ class instance.

◆ swap()

None CDPL.Util.BitSet.swap ( BitSet  bs)

Swaps the contents of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.

◆ assign()

BitSet CDPL.Util.BitSet.assign ( BitSet  bs)

Replaces the current state with a copy of the state of the BitSet instance bs.

Parameters
bsThe BitSet instance to copy.
Returns
self.

◆ resize()

None CDPL.Util.BitSet.resize ( int  num_bits,
bool   value = False 
)

Changes the number of bits to num_bits.

Parameters
num_bitsThe new size of the bitset.
valueThe value of emerging new bits.

◆ append()

None CDPL.Util.BitSet.append ( bool  value)

Increases the size of the bitset by one, and sets the value of the new most significant bit to value.

Parameters
valueThe value of the new bit.

◆ flip() [1/2]

BitSet CDPL.Util.BitSet.flip ( )

Toggles the value of every bit.

Returns
self.

◆ flip() [2/2]

BitSet CDPL.Util.BitSet.flip ( int  idx)

Toggles the value of the bit at index idx.

Parameters
idxThe zero-based index of the bit.
Returns
self.
Exceptions
Base.IndexErrorif idx is not in the range [0, getSize()).

◆ set() [1/2]

BitSet CDPL.Util.BitSet.set ( )

Sets all bits to True.

Returns
self.

◆ set() [2/2]

BitSet CDPL.Util.BitSet.set ( int  idx,
bool   value = True 
)

Sets the bit at index idx to value.

Parameters
idxThe zero-based index of the bit.
valueThe new value of the bit.
Returns
self.
Exceptions
Base.IndexErrorif idx is not in the range [0, getSize()).

◆ reset() [1/2]

BitSet CDPL.Util.BitSet.reset ( )

Sets all bits to False.

Returns
self.

◆ reset() [2/2]

BitSet CDPL.Util.BitSet.reset ( int  idx)

Sets the bit at index idx to False.

Parameters
idxThe zero-based index of the bit.
Returns
self.
Exceptions
Base.IndexErrorif idx is not in the range [0, getSize()).

◆ test()

bool CDPL.Util.BitSet.test ( int  idx)

Returns the value of the bit at index idx.

Parameters
idxThe zero-based index of the bit.
Returns
The value of the bit.
Exceptions
Base.IndexErrorif idx is not in the range [0, getSize()).

◆ findFirst()

int CDPL.Util.BitSet.findFirst ( )

Returns the index of the first set bit (if any).

Returns
The lowest zero-based index of a set bit or npos if no such bit exists.

◆ findNext()

int CDPL.Util.BitSet.findNext ( int  idx)

Returns the index of the first set bit after idx (if any).

Returns
The lowest zero-based index > idx of a set bit or npos if no such bit exists.
Exceptions
Base.IndexErrorif idx is not in the range [0, getSize()).

◆ isSubsetOf()

bool CDPL.Util.BitSet.isSubsetOf ( BitSet  bs)

Checks whether this bitset is a subset of the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
True if for every bit that is set in this bitset the corresponding bit in bs is also set, and False otherwise.

◆ isProperSubsetOf()

bool CDPL.Util.BitSet.isProperSubsetOf ( BitSet  bs)

Checks whether this bitset is a proper subset of the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
True if for every bit that is set in this bitset the corresponding bit in bs is also set and furthermore getCount() < bs.getCount(). Otherwise False is returned.

◆ isEmpty()

bool CDPL.Util.BitSet.isEmpty ( )

Checks whether this bitset has size zero.

Returns
True if the size is zero, and False otherwise.

◆ getCount()

int CDPL.Util.BitSet.getCount ( )

Returns the number of set bits.

Returns
The number of set bits.

◆ getSize()

int CDPL.Util.BitSet.getSize ( )

Returns the size of the bitset.

Returns
The size of the bitset.

◆ getMaxSize()

int CDPL.Util.BitSet.getMaxSize ( )

Returns the maximum allowed bitset size.

Returns
The maximum allowed bitset size.

◆ hasAny()

bool CDPL.Util.BitSet.hasAny ( )

Checks whether at least one bit is set.

Returns
True if at least one bit is set, and False otherwise.

◆ hasNone()

bool CDPL.Util.BitSet.hasNone ( )

Checks whether all bits are unset.

Returns
True if none of the bits is set, and False otherwise.

◆ __getitem__()

bool CDPL.Util.BitSet.__getitem__ ( int  idx)

Returns the value of the bit at index idx.

Parameters
idxThe zero-based index of the bit.
Returns
The value of the bit.
Exceptions
Base.IndexErrorif idx is not in the range [0, getSize()).

◆ __setitem__()

None CDPL.Util.BitSet.__setitem__ ( int  idx,
bool  value 
)

Sets the bit at index idx to value.

Parameters
idxThe zero-based index of the bit.
valueThe new value of the bit.
Returns
self.
Exceptions
Base.IndexErrorif idx is not in the range [0, getSize()).

◆ __and__()

BitSet CDPL.Util.BitSet.__and__ ( BitSet  bs)

Performs a bitwise‐AND of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
The result of the bitwise‐AND operation.
Exceptions
Base.ValueErrorif getSize() != bs.getSize().

◆ __or__()

BitSet CDPL.Util.BitSet.__or__ ( BitSet  bs)

Performs a bitwise‐OR of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
The result of the bitwise‐OR operation.
Exceptions
Base.ValueErrorif getSize() != bs.getSize().

◆ __xor__()

BitSet CDPL.Util.BitSet.__xor__ ( BitSet  bs)

Performs a bitwise‐XOR of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
The result of the bitwise‐XOR operation.
Exceptions
Base.ValueErrorif getSize() != bs.getSize().

◆ __sub__()

BitSet CDPL.Util.BitSet.__sub__ ( BitSet  bs)

Computes the set difference of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
The computed set difference.
Exceptions
Base.ValueErrorif getSize() != bs.getSize().

◆ __iand__()

BitSet CDPL.Util.BitSet.__iand__ ( BitSet  bs)

Performs an in-place bitwise‐AND of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
self.
Exceptions
Base.ValueErrorif getSize() != bs.getSize().

◆ __ior__()

BitSet CDPL.Util.BitSet.__ior__ ( BitSet  bs)

Performs an in-place bitwise‐OR of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
self.
Exceptions
Base.ValueErrorif getSize() != bs.getSize().

◆ __ixor__()

BitSet CDPL.Util.BitSet.__ixor__ ( BitSet  bs)

Performs an in-place bitwise‐XOR of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
self.
Exceptions
Base.ValueErrorif getSize() != bs.getSize().

◆ __isub__()

BitSet CDPL.Util.BitSet.__isub__ ( BitSet  bs)

Computes the in-place set difference of this bitset and the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
self.
Exceptions
Base.ValueErrorif getSize() != bs.getSize().

◆ __long__()

int CDPL.Util.BitSet.__long__ ( )

Returns the numeric value that corresponds to this bitset (0 if empty).

Returns
The numeric value corresponding to this bitset.
Exceptions
RuntimeErrorif that value is too large to be represented in an unsigned long.

◆ __ilshift__()

BitSet CDPL.Util.BitSet.__ilshift__ ( int  num_bits)

Shifts the bits to the left by num_bits positions.

Parameters
num_bitsThe number of positions to shift.
Returns
self.

◆ __lshift__()

BitSet CDPL.Util.BitSet.__lshift__ ( int  num_bits)

Shifts the bits in a copy of this bitset to the left by num_bits positions.

Parameters
num_bitsThe number of positions to shift.
Returns
The resulting shifted bitset.

◆ __irshift__()

BitSet CDPL.Util.BitSet.__irshift__ ( int  num_bits)

Shifts the bits to the right by num_bits positions.

Parameters
num_bitsThe number of positions to shift.
Returns
self.

◆ __rshift__()

BitSet CDPL.Util.BitSet.__rshift__ ( int  num_bits)

Shifts the bits in a copy of this bitset to the right by num_bits positions.

Parameters
num_bitsThe number of positions to shift.
Returns
The resulting shifted bitset.

◆ __invert__()

BitSet CDPL.Util.BitSet.__invert__ ( )

Toggles the value of every bit.

Returns
self.

◆ __eq__()

bool CDPL.Util.BitSet.__eq__ ( BitSet  bs)

Checks whether this bitset is equal to the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
True if this bitset is equal to bs, and False otherwise.

◆ __ne__()

bool CDPL.Util.BitSet.__ne__ ( BitSet  bs)

Checks whether this bitset is not equal to the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
True this bitset is not equal to bs, and False otherwise.

◆ __lt__()

bool CDPL.Util.BitSet.__lt__ ( BitSet  bs)

Checks whether this bitset is lexicographically less than the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
True if this bitset is lexicographically less than bs, and False otherwise.

◆ __le__()

bool CDPL.Util.BitSet.__le__ ( BitSet  bs)

Checks whether this bitset is lexicographically less or equal to the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
True if this bitset is lexicographically less or equal to bs, and False otherwise.

◆ __gt__()

bool CDPL.Util.BitSet.__gt__ ( BitSet  bs)

Checks whether this bitset is lexicographically greater than the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
True if this bitset is lexicographically greater than bs, and False otherwise.

◆ __ge__()

bool CDPL.Util.BitSet.__ge__ ( BitSet  bs)

Checks whether this bitset is lexicographically greater or equal to the bitset bs.

Parameters
bsThe other BitSet instance.
Returns
True if this bitset is lexicographically greater or equal to bs, and False otherwise.

◆ __len__()

int CDPL.Util.BitSet.__len__ ( )

Returns the size of the bitset.

Returns
The size of the bitset.

◆ __nonzero__()

bool CDPL.Util.BitSet.__nonzero__ ( )

Checks whether at least one bit is set.

Returns
True if at least one bit is set, and False otherwise.

◆ __bool__()

bool CDPL.Util.BitSet.__bool__ ( )

Checks whether at least one bit is set.

Returns
True if at least one bit is set, and False otherwise.

◆ __str__()

str CDPL.Util.BitSet.__str__ ( )

Returns a string representation of the BitSet instance.

Returns
The generated string representation.