RDKit: ExplicitBitVect.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
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
15#include <RDGeneral/BoostStartInclude.h>
16#include <boost/dynamic_bitset.hpp>
17#include <RDGeneral/BoostEndInclude.h>
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 */
29 class RDKIT_DATASTRUCTS_EXPORT ExplicitBitVect : public BitVect {
30 public:
31 ExplicitBitVect() {}
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);
39 ExplicitBitVect(const ExplicitBitVect &other);
40 ExplicitBitVect(ExplicitBitVect &&other) noexcept;
41 //! construct from a string pickle
42 ExplicitBitVect(const std::string &pkl);
43 //! construct from a text pickle
44 ExplicitBitVect(const char *, const unsigned int);
45 //! construct directly from a dynamic_bitset pointer
46 /// takes ownership of the pointer
47 ExplicitBitVect(boost::dynamic_bitset<> *bits)
48 : dp_bits(bits),
49 d_size(static_cast<unsigned int>(bits->size())),
50 d_numOnBits(static_cast<unsigned int>(bits->count())) {}
51
52 ~ExplicitBitVect() override;
53
54 ExplicitBitVect &operator=(const ExplicitBitVect &other);
55 ExplicitBitVect &operator=(ExplicitBitVect &&other) noexcept;
56 bool operator[](const unsigned int which) const override;
57 bool setBit(const unsigned int which) override;
58 bool unsetBit(const unsigned int which) override;
59 bool getBit(const unsigned int which) const override;
60
61 ExplicitBitVect operator^(const ExplicitBitVect &other) const;
62 ExplicitBitVect operator&(const ExplicitBitVect &other) const;
63 ExplicitBitVect operator|(const ExplicitBitVect &other) const;
64 ExplicitBitVect operator~() const;
65 /* concatenate two ExplicitBitVects */
66 ExplicitBitVect operator+(const ExplicitBitVect &other) const;
67
68 ExplicitBitVect &operator^=(const ExplicitBitVect &other);
69 ExplicitBitVect &operator&=(const ExplicitBitVect &other);
70 ExplicitBitVect &operator|=(const ExplicitBitVect &other);
71 /* concatenate two ExplicitBitVects */
72 ExplicitBitVect &operator+=(const ExplicitBitVect &other);
73
74 unsigned int getNumBits() const override;
75 unsigned int getNumOnBits() const override;
76 unsigned int getNumOffBits() const override;
77
78 void getOnBits(IntVect &v) const override;
79
80 void clearBits() override { dp_bits->reset(); }
81 std::string toString() const override;
82
83 std::unique_ptr<boost::dynamic_bitset<>> dp_bits{
84 nullptr}; //!< our raw storage
85
86 bool operator==(const ExplicitBitVect &o) const {
87 return *dp_bits == *o.dp_bits;
88 }
89 bool operator!=(const ExplicitBitVect &o) const {
90 return *dp_bits != *o.dp_bits;
91 }
92
93 private:
94 unsigned int d_size{0};
95 unsigned int d_numOnBits{0};
96 void _initForSize(const unsigned int size) override;
97};
98
99#endif
BitVect.h
IntVect
std::vector< int > IntVect
Definition BitVect.h:17
BoostEndInclude.h
BoostStartInclude.h
BitVect
Abstract base class for storing BitVectors.
Definition BitVect.h:24
BitVect::size
unsigned int size() const
Definition BitVect.h:62
ExplicitBitVect::operator!=
bool operator!=(const ExplicitBitVect &o) const
Definition ExplicitBitVect.h:89
ExplicitBitVect::getNumOnBits
unsigned int getNumOnBits() const override
returns the number of on bits
ExplicitBitVect::getBit
bool getBit(const unsigned int which) const override
returns the value of a particular bit
ExplicitBitVect::dp_bits
std::unique_ptr< boost::dynamic_bitset<> > dp_bits
our raw storage
Definition ExplicitBitVect.h:83
ExplicitBitVect::operator^
ExplicitBitVect operator^(const ExplicitBitVect &other) const
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(unsigned int size)
initialize with a particular size;
Definition ExplicitBitVect.h:33
ExplicitBitVect::operator=
ExplicitBitVect & operator=(ExplicitBitVect &&other) noexcept
ExplicitBitVect::operator|
ExplicitBitVect operator|(const ExplicitBitVect &other) const
ExplicitBitVect::setBit
bool setBit(const unsigned int which) override
sets a particular bit and returns its original value
ExplicitBitVect::operator+=
ExplicitBitVect & operator+=(const ExplicitBitVect &other)
ExplicitBitVect::getOnBits
void getOnBits(IntVect &v) const override
replaces the contents of v with indices of our on bits
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(const std::string &pkl)
construct from a string pickle
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(const char *, const unsigned int)
construct from a text pickle
ExplicitBitVect::operator[]
bool operator[](const unsigned int which) const override
ExplicitBitVect::operator~
ExplicitBitVect operator~() const
ExplicitBitVect::operator|=
ExplicitBitVect & operator|=(const ExplicitBitVect &other)
ExplicitBitVect::clearBits
void clearBits() override
clears (sets to off) all of our bits
Definition ExplicitBitVect.h:80
ExplicitBitVect::operator^=
ExplicitBitVect & operator^=(const ExplicitBitVect &other)
ExplicitBitVect::operator+
ExplicitBitVect operator+(const ExplicitBitVect &other) const
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect()
Definition ExplicitBitVect.h:31
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(ExplicitBitVect &&other) noexcept
ExplicitBitVect::operator=
ExplicitBitVect & operator=(const ExplicitBitVect &other)
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(unsigned int size, bool bitsSet)
initialize with a particular size and all bits set
ExplicitBitVect::toString
std::string toString() const override
returns a serialized (pickled) version of this BitVect
ExplicitBitVect::operator==
bool operator==(const ExplicitBitVect &o) const
Definition ExplicitBitVect.h:86
ExplicitBitVect::operator&=
ExplicitBitVect & operator&=(const ExplicitBitVect &other)
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(const ExplicitBitVect &other)
ExplicitBitVect::~ExplicitBitVect
~ExplicitBitVect() override
ExplicitBitVect::unsetBit
bool unsetBit(const unsigned int which) override
unsets a particular bit and returns its original value
ExplicitBitVect::operator&
ExplicitBitVect operator&(const ExplicitBitVect &other) const
ExplicitBitVect::ExplicitBitVect
ExplicitBitVect(boost::dynamic_bitset<> *bits)
Definition ExplicitBitVect.h:47
ExplicitBitVect::getNumBits
unsigned int getNumBits() const override
returns the number of bits (the length of the BitVect)
ExplicitBitVect::getNumOffBits
unsigned int getNumOffBits() const override
returns the number of off bits
export.h
RDKIT_DATASTRUCTS_EXPORT
#define RDKIT_DATASTRUCTS_EXPORT
Definition export.h:89