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 
14 #include <boost/dynamic_bitset.hpp>
15 #include "BitVect.h"
16 
17 //! a class for bit vectors that are densely occupied
18 /*!
19  ExplicitBitVect objects store all of their bits using
20  a boost::dynamic_bitset
21 
22  These are very fast, but can require large amounts of memory for large,
23  sparsely occupied vectors.
24 
25  */
26 class ExplicitBitVect : public BitVect {
27  public:
28  ExplicitBitVect() : dp_bits(0), d_size(0), d_numOnBits(0){};
29  //! initialize with a particular size;
30  explicit ExplicitBitVect(unsigned int size)
31  : dp_bits(0), d_size(0), d_numOnBits(0) {
32  _initForSize(size);
33  };
34  //! initialize with a particular size and all bits set
35  ExplicitBitVect(unsigned int size, bool bitsSet);
36  ExplicitBitVect(const ExplicitBitVect &other);
37  //! construct from a string pickle
38  ExplicitBitVect(const std::string &);
39  //! construct from a text pickle
40  ExplicitBitVect(const char *, const unsigned int);
41  //! construct directly from a dynamic_bitset pointer
42  // takes ownership of the pointer
43  ExplicitBitVect(boost::dynamic_bitset<> *bits)
44  : dp_bits(bits), d_size(static_cast<unsigned int>(bits->size())),
45  d_numOnBits(static_cast<unsigned int>(bits->count())){};
46 
48 
50  bool operator[](const unsigned int which) const;
51  bool setBit(const unsigned int which);
52  bool unsetBit(const unsigned int which);
53  bool getBit(const unsigned int which) const;
54 
55  ExplicitBitVect operator^(const ExplicitBitVect &other) const;
56  ExplicitBitVect operator&(const ExplicitBitVect &other) const;
57  ExplicitBitVect operator|(const ExplicitBitVect &other) const;
58  ExplicitBitVect operator~() const;
59  /* concatenate two ExplicitBitVects */
60  ExplicitBitVect operator+(const ExplicitBitVect &other) const;
61 
65  /* concatenate two ExplicitBitVects */
67 
68  unsigned int getNumBits() const;
69  unsigned int getNumOnBits() const;
70  unsigned int getNumOffBits() const;
71 
72  void getOnBits(IntVect &v) const;
73 
74  void clearBits() { dp_bits->reset(); };
75  std::string toString() const;
76 
77  boost::dynamic_bitset<> *dp_bits; //!< our raw storage
78 
79  bool operator==(const ExplicitBitVect &o) const {
80  return *dp_bits == *o.dp_bits;
81  }
82  bool operator!=(const ExplicitBitVect &o) const {
83  return *dp_bits != *o.dp_bits;
84  }
85 
86  private:
87  unsigned int d_size;
88  unsigned int d_numOnBits;
89  void _initForSize(const unsigned int size);
90 };
91 
92 #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)