Open Babel
3.0
|
#include <openbabel/bitvec.h>
Public Types | |
typedef std::vector< uint32_t > | word_vector |
Public Member Functions | |
OBBitVec () | |
OBBitVec (unsigned size_in_bits) | |
OBBitVec (const OBBitVec &bv) | |
void | SetBitOn (unsigned bit_offset) |
void | SetBitOff (unsigned bit_offset) |
void | SetRangeOn (unsigned lo_bit_offset, unsigned hi_bit_offset) |
void | SetRangeOff (unsigned lo_bit_offset, unsigned hi_bit_offset) |
void | Fold (unsigned new_bit_size) |
int | FirstBit (unsigned bit_offset=0) const |
int | NextBit (int last_bit_offset) const |
int | EndBit () const |
size_t | GetSize () const |
unsigned | CountBits () const |
bool | IsEmpty () const |
bool | Resize (unsigned size_in_bits) |
bool | ResizeWords (unsigned size_in_words) |
bool | BitIsSet (unsigned bit_offset) const |
void | FromVecInt (const std::vector< int > &bit_offsets) |
void | FromString (const std::string &line, int bits) |
void | ToVecInt (std::vector< int > &bit_offsets) const |
void | Clear () |
void | Negate () |
void | GetWords (word_vector &vec) |
OBBitVec & | operator= (const OBBitVec &bv) |
OBBitVec & | operator &= (const OBBitVec &bv) |
OBBitVec & | operator|= (const OBBitVec &bv) |
OBBitVec & | operator|= (int bit_offset) |
OBBitVec & | operator^= (const OBBitVec &bv) |
OBBitVec & | operator-= (const OBBitVec &bv) |
OBBitVec & | operator+= (const OBBitVec &bv) |
bool | operator[] (int bit_offset) const |
Friends | |
OBBitVec | operator| (const OBBitVec &bv1, const OBBitVec &bv2) |
OBBitVec | operator & (const OBBitVec &bv1, const OBBitVec &bv2) |
OBBitVec | operator^ (const OBBitVec &bv1, const OBBitVec &bv2) |
OBBitVec | operator- (const OBBitVec &bv1, const OBBitVec &bv2) |
bool | operator== (const OBBitVec &bv1, const OBBitVec &bv2) |
bool | operator< (const OBBitVec &bv1, const OBBitVec &bv2) |
std::istream & | operator>> (std::istream &is, OBBitVec &bv) |
std::ostream & | operator<< (std::ostream &os, const OBBitVec &bv) |
A speed-optimized vector of bits.
Fast and efficient bitstring class.
This class implements a fast vector of bits using internally a vector of fixed size unsigned ints (uint32_t). Any bits which are out of reach of the current size are considered to be zero. Streamlined, corrected and documented by kshep herd 1@use rs.s ource forg e.net
The OBBitVec class is a fast and efficient bitstring class that is handy to use as a truth table. Truth tables are an easy way to store whether a list of items has a particular property. Instances of OBBitVec can be dynamically resized, and have a number of overloaded operators that make code simple and readable. The following examples demonstrate uses of the OBBitVec class:
typedef std::vector<uint32_t> word_vector |
|
inline |
Construct a bit vector of the default size.
Construct a bit vector of STARTWORDS size, cleared to all zero bits.
|
inline |
Construct a bit vector of maxbits bits.
Construct a bit vector with a size in bits of size_in_bits
rounded up to the nearest word and cleared to all zero bits.
[in] | size_in_bits | The number of bits for which to reserve space |
Copy constructor (result has same number of bits)
Construct a bit vector which is an exact duplicate of bv
.
[in] | bv | The other bit vector to copy to this |
void SetBitOn | ( | unsigned | bit_offset | ) |
Set the bit_offset
'th bit to 1.
Set the bit_offset
'th bit to 1 Increases the size of this bit vector if necessary
[in] | bit_offset | a zero based offset into the bit vector |
Referenced by OBDepict::AddAtomLabels(), OpenBabel::addNbrs(), OBBuilder::AddNbrs(), OBRingSearch::AddRingFromClosure(), OBBuilder::Build(), OpenBabel::CanonicalLabels(), OpenBabel::ComparePairSecond(), OpenBabel::CompileMoleculeQuery(), OBMol::ContigFragList(), OBBuilder::CorrectStereoAtoms(), OBDepict::DrawMolecule(), OpenBabel::FindAutomorphisms(), OBMol::FindChildren(), OBMol::FindLargestFragment(), OpenBabel::findMetalloceneBonds(), OBBitVec::FromString(), OBBitVec::FromVecInt(), OBResidue::GetBonds(), OpenBabel::GetDFFVector(), OpenBabel::getFragment(), OBBuilder::GetFragment(), OBMol::GetGTDVector(), OBMol::GetNextFragment(), OpenBabel::MarkGrowBonds(), OpenBabel::NeedsDoubleBond(), OpenBabel::OBBondGetSmallestRingSize(), OpenBabel::operator>>(), OBRingSearch::SaveUniqueRing(), OBRotorList::SetEvalAtoms(), OBBitVec::SetRangeOn(), OBAlign::SetRefMol(), and OpenBabel::visitRing().
void SetBitOff | ( | unsigned | bit_offset | ) |
Set the bit_offset
'th bit to 0.
Set the bit_offset
'th bit to 0
[in] | bit_offset | a zero based offset into the bit vector |
Referenced by OBMol::FindChildren(), OpenBabel::findMetalloceneBonds(), OpenBabel::NeedsDoubleBond(), OBMolAtomBFSIter::OBMolAtomBFSIter(), OBMolAtomDFSIter::OBMolAtomDFSIter(), OBMolBondBFSIter::OBMolBondBFSIter(), OBMolAtomDFSIter::operator++(), OBMolAtomBFSIter::operator++(), OBMolBondBFSIter::operator++(), and OBBitVec::SetRangeOff().
void SetRangeOn | ( | unsigned | lo_bit_offset, |
unsigned | hi_bit_offset | ||
) |
Set the range of bits from lo_bit_offset
to hi_bit_offset
to 1.
Set the range of bits from lo_bit_offset
to hi_bit_offset
to 1 Increases the size of this bit vector if necessary
[in] | lo_bit_offset | a zero based offset into the bit vector |
[in] | hi_bit_offset | a zero based offset into the bit vector |
Referenced by OBBuilder::Connect(), OBMolAtomBFSIter::OBMolAtomBFSIter(), OBMolAtomDFSIter::OBMolAtomDFSIter(), and OBMolBondBFSIter::OBMolBondBFSIter().
void SetRangeOff | ( | unsigned | lo_bit_offset, |
unsigned | hi_bit_offset | ||
) |
Set the range of bits from lo_bit_offset
to hi_bit_offset
to 0.
Set the range of bits from lo_bit_offset
to hi_bit_offset
to 0
[in] | lo_bit_offset | a zero based offset into the bit vector |
[in] | hi_bit_offset | a zero based offset into the bit vector |
void Fold | ( | unsigned | new_bit_size | ) |
Reduce the size of the vector by or-ing the excess bits over the start.
Reduce the size of the vector to new_bit_size
by or-ing the excess bits over the start of the vector
[in] | new_bit_size | the size of the resultant vector, in bits |
|
inline |
Find the first true bit at or after bit_offset
.
Searches the vector for the first true value, starting at the bit_offset
'th bit
[in] | bit_offset | the first bit to consider |
bit_offset
, or -1 if there is none Referenced by OBMol::CopySubstructure(), OBMolAtomDFSIter::operator++(), OBMolAtomBFSIter::operator++(), and OBMolBondBFSIter::operator++().
int NextBit | ( | int | last_bit_offset | ) | const |
Find the next true bit after last_bit_offset
.
Searches the vector for the first true value, starting at the last_bit_offset
'th bit
[in] | last_bit_offset | the bit before the first to consider |
last_bit_offset
, or -1 if there is none Referenced by OpenBabel::BuildOBRTreeVector(), OpenBabel::ComparePairSecond(), OBMol::ContigFragList(), OBMol::CopySubstructure(), OBMol::FindChildren(), OBMol::FindLargestFragment(), OpenBabel::GetDFFVector(), OBMol::GetGTDVector(), OpenBabel::operator<(), OBRotorList::SetEvalAtoms(), and OBBitVec::ToVecInt().
|
inline |
Return the bit offset of the last bit (for iterating) i.e. -1.
Referenced by OpenBabel::BuildOBRTreeVector(), OpenBabel::ComparePairSecond(), OBMol::ContigFragList(), OBMol::CopySubstructure(), OBMol::FindChildren(), OBMol::FindLargestFragment(), OpenBabel::GetDFFVector(), OBMol::GetGTDVector(), OBMolAtomDFSIter::operator++(), OBMolAtomBFSIter::operator++(), OBMolBondBFSIter::operator++(), and OBRotorList::SetEvalAtoms().
|
inline |
Return the number of words ( NOT the number of bits ).
Referenced by OBBitVec::NextBit(), OBBitVec::operator-=(), OBBitVec::operator=(), OpenBabel::operator==(), OBBitVec::operator^=(), OBBitVec::operator|=(), OBBitVec::SetBitOff(), OBBitVec::SetBitOn(), OBBitVec::SetRangeOff(), and OBBitVec::SetRangeOn().
unsigned CountBits | ( | ) | const |
Return the number of bits which are set to 1 in the vector.
Count the number of bits which are set in this vector
Referenced by OpenBabel::CanonicalLabels(), OpenBabel::CompileMoleculeQuery(), OBMol::ContigFragList(), OpenBabel::FindAutomorphisms(), OBMol::FindLargestFragment(), OpenBabel::findMetalloceneBonds(), OpenBabel::Tanimoto(), and OBBitVec::ToVecInt().
bool IsEmpty | ( | ) | const |
Are there no bits set to 1 in this vector?
Are there no bits set to 1 in this vector?
Referenced by OpenBabel::BuildOBRTreeVector(), OpenBabel::ComparePairSecond(), OBMol::ContigFragList(), OBMol::FindChildren(), OBMol::FindLargestFragment(), OpenBabel::GetDFFVector(), OBMol::GetGTDVector(), OBRotorList::HasFixedAtoms(), OBRotorList::HasFixedBonds(), and OBRotorList::SetEvalAtoms().
|
inline |
Reserve space for size_in_bits
bits.
Reserve space for size_in_bits
bits rounded up
[in] | size_in_bits | the number of bits |
Referenced by OpenBabel::ComparePairSecond(), OBMol::ContigFragList(), OBBitVec::FromString(), OBMolAtomBFSIter::OBMolAtomBFSIter(), OBMolAtomDFSIter::OBMolAtomDFSIter(), OBMolBondBFSIter::OBMolBondBFSIter(), OBRing::OBRing(), and OBAlign::SetRefMol().
|
inline |
Reserve space for size_in_words
words.
Reserve space for size_in_words
words
[in] | size_in_words | the number of words |
Referenced by OBBitVec::Fold(), OBBitVec::operator-=(), OBBitVec::operator^=(), OBBitVec::operator|=(), OBBitVec::SetBitOn(), and OBBitVec::SetRangeOn().
|
inline |
Asks if the bit_offset
'th bit is set.
Is the bit_offset
'th bit set ?
[in] | bit_offset | a zero based offset into the bit vector |
Referenced by OBDepict::AddAtomLabels(), OpenBabel::addNbrs(), OBBuilder::AddNbrs(), OBAlign::Align(), OBBuilder::Build(), OpenBabel::ComparePairSecond(), OpenBabel::CompileAutomorphismQuery(), OpenBabel::CompileMoleculeQuery(), OBBuilder::Connect(), OBMol::ContigFragList(), OBMol::CopySubstructure(), OBBuilder::CorrectStereoAtoms(), OpenBabel::FindAutomorphisms(), OBMol::FindChildren(), OBMol::FindLargestFragment(), OpenBabel::findMetalloceneBonds(), OBResidue::GetBonds(), OpenBabel::GetDFFVector(), OpenBabel::getFragment(), OBMol::GetGTDVector(), OBRing::IsInRing(), OBBuilder::IsSpiroAtom(), OpenBabel::NeedsDoubleBond(), and OpenBabel::OBBondGetSmallestRingSize().
void FromVecInt | ( | const std::vector< int > & | bit_offsets | ) |
Sets the bits listed as bit offsets.
Sets bits on, listed as bit offsets
[in] | bit_offsets | A list of bit offsets |
Referenced by OBSmartsPattern::GetUMapList(), OBSmartsPattern::Match(), and OBRing::OBRing().
void FromString | ( | const std::string & | line, |
int | new_bit_size | ||
) |
Sets the bits listed as a string of integers.
Sets bits on, listed as a string of character-represented integers This bit vector is first cleared. The format is "[ n0 n1 n2 n3 ... ]". The square brackets are optional. The whitespace can be SPACE, NEWLINE or HTAB For example "[ 1 5 6 9 ]"
[in] | line | A string containing positive integers |
[in] | new_bit_size | The size that the vector should become |
void ToVecInt | ( | std::vector< int > & | bit_offsets | ) | const |
List the offsets of the bits which are set.
Retrieve a list of bit offsets The bit_offsets
vector is first cleared.
[out] | bit_offsets | A list of bit offsets, in ascending order |
Referenced by OBMol::ContigFragList(), and OBMol::FindChildren().
void Clear | ( | void | ) |
Set all bits to zero.
Set all the bits in this vector to zero Does not currently change the size of the vector.
Referenced by OpenBabel::BuildOBRTreeVector(), OpenBabel::ComparePairSecond(), OBMol::ContigFragList(), OBMol::FindChildren(), OBMol::FindLargestFragment(), OBBitVec::FromString(), OpenBabel::GetDFFVector(), OBMol::GetGTDVector(), OBSmartsPattern::GetUMapList(), OBSmartsPattern::Match(), OBRingSearch::RemoveRedundant(), OBRotorList::SetEvalAtoms(), OBRotorList::SetFixAtoms(), OBRotorList::SetFixedBonds(), OBAlign::SetRefMol(), and OpenBabel::visitRing().
|
inline |
Inverts every bit in the vector.
Inverts the entire vector. Note that this may give unexpected results, as the vector can be considered to end in an arbitrary number of zero bits.
|
inline |
Return a copy of the internal vector of words, at the end of vec
.
Copy the internal word vector. The copy is appended to vec
.
[out] | vec | a vector of words to which to append the data |
Assignment operator.
Assign this vector to be a copy of bv
[in] | bv | A bit vector |
And-equals operator.
Referenced by OBBitVec::operator=().
Or-equals operator.
Assign this vector to the result of Or-ing it with bv
[in] | bv | A bit vector |
|
inline |
Or-equals operator for integer.
Or the bit at offset bit_offset
with 1
Exclusive-or-equals operator.
Assign this vector to the result of Exclusive-or-ing it with bv
[in] | bv | A bit vector |
Minus-equals operator.
Unset bits in this vector which are set in bv
[in] | bv | A bit vector |
Plus-equals operator.
Append vector bv
to the end if this vector
[in] | bv | A bit vector |
|
inline |
Asks if the bit_offset
'th bit is set.
Is the bit_offset
'th bit set ?
[in] | bit_offset | a zero based offset into the bit vector |
Or operator.
Return a bit vector of the results of Or-ing each bit in bv1
with the corresponding bit in bv2
[in] | bv1 | A bit vector |
[in] | bv2 | Another bit vector |
And operator.
Return a bit vector of the results of And-ing each bit in bv1
with the corresponding bit in bv2
[in] | bv1 | A bit vector |
[in] | bv2 | Another bit vector |
Exclusive-or operator.
Return a bit vector of the results of Exclusive-or-ing each bit in bv1
with the corresponding bit in bv2
[in] | bv1 | A bit vector |
[in] | bv2 | Another bit vector |
Minus operator.
Return a bit vector of the results of clearing each bit in bv1
which is set in bv2
[in] | bv1 | A bit vector |
[in] | bv2 | Another bit vector |
Equivalency operator.
Return true if bv1
and bv2
are equivalent Not that they may be of different size, and still equivalent provided that the extra bits are all zero.
[in] | bv1 | A bit vector |
[in] | bv2 | Another bit vector |
Smaller-than operator.
Return true if bv1
i less than bv2
Lexicographical order, with bit vectors written LSB first.
[in] | bv1 | A bit vector |
[in] | bv2 | Another bit vector |
|
friend |
Input from a stream.
Sets bits on, listed as a string of character-represented integers in a stream Only reads one line of input The format is "[ n0 n1 n2 n3 ... ]". The square brackets are optional. The whitespace can be SPACE or HTAB For example "[ 1 5 6 9 ]"
[in,out] | is | The input stream |
[out] | bv | The bit vector to contain the result |
|
friend |
Output to a stream.
Output this bit vector to a stream The format is "[ n0 n1 n2 n3 ... ]". The whitespace is SPACE For example "[ 1 5 6 9 ]"
[out] | os | The output stream |
[in] | bv | The bit vector to be output |