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 #include <RDGeneral/export.h>
12 #ifndef __RD_EXPLICITBITVECTS_H__
13 #define __RD_EXPLICITBITVECTS_H__
14 
16 #include <boost/dynamic_bitset.hpp>
18 #include "BitVect.h"
19 
20 //! a class for bit vectors that are densely occupied
21 /*!
22  ExplicitBitVect objects store all of their bits using
23  a boost::dynamic_bitset
24 
25  These are very fast, but can require large amounts of memory for large,
26  sparsely occupied vectors.
27 
28  */
30  public:
31  ExplicitBitVect() : dp_bits(0), d_size(0), d_numOnBits(0){};
32  //! initialize with a particular size;
33  explicit ExplicitBitVect(unsigned int size)
34  : dp_bits(0), d_size(0), d_numOnBits(0) {
35  _initForSize(size);
36  };
37  //! initialize with a particular size and all bits set
38  ExplicitBitVect(unsigned int size, bool bitsSet);
39  ExplicitBitVect(const ExplicitBitVect &other);
40  //! construct from a string pickle
41  ExplicitBitVect(const std::string &);
42  //! construct from a text pickle
43  ExplicitBitVect(const char *, const unsigned int);
44  //! construct directly from a dynamic_bitset pointer
45  // takes ownership of the pointer
46  ExplicitBitVect(boost::dynamic_bitset<> *bits)
47  : dp_bits(bits), d_size(static_cast<unsigned int>(bits->size())),
48  d_numOnBits(static_cast<unsigned int>(bits->count())){};
49 
50  ~ExplicitBitVect();
51 
52  ExplicitBitVect &operator=(const ExplicitBitVect &other);
53  bool operator[](const unsigned int which) const;
54  bool setBit(const unsigned int which);
55  bool unsetBit(const unsigned int which);
56  bool getBit(const unsigned int which) const;
57 
58  ExplicitBitVect operator^(const ExplicitBitVect &other) const;
59  ExplicitBitVect operator&(const ExplicitBitVect &other) const;
60  ExplicitBitVect operator|(const ExplicitBitVect &other) const;
61  ExplicitBitVect operator~() const;
62  /* concatenate two ExplicitBitVects */
63  ExplicitBitVect operator+(const ExplicitBitVect &other) const;
64 
65  ExplicitBitVect &operator^=(const ExplicitBitVect &other);
66  ExplicitBitVect &operator&=(const ExplicitBitVect &other);
67  ExplicitBitVect &operator|=(const ExplicitBitVect &other);
68  /* concatenate two ExplicitBitVects */
69  ExplicitBitVect &operator+=(const ExplicitBitVect &other);
70 
71  unsigned int getNumBits() const;
72  unsigned int getNumOnBits() const;
73  unsigned int getNumOffBits() const;
74 
75  void getOnBits(IntVect &v) const;
76 
77  void clearBits() { dp_bits->reset(); };
78  std::string toString() const;
79 
80  boost::dynamic_bitset<> *dp_bits; //!< our raw storage
81 
82  bool operator==(const ExplicitBitVect &o) const {
83  return *dp_bits == *o.dp_bits;
84  }
85  bool operator!=(const ExplicitBitVect &o) const {
86  return *dp_bits != *o.dp_bits;
87  }
88 
89  private:
90  unsigned int d_size;
91  unsigned int d_numOnBits;
92  void _initForSize(const unsigned int size);
93 };
94 
95 #endif
boost::dynamic_bitset * dp_bits
our raw storage
void clearBits()
clears (sets to off) all of our bits
bool operator==(const ExplicitBitVect &o) const
ExplicitBitVect(boost::dynamic_bitset<> *bits)
construct directly from a dynamic_bitset pointer
#define RDKIT_DATASTRUCTS_EXPORT
Definition: export.h:112
virtual unsigned int getNumBits() const =0
returns the number of bits (the length of the BitVect)
ExplicitBitVect(unsigned int size)
initialize with a particular size;
virtual bool unsetBit(const unsigned int which)=0
unsets a particular bit and returns its original value
virtual bool operator[](const unsigned int which) const =0
bool operator!=(const ExplicitBitVect &o) const
virtual unsigned int getNumOffBits() const =0
returns the number of off bits
virtual bool getBit(const unsigned int which) const =0
returns the value of a particular bit
virtual void getOnBits(IntVect &v) const =0
replaces the contents of v with indices of our on bits
std::vector< int > IntVect
Definition: BitVect.h:17
virtual std::string toString() const =0
returns a serialized (pickled) version of this BitVect
a class for bit vectors that are densely occupied
RDKIT_DATASTRUCTS_EXPORT DiscreteValueVect operator+(const DiscreteValueVect &p1, const DiscreteValueVect &p2)
Abstract base class for storing BitVectors.
Definition: BitVect.h:24
virtual unsigned int getNumOnBits() const =0
returns the number of on bits
virtual bool setBit(const unsigned int which)=0
sets a particular bit and returns its original value