// the contents of v are blown out void ExplicitBitVect::getOnBits (IntVect& v) const { unsigned int nOn = getNumOnBits(); if(!v.empty()) IntVect().swap(v); v.reserve(nOn); for(unsigned int i=0;i<d_size;i++){ if((bool)(*dp_bits)[i]) v.push_back(i); } };
// """ ------------------------------------------------------- // // getOnBits(IntVect &which) // C++: Passes the set of on bits out in the IntVect passed in. // The contents of IntVect are destroyed. // // Python: Returns the tuple of on bits // // """ ------------------------------------------------------- void SparseBitVect::getOnBits(IntVect &v) const { if (!dp_bits) { throw ValueErrorException("BitVect not properly initialized."); } unsigned int nOn = getNumOnBits(); if (!v.empty()) IntVect().swap(v); v.reserve(nOn); v.resize(nOn); std::copy(dp_bits->begin(), dp_bits->end(), v.begin()); };
// """ ------------------------------------------------------- // // toString() // Returns a binary string with the contents of the BitVector // // """ ------------------------------------------------------- std::string SparseBitVect::toString() const { // This Function replaces the older version (version 16) of writing the onbits // to // a string // the old version does not perform any run length encoding, it only checks to // see if // the length of the bitvect can be short ints and writes the on bits as // shorts // other wise the onbits are all written as ints // here we do run length encoding and the version number has been bumped to 32 // as well. // only the reader needs to take care of readinf all legacy versions // also in this scheme each bit number written to the string is checked to see // how many // bytes it needs std::stringstream ss(std::ios_base::binary | std::ios_base::out | std::ios_base::in); boost::int32_t tInt = ci_BITVECT_VERSION * -1; RDKit::streamWrite(ss, tInt); tInt = d_size; RDKit::streamWrite(ss, tInt); tInt = getNumOnBits(); RDKit::streamWrite(ss, tInt); int prev = -1; unsigned int zeroes; for (IntSetIter i = dp_bits->begin(); i != dp_bits->end(); i++) { zeroes = *i - prev - 1; RDKit::appendPackedIntToStream(ss, zeroes); prev = *i; } zeroes = d_size - prev - 1; RDKit::appendPackedIntToStream(ss, zeroes); std::string res(ss.str()); return res; }