RDKit
Open-source cheminformatics and machine learning.
ExplicitBitVect.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2003-208 greg Landrum and Rational Discovery LLC
3 // Copyright (c) 2014, Novartis Institutes for BioMedical Research Inc.
4 //
5 // @@ All Rights Reserved @@
6 // This file is part of the RDKit.
7 // The contents are covered by the terms of the BSD license
8 // which is included in the file license.txt, found at the root
9 // of the RDKit source tree.
10 //
11 #ifndef __RD_EXPLICITBITVECTS_H__
12 #define __RD_EXPLICITBITVECTS_H__
13 
15 #include <boost/dynamic_bitset.hpp>
17 #include "BitVect.h"
18 
19 //! a class for bit vectors that are densely occupied
20 /*!
21  ExplicitBitVect objects store all of their bits using
22  a boost::dynamic_bitset
23 
24  These are very fast, but can require large amounts of memory for large,
25  sparsely occupied vectors.
26 
27  */
28 class ExplicitBitVect : public BitVect {
29  public:
30  ExplicitBitVect() : dp_bits(0), d_size(0), d_numOnBits(0){};
31  //! initialize with a particular size;
32  explicit ExplicitBitVect(unsigned int size)
33  : dp_bits(0), d_size(0), d_numOnBits(0) {
34  _initForSize(size);
35  };
36  //! initialize with a particular size and all bits set
37  ExplicitBitVect(unsigned int size, bool bitsSet);
38  ExplicitBitVect(const ExplicitBitVect &other);
39  //! construct from a string pickle
40  ExplicitBitVect(const std::string &);
41  //! construct from a text pickle
42  ExplicitBitVect(const char *, const unsigned int);
43  //! construct directly from a dynamic_bitset pointer
44  // takes ownership of the pointer
45  ExplicitBitVect(boost::dynamic_bitset<> *bits)
46  : dp_bits(bits), d_size(static_cast<unsigned int>(bits->size())),
47  d_numOnBits(static_cast<unsigned int>(bits->count())){};
48 
50 
52  bool operator[](const unsigned int which) const;
53  bool setBit(const unsigned int which);
54  bool unsetBit(const unsigned int which);
55  bool getBit(const unsigned int which) const;
56 
57  ExplicitBitVect operator^(const ExplicitBitVect &other) const;
58  ExplicitBitVect operator&(const ExplicitBitVect &other) const;
59  ExplicitBitVect operator|(const ExplicitBitVect &other) const;
60  ExplicitBitVect operator~() const;
61  /* concatenate two ExplicitBitVects */
62  ExplicitBitVect operator+(const ExplicitBitVect &other) const;
63 
67  /* concatenate two ExplicitBitVects */
69 
70  unsigned int getNumBits() const;
71  unsigned int getNumOnBits() const;
72  unsigned int getNumOffBits() const;
73 
74  void getOnBits(IntVect &v) const;
75 
76  void clearBits() { dp_bits->reset(); };
77  std::string toString() const;
78 
79  boost::dynamic_bitset<> *dp_bits; //!< our raw storage
80 
81  bool operator==(const ExplicitBitVect &o) const {
82  return *dp_bits == *o.dp_bits;
83  }
84  bool operator!=(const ExplicitBitVect &o) const {
85  return *dp_bits != *o.dp_bits;
86  }
87 
88  private:
89  unsigned int d_size;
90  unsigned int d_numOnBits;
91  void _initForSize(const unsigned int size);
92 };
93 
94 #endif
ExplicitBitVect operator|(const ExplicitBitVect &other) const
bool operator!=(const ExplicitBitVect &o) const
ExplicitBitVect operator^(const ExplicitBitVect &other) const
bool unsetBit(const unsigned int which)
unsets a particular bit and returns its original value
ExplicitBitVect operator~() const
ExplicitBitVect operator+(const ExplicitBitVect &other) const
ExplicitBitVect & operator^=(const ExplicitBitVect &other)
bool operator[](const unsigned int which) const
boost::dynamic_bitset * dp_bits
our raw storage
void clearBits()
clears (sets to off) all of our bits
ExplicitBitVect(boost::dynamic_bitset<> *bits)
construct directly from a dynamic_bitset pointer
ExplicitBitVect & operator=(const ExplicitBitVect &other)
ExplicitBitVect & operator+=(const ExplicitBitVect &other)
unsigned int getNumOnBits() const
returns the number of on bits
std::string toString() const
returns a serialized (pickled) version of this BitVect
ExplicitBitVect(unsigned int size)
initialize with a particular size;
unsigned int getNumBits() const
returns the number of bits (the length of the BitVect)
void getOnBits(IntVect &v) const
replaces the contents of v with indices of our on bits
bool operator==(const ExplicitBitVect &o) const
unsigned int getNumOffBits() const
returns the number of off bits
unsigned int size() const
Definition: BitVect.h:61
bool setBit(const unsigned int which)
sets a particular bit and returns its original value
ExplicitBitVect & operator|=(const ExplicitBitVect &other)
ExplicitBitVect operator&(const ExplicitBitVect &other) const
std::vector< int > IntVect
Definition: BitVect.h:16
a class for bit vectors that are densely occupied
bool getBit(const unsigned int which) const
returns the value of a particular bit
Abstract base class for storing BitVectors.
Definition: BitVect.h:23
ExplicitBitVect & operator&=(const ExplicitBitVect &other)