Loading...
Searching...
No Matches
OBBitVec Class Reference

`#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)

## Detailed Description

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.nosp@m.herd.nosp@m.1@use.nosp@m.rs.s.nosp@m.ource.nosp@m.forg.nosp@m.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:

OBBitVec bv1,bv2,bv3;
bv1.SetBitOn(5);
bv2.SetBitOff(200);
bv1 |= bv2;
bv1 = bv1 & bv2;
if (bv1.IsEmpty()) // IsEmpty() returns true if no bits are set on
{
std::cout << "bv1 = " << bv1 << std::endl;
}
int bit;
for (bit = bv1.NextBit(0);bit != bv1.EndBit();bit = bv1.NextBit(bit))
{
cout << "the next bit turned on is " << bit << endl;
}
OpenBabel::OBBitVec::SetBitOn
void SetBitOn(unsigned bit_offset)
Set the bit_offset 'th bit to 1.
Definition bitvec.cpp:86
OpenBabel::OBBitVec::EndBit
int EndBit() const
Return the bit offset of the last bit (for iterating) i.e. -1.
Definition bitvec.h:115
OpenBabel::OBBitVec::NextBit
int NextBit(int last_bit_offset) const
Find the next true bit after last_bit_offset.
Definition bitvec.cpp:217
OpenBabel::OBBitVec::SetBitOff
void SetBitOff(unsigned bit_offset)
Set the bit_offset 'th bit to 0.
Definition bitvec.cpp:99
OpenBabel::OBBitVec::IsEmpty
bool IsEmpty() const
Are there no bits set to 1 in this vector?
Definition bitvec.cpp:297
OpenBabel::OBBitVec::OBBitVec
OBBitVec()
Construct a bit vector of the default size.
Definition bitvec.h:73

## Member Typedef Documentation

## word_vector

typedef std::vector<uint32_t> word_vector

## Constructor & Destructor Documentation

## OBBitVec() [1/3]

OBBitVec | ( |  | ) |

inline

Construct a bit vector of the default size.

Construct a bit vector of STARTWORDS size, cleared to all zero bits.

Referenced by OBBitVec(), operator&, operator&=(), operator+=(), operator-, operator-=(), operator<, operator<<, operator=(), operator==, operator>>, operator^, operator^=(), operator|, operator|=(), and operator|=().

## OBBitVec() [2/3]

OBBitVec | ( | unsigned | size_in_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.

Parameters

  [in] | size_in_bits | The number of bits for which to reserve space

## OBBitVec() [3/3]

OBBitVec | ( | const OBBitVec & | bv | ) |

inline

Copy constructor (result has same number of bits).

Construct a bit vector which is an exact duplicate of `bv`.

Parameters

  [in] | bv | The other bit vector to copy to this

## Member Function Documentation

## SetBitOn()

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

Parameters

  [in] | bit_offset | a zero based offset into the bit vector

Referenced by OBBuilder::AddNbrs(), OpenBabel::addNbrs(), OBRingSearch::AddRingFromClosure(), OBBuilder::Build(), OpenBabel::CanonicalLabels(), OpenBabel::CompileMoleculeQuery(), OBMol::ContigFragList(), OBDepict::DrawMolecule(), OBSmartsMatcher::FastSingleMatch(), OpenBabel::FindAutomorphisms(), OpenBabel::FindAutomorphisms(), OBMol::FindChildren(), OBMol::FindLargestFragment(), FromString(), FromVecInt(), OBResidue::GetBonds(), OpenBabel::GetDFFVector(), OBBuilder::GetFragment(), OpenBabel::getFragment(), OpenBabel::getFragment(), OBMol::GetGTDVector(), OBMol::GetNextFragment(), OpenBabel::MarkGrowBonds(), OpenBabel::OBBondGetSmallestRingSize(), operator>>, operator|=(), OBRingSearch::SaveUniqueRing(), OBRotorList::SetEvalAtoms(), SetRangeOn(), and OpenBabel::visitRing().

## SetBitOff()

void SetBitOff | ( | unsigned | bit_offset | ) |

Set the `bit_offset` 'th bit to 0.

Set the `bit_offset` 'th bit to 0

Parameters

  [in] | bit_offset | a zero based offset into the bit vector

Referenced by OBSmartsMatcher::FastSingleMatch(), OBMol::FindChildren(), and SetRangeOff().

## SetRangeOn()

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

Parameters

  [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().

## SetRangeOff()

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

Parameters

  [in] | lo_bit_offset | a zero based offset into the bit vector
  [in] | hi_bit_offset | a zero based offset into the bit vector

## Fold()

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

Parameters

  [in] | new_bit_size | the size of the resultant vector, in bits

## FirstBit()

int FirstBit | ( | unsigned | bit_offset = 0 | ) | const

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

Parameters

  [in] | bit_offset | the first bit to consider

Returns
  the bit offset of the first true bit at or after `bit_offset`, or -1 if there is none

Referenced by OBMol::CopySubstructure().

## NextBit()

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

Parameters

  [in] | last_bit_offset | the bit before the first to consider

Returns
  the bit offset of the first true bit after `last_bit_offset`, or -1 if there is none

Referenced by OpenBabel::BuildOBRTreeVector(), OBMol::ContigFragList(), OBMol::CopySubstructure(), OBMol::FindChildren(), OBMol::FindChildren(), OBMol::FindLargestFragment(), FirstBit(), OBMol::GetGTDVector(), operator<, OBRotorList::SetEvalAtoms(), and ToVecInt().

## EndBit()

int EndBit | ( |  | ) | const

inline

Return the bit offset of the last bit (for iterating) i.e. -1.

Referenced by OpenBabel::BuildOBRTreeVector(), OBMol::ContigFragList(), OBMol::CopySubstructure(), OBMol::FindChildren(), OBMol::FindChildren(), OBMol::FindLargestFragment(), OBMol::GetGTDVector(), and OBRotorList::SetEvalAtoms().

## GetSize()

size_t GetSize | ( |  | ) | const

inline

Return the number of words ( NOT the number of bits ).

Referenced by BitIsSet(), NextBit(), operator&=(), operator-=(), operator==, operator^=(), operator|=(), SetBitOff(), SetBitOn(), SetRangeOff(), and SetRangeOn().

## CountBits()

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

Returns
  the bit count

Referenced by OpenBabel::CanonicalLabels(), OpenBabel::CompileMoleculeQuery(), OBMol::ContigFragList(), OpenBabel::FindAutomorphisms(), OpenBabel::FindAutomorphisms(), OBMol::FindLargestFragment(), OpenBabel::Tanimoto(), and ToVecInt().

## IsEmpty()

bool IsEmpty | ( |  | ) | const

Are there no bits set to 1 in this vector?

Are there no bits set to 1 in this vector?

Returns
  true for "is empty", false if not empty

Referenced by OpenBabel::BuildOBRTreeVector(), OBMol::ContigFragList(), OBMol::FindChildren(), OBMol::FindChildren(), OBMol::FindLargestFragment(), OpenBabel::GetDFFVector(), OBMol::GetGTDVector(), and OBRotorList::SetEvalAtoms().

## Resize()

bool Resize | ( | unsigned | size_in_bits | ) |

inline

Reserve space for `size_in_bits` bits.

Reserve space for `size_in_bits` bits rounded up

Parameters

  [in] | size_in_bits | the number of bits

Returns
  true if enlargement was necessary, false otherwise

Referenced by OBMol::ContigFragList(), and FromString().

## ResizeWords()

bool ResizeWords | ( | unsigned | size_in_words | ) |

inline

Reserve space for `size_in_words` words.

Reserve space for `size_in_words` words

Parameters

  [in] | size_in_words | the number of words

Returns
  true if enlargement was necessary, false otherwise

Referenced by Fold(), operator-=(), operator^=(), operator|=(), Resize(), SetBitOn(), and SetRangeOn().

## BitIsSet()

bool BitIsSet | ( | unsigned | bit_offset | ) | const

inline

Asks if the `bit_offset` 'th bit is set.

Is the `bit_offset` 'th bit set ?

Parameters

  [in] | bit_offset | a zero based offset into the bit vector

Returns
  true if it is set, false otherwise

Referenced by OBBuilder::AddNbrs(), OpenBabel::addNbrs(), OBBuilder::Build(), OpenBabel::CompileAutomorphismQuery(), OpenBabel::CompileMoleculeQuery(), OBBuilder::Connect(), OBMol::ContigFragList(), OBMol::CopySubstructure(), OBDepict::DrawMolecule(), OpenBabel::FindAutomorphisms(), OBMol::FindChildren(), OBMol::FindLargestFragment(), FirstBit(), OBResidue::GetBonds(), OpenBabel::GetDFFVector(), OpenBabel::getFragment(), OBMol::GetGTDVector(), OpenBabel::OBBondGetSmallestRingSize(), and operator[]().

## FromVecInt()

void FromVecInt | ( | const std::vector< int > & | bit_offsets | ) |

Sets the bits listed as bit offsets.

Sets bits on, listed as bit offsets

Parameters

  [in] | bit_offsets | A list of bit offsets

Referenced by OBSmartsPattern::GetUMapList(), and OBSmartsPattern::Match().

## FromString()

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 ]"

Parameters

  [in] | line | A string containing positive integers
  [in] | new_bit_size | The size that the vector should become

## ToVecInt()

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.

Parameters

  [out] | bit_offsets | A list of bit offsets, in ascending order

Referenced by OBMol::ContigFragList(), and OBMol::FindChildren().

## Clear()

void Clear | ( |  | ) |

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(), OBMol::ContigFragList(), OBSmartsMatcher::FastSingleMatch(), OBMol::FindChildren(), OBMol::FindChildren(), OBMol::FindLargestFragment(), FromString(), OpenBabel::GetDFFVector(), OBMol::GetGTDVector(), OBSmartsPattern::GetUMapList(), OBSmartsPattern::Match(), OBRingSearch::RemoveRedundant(), OBRotorList::SetEvalAtoms(), OBRotorList::SetFixAtoms(), OBRotorList::SetFixedBonds(), and OpenBabel::visitRing().

## Negate()

void Negate | ( |  | ) |

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.

## GetWords()

void GetWords | ( | word_vector & | vec | ) |

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`.

