Loading...
Searching...
No Matches
ExplicitBitVect.h
Go to the documentation of this file.
//
// Copyright (c) 2003-208 greg Landrum and Rational Discovery LLC
// Copyright (c) 2014, Novartis Institutes for BioMedical Research Inc.
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef __RD_EXPLICITBITVECTS_H__
#define __RD_EXPLICITBITVECTS_H__
#include <RDGeneral/BoostStartInclude.h>
#include <boost/dynamic_bitset.hpp>
#include <RDGeneral/BoostEndInclude.h>
#include "BitVect.h"
//! a class for bit vectors that are densely occupied
/*!
ExplicitBitVect objects store all of their bits using
a boost::dynamic_bitset
These are very fast, but can require large amounts of memory for large,
sparsely occupied vectors.
*/
class RDKIT_DATASTRUCTS_EXPORT ExplicitBitVect : public BitVect {
public:
ExplicitBitVect() {}
//! initialize with a particular size;
explicit ExplicitBitVect(unsigned int size)
: dp_bits(nullptr), d_size(0), d_numOnBits(0) {
_initForSize(size);
}
//! initialize with a particular size and all bits set
ExplicitBitVect(unsigned int size, bool bitsSet);
ExplicitBitVect(const ExplicitBitVect &other);
ExplicitBitVect(ExplicitBitVect &&other) noexcept;
//! construct from a string pickle
ExplicitBitVect(const std::string &pkl);
//! construct from a text pickle
ExplicitBitVect(const char *, const unsigned int);
//! construct directly from a dynamic_bitset pointer
/// takes ownership of the pointer
ExplicitBitVect(boost::dynamic_bitset<> *bits)
: dp_bits(bits),
d_size(static_cast<unsigned int>(bits->size())),
d_numOnBits(static_cast<unsigned int>(bits->count())) {}
~ExplicitBitVect() override;
ExplicitBitVect &operator=(const ExplicitBitVect &other);
ExplicitBitVect &operator=(ExplicitBitVect &&other) noexcept;
bool operator[](const unsigned int which) const override;
bool setBit(const unsigned int which) override;
bool unsetBit(const unsigned int which) override;
bool getBit(const unsigned int which) const override;
ExplicitBitVect operator^(const ExplicitBitVect &other) const;
ExplicitBitVect operator&(const ExplicitBitVect &other) const;
ExplicitBitVect operator|(const ExplicitBitVect &other) const;
ExplicitBitVect operator~() const;
/* concatenate two ExplicitBitVects */
ExplicitBitVect operator+(const ExplicitBitVect &other) const;
ExplicitBitVect &operator^=(const ExplicitBitVect &other);
ExplicitBitVect &operator&=(const ExplicitBitVect &other);
ExplicitBitVect &operator|=(const ExplicitBitVect &other);
/* concatenate two ExplicitBitVects */
ExplicitBitVect &operator+=(const ExplicitBitVect &other);
unsigned int getNumBits() const override;
unsigned int getNumOnBits() const override;
unsigned int getNumOffBits() const override;
void getOnBits(IntVect &v) const override;
void clearBits() override { dp_bits->reset(); }
std::string toString() const override;
std::unique_ptr<boost::dynamic_bitset<>> dp_bits{
nullptr}; //!< our raw storage
bool operator==(const ExplicitBitVect &o) const {
return *dp_bits == *o.dp_bits;
}
bool operator!=(const ExplicitBitVect &o) const {
return *dp_bits != *o.dp_bits;
}
private:
unsigned int d_size{0};
unsigned int d_numOnBits{0};
void _initForSize(const unsigned int size) override;
};
#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
ExplicitBitVect
a class for bit vectors that are densely occupied
Definition ExplicitBitVect.h:29
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:81