ExplicitBitVect.h

Go to the documentation of this file.
00001 //
00002 // Copyright (c) 2003-2008 greg Landrum and Rational Discovery LLC
00003 //
00004 //  @@ All Rights Reserved @@
00005 //  This file is part of the RDKit.
00006 //  The contents are covered by the terms of the BSD license
00007 //  which is included in the file license.txt, found at the root
00008 //  of the RDKit source tree.
00009 //
00010 #ifndef __RD_EXPLICITBITVECTS_H__
00011 #define __RD_EXPLICITBITVECTS_H__
00012 
00013 #include <boost/dynamic_bitset.hpp>
00014 #include "BitVect.h"
00015 
00016 //! a class for bit vectors that are densely occupied
00017 /*!
00018     ExplicitBitVect objects store all of their bits using
00019     a boost::dynamic_bitset
00020 
00021     These are very fast, but can require large amounts of memory for large,
00022     sparsely occupied vectors.
00023 
00024  */
00025 class ExplicitBitVect : public BitVect {
00026 public:
00027   ExplicitBitVect() : dp_bits(0), d_size(0), d_numOnBits(0) {};
00028   //! initialize with a particular size;
00029   explicit ExplicitBitVect(unsigned int size) : dp_bits(0), d_size(0), d_numOnBits(0) {_initForSize(size);};
00030   ExplicitBitVect(const ExplicitBitVect& other);
00031   //! construct from a string pickle
00032   ExplicitBitVect(const std::string &);
00033   //! construct from a text pickle
00034   ExplicitBitVect(const char *,const unsigned int);
00035   
00036   ~ExplicitBitVect();
00037 
00038   ExplicitBitVect& operator=(const ExplicitBitVect& other);
00039   bool operator[] (const unsigned int which) const;
00040   bool setBit(const unsigned int which);
00041   bool unsetBit(const unsigned int which);
00042   bool getBit(const unsigned int which) const;
00043 
00044   ExplicitBitVect operator^ (const ExplicitBitVect &other) const;
00045   ExplicitBitVect operator& (const ExplicitBitVect &other) const;
00046   ExplicitBitVect operator| (const ExplicitBitVect &other) const;
00047   ExplicitBitVect operator~ () const;
00048   unsigned int getNumBits() const;
00049   unsigned int getNumOnBits() const;
00050   unsigned int getNumOffBits() const;
00051 
00052   void getOnBits (IntVect& v) const;
00053 
00054   // FIX: complete these
00055   void clearBits() { dp_bits->reset(); };
00056   std::string toString() const;
00057   
00058   boost::dynamic_bitset<> *dp_bits; //!< our raw storage
00059 
00060   bool operator==(const ExplicitBitVect &o) const {
00061     return *dp_bits==*o.dp_bits;
00062   }
00063   bool operator!=(const ExplicitBitVect &o) const {
00064     return *dp_bits!=*o.dp_bits;
00065   }
00066 
00067 private:
00068   unsigned int d_size;
00069   unsigned int d_numOnBits;
00070   void _initForSize(const unsigned int size);
00071 };
00072 
00073 
00074 #endif