Parameters

  [out] | vec | a vector of words to which to append the data

## operator=()

OBBitVec & operator= | ( | const OBBitVec & | bv | ) |

Assignment operator.

Assign this vector to be a copy of `bv`

Parameters

  [in] | bv | A bit vector

Returns
  A reference to this

## operator&=()

OBBitVec & operator&= | ( | const OBBitVec & | bv | ) |

And-equals operator.

Assign this vector to the result of And-ing it with `bv`

Parameters

  [in] | bv | A bit vector

Returns
  A reference to this

## operator|=() [1/2]

OBBitVec & operator|= | ( | const OBBitVec & | bv | ) |

Or-equals operator.

Assign this vector to the result of Or-ing it with `bv`

Parameters

  [in] | bv | A bit vector

Returns
  A reference to this

## operator|=() [2/2]

OBBitVec & operator|= | ( | int | bit_offset | ) |

inline

Or-equals operator for integer.

Or the bit at offset `bit_offset` with 1

## operator^=()

OBBitVec & operator^= | ( | const OBBitVec & | bv | ) |

Exclusive-or-equals operator.

Assign this vector to the result of Exclusive-or-ing it with `bv`

Parameters

  [in] | bv | A bit vector

Returns
  A reference to this

## operator-=()

OBBitVec & operator-= | ( | const OBBitVec & | bv | ) |

