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) : dp_bits(0), d_size(0), d_numOnBits(0) {_initForSize(size);};
31  //! initialize with a particular size and all bits set
32  ExplicitBitVect(unsigned int size, bool bitsSet);
33  ExplicitBitVect(const ExplicitBitVect& other);
34  //! construct from a string pickle
35  ExplicitBitVect(const std::string &);
36  //! construct from a text pickle
37  ExplicitBitVect(const char *,const unsigned int);
38 
40 
42  bool operator[] (const unsigned int which) const;
43  bool setBit(const unsigned int which);
44  bool unsetBit(const unsigned int which);
45  bool getBit(const unsigned int which) const;
46 
47  ExplicitBitVect operator^ (const ExplicitBitVect &other) const;
48  ExplicitBitVect operator& (const ExplicitBitVect &other) const;
49  ExplicitBitVect operator| (const ExplicitBitVect &other) const;
51  /* concatenate two ExplicitBitVects */
52  ExplicitBitVect operator+ (const ExplicitBitVect &other) const;
53 
57  /* concatenate two ExplicitBitVects */
59 
60  unsigned int getNumBits() const;
61  unsigned int getNumOnBits() const;
62  unsigned int getNumOffBits() const;
63 
64  void getOnBits (IntVect& v) const;
65 
66  void clearBits() { dp_bits->reset(); };
67  std::string toString() const;
68 
69  boost::dynamic_bitset<> *dp_bits; //!< our raw storage
70 
71  bool operator==(const ExplicitBitVect &o) const {
72  return *dp_bits==*o.dp_bits;
73  }
74  bool operator!=(const ExplicitBitVect &o) const {
75  return *dp_bits!=*o.dp_bits;
76  }
77 
78 private:
79  unsigned int d_size;
80  unsigned int d_numOnBits;
81  void _initForSize(const unsigned int size);
82 };
83 
84 
85 #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 & 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)