diff --git a/Code/DataStructs/ExplicitBitVect.cpp b/Code/DataStructs/ExplicitBitVect.cpp index ea72e42a7..84690cc84 100644 --- a/Code/DataStructs/ExplicitBitVect.cpp +++ b/Code/DataStructs/ExplicitBitVect.cpp @@ -1,6 +1,7 @@ // $Id$ // // Copyright (c) 2001-2008 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. @@ -111,6 +112,24 @@ ExplicitBitVect::ExplicitBitVect(const char *data,const unsigned int dataLen) return(ans); }; + ExplicitBitVect& ExplicitBitVect::operator^= (const ExplicitBitVect &other) { + *(dp_bits) ^= *(other.dp_bits); + d_numOnBits=dp_bits->count(); + return *this; + }; + + ExplicitBitVect& ExplicitBitVect::operator&= (const ExplicitBitVect &other) { + *(dp_bits) &= *(other.dp_bits); + d_numOnBits=dp_bits->count(); + return *this; + }; + + ExplicitBitVect& ExplicitBitVect::operator|= (const ExplicitBitVect &other) { + *(dp_bits) |= *(other.dp_bits); + d_numOnBits=dp_bits->count(); + return *this; + }; + ExplicitBitVect ExplicitBitVect::operator~ () const { ExplicitBitVect ans(d_size); *(ans.dp_bits) = ~(*dp_bits); @@ -118,6 +137,24 @@ ExplicitBitVect::ExplicitBitVect(const char *data,const unsigned int dataLen) return(ans); }; + ExplicitBitVect& ExplicitBitVect::operator+= (const ExplicitBitVect &other) { + dp_bits->resize(d_size+other.d_size); + unsigned int original_size = d_size; + d_size = dp_bits->size(); + for(unsigned i=0;icount(); + return *this; + }; + + ExplicitBitVect ExplicitBitVect::operator+ (const ExplicitBitVect &other) const { + ExplicitBitVect ans(*this); + return ans+=other; + }; + unsigned int ExplicitBitVect::getNumBits() const { return d_size; }; diff --git a/Code/DataStructs/ExplicitBitVect.h b/Code/DataStructs/ExplicitBitVect.h index 7a021d04d..957572c0e 100644 --- a/Code/DataStructs/ExplicitBitVect.h +++ b/Code/DataStructs/ExplicitBitVect.h @@ -1,5 +1,6 @@ // -// Copyright (c) 2003-2008 greg Landrum and Rational Discovery LLC +// 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. @@ -47,13 +48,21 @@ public: 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; unsigned int getNumOnBits() const; unsigned int getNumOffBits() const; void getOnBits (IntVect& v) const; - // FIX: complete these void clearBits() { dp_bits->reset(); }; std::string toString() const; diff --git a/Code/DataStructs/Wrap/wrap_ExplicitBV.cpp b/Code/DataStructs/Wrap/wrap_ExplicitBV.cpp index ad4dcadb7..78e68e4f3 100644 --- a/Code/DataStructs/Wrap/wrap_ExplicitBV.cpp +++ b/Code/DataStructs/Wrap/wrap_ExplicitBV.cpp @@ -88,9 +88,11 @@ struct EBV_wrapper { .def(python::self & python::self) .def(python::self | python::self) .def(python::self ^ python::self) + .def(python::self + python::self) .def(~python::self) .def(python::self == python::self) .def(python::self != python::self) + .def(python::self += python::self) .def_pickle(ebv_pickle_suite()) ; diff --git a/Code/DataStructs/testDatastructs.cpp b/Code/DataStructs/testDatastructs.cpp index 5a6a667ff..661de7a50 100644 --- a/Code/DataStructs/testDatastructs.cpp +++ b/Code/DataStructs/testDatastructs.cpp @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2001-2010 Greg Landrum and Rational Discovery LLC +// Copyright (C) 2001-2014 Greg Landrum and Rational Discovery LLC // // @@ All Rights Reserved @@ // This file is part of the RDKit. @@ -1296,6 +1296,17 @@ void test13BitVectAllOnes() { } } +void test18BitVectConcatenation() { + { + ExplicitBitVect bv(32, false); + ExplicitBitVect bv2(32, true); + ExplicitBitVect bv3 = bv + bv2; + TEST_ASSERT(bv3.getNumBits() == 64); + TEST_ASSERT(bv3.getNumOnBits() == 32); + TEST_ASSERT(bv3.getNumOffBits() == 32); + } +} + int main(){ RDLog::InitLogs(); try{ @@ -1363,6 +1374,9 @@ int main(){ BOOST_LOG(rdInfoLog) << " Test BitVect with all ones -------------------------------" << std::endl; test13BitVectAllOnes(); + BOOST_LOG(rdInfoLog) << " Test Explicit BitVects: Concatenation Operation -------------------------------" << std::endl; + test18BitVectConcatenation(); + return 0; }