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:
32  //! initialize with a particular size;
33  explicit ExplicitBitVect(unsigned int size)
34  : dp_bits(nullptr), 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);
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),
48  d_size(static_cast<unsigned int>(bits->size())),
49  d_numOnBits(static_cast<unsigned int>(bits->count())){};
50 
52 
54  bool operator[](const unsigned int which) const;
55  bool setBit(const unsigned int which);
56  bool unsetBit(const unsigned int which);
57  bool getBit(const unsigned int which) const;
58 
63  /* concatenate two ExplicitBitVects */
65 
69  /* concatenate two ExplicitBitVects */
71 
72  unsigned int getNumBits() const;
73  unsigned int getNumOnBits() const;
74  unsigned int getNumOffBits() const;
75 
76  void getOnBits(IntVect &v) const;
77 
78  void clearBits() { dp_bits->reset(); };
79  std::string toString() const;
80 
81  boost::dynamic_bitset<> *dp_bits{nullptr}; //!< our raw storage
82 
83  bool operator==(const ExplicitBitVect &o) const {
84  return *dp_bits == *o.dp_bits;
85  }
86  bool operator!=(const ExplicitBitVect &o) const {
87  return *dp_bits != *o.dp_bits;
88  }
89 
90  private:
91  unsigned int d_size{0};
92  unsigned int d_numOnBits{0};
93  void _initForSize(const unsigned int size);
94 };
95 
96 #endif
std::vector< int > IntVect
Definition: BitVect.h:17
Abstract base class for storing BitVectors.
Definition: BitVect.h:24
a class for bit vectors that are densely occupied
unsigned int getNumBits() const
returns the number of bits (the length of the BitVect)
bool operator!=(const ExplicitBitVect &o) const
boost::dynamic_bitset * dp_bits
our raw storage
std::string toString() const
returns a serialized (pickled) version of this BitVect
ExplicitBitVect(const std::string &)
construct from a string pickle
bool operator[](const unsigned int which) const
ExplicitBitVect operator^(const ExplicitBitVect &other) const
ExplicitBitVect(unsigned int size)
initialize with a particular size;
ExplicitBitVect operator|(const ExplicitBitVect &other) const
ExplicitBitVect & operator=(const ExplicitBitVect &other)
ExplicitBitVect(const char *, const unsigned int)
construct from a text pickle
void clearBits()
clears (sets to off) all of our bits
bool getBit(const unsigned int which) const
returns the value of a particular bit
bool setBit(const unsigned int which)
sets a particular bit and returns its original value
ExplicitBitVect operator~() const
unsigned int getNumOnBits() const
returns the number of on bits
ExplicitBitVect & operator|=(const ExplicitBitVect &other)
unsigned int getNumOffBits() const
returns the number of off bits
bool unsetBit(const unsigned int which)
unsets a particular bit and returns its original value
ExplicitBitVect & operator+=(const ExplicitBitVect &other)
ExplicitBitVect operator+(const ExplicitBitVect &other) const
ExplicitBitVect & operator^=(const ExplicitBitVect &other)
ExplicitBitVect & operator&=(const ExplicitBitVect &other)
void getOnBits(IntVect &v) const
replaces the contents of v with indices of our on bits
ExplicitBitVect(unsigned int size, bool bitsSet)
initialize with a particular size and all bits set
bool operator==(const ExplicitBitVect &o) const
ExplicitBitVect(const ExplicitBitVect &other)
ExplicitBitVect operator&(const ExplicitBitVect &other) const
ExplicitBitVect(boost::dynamic_bitset<> *bits)
construct directly from a dynamic_bitset pointer
#define RDKIT_DATASTRUCTS_EXPORT
Definition: export.h:138