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 <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(bits->size()), d_numOnBits(bits->count()){};
45
46 ~ExplicitBitVect();
47
48 ExplicitBitVect &operator=(const ExplicitBitVect &other);
49 bool operator[](const unsigned int which) const;
50 bool setBit(const unsigned int which);
51 bool unsetBit(const unsigned int which);
52 bool getBit(const unsigned int which) const;
53
54 ExplicitBitVect operator^(const ExplicitBitVect &other) const;
55 ExplicitBitVect operator&(const ExplicitBitVect &other) const;
56 ExplicitBitVect operator|(const ExplicitBitVect &other) const;
57 ExplicitBitVect operator~() const;
58 /* concatenate two ExplicitBitVects */
59 ExplicitBitVect operator+(const ExplicitBitVect &other) const;
60
61 ExplicitBitVect &operator^=(const ExplicitBitVect &other);
62 ExplicitBitVect &operator&=(const ExplicitBitVect &other);
63 ExplicitBitVect &operator|=(const ExplicitBitVect &other);
64 /* concatenate two ExplicitBitVects */
65 ExplicitBitVect &operator+=(const ExplicitBitVect &other);
66
67 unsigned int getNumBits() const;
68 unsigned int getNumOnBits() const;
69 unsigned int getNumOffBits() const;
70
71 void getOnBits(IntVect &v) const;
72
73 void clearBits() { dp_bits->reset(); };
74 std::string toString() const;
75
76 boost::dynamic_bitset<> *dp_bits; //!< our raw storage
77
78 bool operator==(const ExplicitBitVect &o) const {
79 return *dp_bits == *o.dp_bits;
80 }
81 bool operator!=(const ExplicitBitVect &o) const {
82 return *dp_bits != *o.dp_bits;
83 }
84
85 private:
86 unsigned int d_size;
87 unsigned int d_numOnBits;
88 void _initForSize(const unsigned int size);
89 };
90
91 #endif
ExplicitBitVect::operator|
ExplicitBitVect operator|(const ExplicitBitVect &other) const
ExplicitBitVect::operator!=
bool operator!=(const ExplicitBitVect &o) const
Definition: ExplicitBitVect.h:81
ExplicitBitVect::operator^
ExplicitBitVect operator^(const ExplicitBitVect &other) const
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:76
ExplicitBitVect::clearBits
void clearBits()
clears (sets to off) all of our bits
Definition: ExplicitBitVect.h:73
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(boost::dynamic_bitset<> *bits)
construct directly from a dynamic_bitset pointer
Definition: ExplicitBitVect.h:43
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:30
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:28
ExplicitBitVect::operator==
bool operator==(const ExplicitBitVect &o) const
Definition: ExplicitBitVect.h:78
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:26
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)