Minus-equals operator.

Unset bits in this vector which are set in `bv`

Parameters

  [in] | bv | A bit vector

Returns
  A reference to this

## operator+=()

OBBitVec & operator+= | ( | const OBBitVec & | bv | ) |

Plus-equals operator.

Append vector `bv` to the end if this vector

Parameters

  [in] | bv | A bit vector

Returns
  A reference to this

## operator[]()

bool operator[] | ( | int | bit_offset | ) | const

inline

Asks if the `bit_offset` 'th bit is set.

Is the `bit_offset` 'th bit set ?

Parameters

  [in] | bit_offset | a zero based offset into the bit vector

Returns
  true if it is set, false otherwise

## Friends And Related Symbol Documentation

## operator|

OBBitVec operator| | ( | const OBBitVec & | bv1,
|  | const OBBitVec & | bv2 )

friend

Or operator.

Return a bit vector of the results of Or-ing each bit in `bv1` with the corresponding bit in `bv2`

Parameters

  [in] | bv1 | A bit vector
  [in] | bv2 | Another bit vector

Returns
  A bit vector

## operator&

OBBitVec operator& | ( | const OBBitVec & | bv1,
|  | const OBBitVec & | bv2 )

friend

And operator.

Return a bit vector of the results of And-ing each bit in `bv1` with the corresponding bit in `bv2`

Parameters

  [in] | bv1 | A bit vector
  [in] | bv2 | Another bit vector

Returns
  A bit vector

## operator^

OBBitVec operator^ | ( | const OBBitVec & | bv1,
|  | const OBBitVec & | bv2 )

friend

Exclusive-or operator.

Return a bit vector of the results of Exclusive-or-ing each bit in `bv1` with the corresponding bit in `bv2`

Parameters

  [in] | bv1 | A bit vector
  [in] | bv2 | Another bit vector

Returns
  A bit vector

## operator-

OBBitVec operator- | ( | const OBBitVec & | bv1,
|  | const OBBitVec & | bv2 )

friend

Minus operator.

Return a bit vector of the results of clearing each bit in `bv1` which is set in `bv2`

Parameters

  [in] | bv1 | A bit vector
  [in] | bv2 | Another bit vector

Returns
  A bit vector

## operator==

bool operator== | ( | const OBBitVec & | bv1,
|  | const OBBitVec & | bv2 )

friend

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.

Parameters

  [in] | bv1 | A bit vector
  [in] | bv2 | Another bit vector

Returns
  true if equal, false otherwise

## operator<

bool operator< | ( | const OBBitVec & | bv1,
|  | const OBBitVec & | bv2 )

friend

Smaller-than operator.

Return true if `bv1` i less than `bv2` Lexicographical order, with bit vectors written LSB first.

Parameters

  [in] | bv1 | A bit vector
  [in] | bv2 | Another bit vector

Returns
  true if equal, false otherwise

## operator>>

std::istream & operator>> | ( | std::istream & | is,
|  | OBBitVec & | bv )

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 ]"

Parameters

  [in,out] | is | The input stream
  [out] | bv | The bit vector to contain the result

## operator<<

std::ostream & operator<< | ( | std::ostream & | os,
|  | const OBBitVec & | bv )

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 ]"

Parameters

  [out] | os | The output stream
  [in] | bv | The bit vector to be output

The documentation for this class was generated from the following files:

- bitvec.h
- bitvec.cpp