RDKit: ExplicitBitVect.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 <RDGeneral/BoostStartInclude.h>
15 #include <boost/dynamic_bitset.hpp>
16 #include <RDGeneral/BoostEndInclude.h>
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
49 ~ExplicitBitVect();
50
51 ExplicitBitVect &operator=(const ExplicitBitVect &other);
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
64 ExplicitBitVect &operator^=(const ExplicitBitVect &other);
65 ExplicitBitVect &operator&=(const ExplicitBitVect &other);
66 ExplicitBitVect &operator|=(const ExplicitBitVect &other);
67 /* concatenate two ExplicitBitVects */
68 ExplicitBitVect &operator+=(const ExplicitBitVect &other);
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|
ExplicitBitVect operator|(const ExplicitBitVect &other) const
ExplicitBitVect::operator!=
bool operator!=(const ExplicitBitVect &o) const
Definition: ExplicitBitVect.h:84
ExplicitBitVect::operator^
ExplicitBitVect operator^(const ExplicitBitVect &other) const
BoostStartInclude.h
ExplicitBitVect::unsetBit
bool unsetBit(const unsigned int which)
unsets a particular bit and returns its original value
ExplicitBitVect::operator~
ExplicitBitVect operator~() const
ExplicitBitVect::operator+
ExplicitBitVect operator+(const ExplicitBitVect &other) const
ExplicitBitVect::operator^=
ExplicitBitVect & operator^=(const ExplicitBitVect &other)
ExplicitBitVect::operator[]
bool operator[](const unsigned int which) const
ExplicitBitVect::dp_bits
boost::dynamic_bitset * dp_bits
our raw storage
Definition: ExplicitBitVect.h:79
ExplicitBitVect::clearBits
void clearBits()
clears (sets to off) all of our bits
Definition: ExplicitBitVect.h:76
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(boost::dynamic_bitset<> *bits)
construct directly from a dynamic_bitset pointer
Definition: ExplicitBitVect.h:45
ExplicitBitVect::operator=
ExplicitBitVect & operator=(const ExplicitBitVect &other)
ExplicitBitVect::operator+=
ExplicitBitVect & operator+=(const ExplicitBitVect &other)
ExplicitBitVect::getNumOnBits
unsigned int getNumOnBits() const
returns the number of on bits
ExplicitBitVect::toString
std::string toString() const
returns a serialized (pickled) version of this BitVect
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(unsigned int size)
initialize with a particular size;
Definition: ExplicitBitVect.h:32
BoostEndInclude.h
ExplicitBitVect::getNumBits
unsigned int getNumBits() const
returns the number of bits (the length of the BitVect)
ExplicitBitVect::~ExplicitBitVect
~ExplicitBitVect()
ExplicitBitVect::getOnBits
void getOnBits(IntVect &v) const
replaces the contents of v with indices of our on bits
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect()
Definition: ExplicitBitVect.h:30
ExplicitBitVect::operator==
bool operator==(const ExplicitBitVect &o) const
Definition: ExplicitBitVect.h:81
ExplicitBitVect::getNumOffBits
unsigned int getNumOffBits() const
returns the number of off bits
BitVect::size
unsigned int size() const
Definition: BitVect.h:61
ExplicitBitVect::setBit
bool setBit(const unsigned int which)
sets a particular bit and returns its original value
ExplicitBitVect::operator|=
ExplicitBitVect & operator|=(const ExplicitBitVect &other)
ExplicitBitVect::operator&
ExplicitBitVect operator&(const ExplicitBitVect &other) const
BitVect.h
IntVect
std::vector< int > IntVect
Definition: BitVect.h:16
ExplicitBitVect
a class for bit vectors that are densely occupied
Definition: ExplicitBitVect.h:28
ExplicitBitVect::getBit
bool getBit(const unsigned int which) const
returns the value of a particular bit
BitVect
Abstract base class for storing BitVectors.
Definition: BitVect.h:23
ExplicitBitVect::operator&=
ExplicitBitVect & operator&=(const ExplicitBitVect &other)