Loading...
Searching...
No Matches
Composition2N.h
Go to the documentation of this file.
//
// Copyright (C) 2014 Novartis Institutes for BioMedical Research
//
// @@ 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>
#pragma once
namespace RDKit {
namespace FMCS {
typedef unsigned long long BitSet;
class Composition2N { // generator of 2^N-1 possible bit combinations
BitSet Bits, InverseBits;
BitSet MaxValue, ValueMask; // need for inverse bitset must be 2^N-1
public:
Composition2N(BitSet maxValue, BitSet valueMask)
: Bits(0), InverseBits(0), MaxValue(maxValue), ValueMask(valueMask) {}
static void compute2N(unsigned int power, BitSet &value) {
value = 1uLL << power;
}
BitSet getBitSet() const {
return InverseBits; // inverse to generate biggest seed first and then
// decrease number of external bonds
}
bool generateNext() {
if ((++Bits) <= MaxValue) {
InverseBits = (~Bits + 1) & ValueMask;
return true;
} else {
return false;
}
}
bool is2Power() const { // one bit is set only
BitSet bits = getBitSet();
unsigned int n = 0;
while (0 == (bits & 1uLL) &&
++n < sizeof(bits) * 8) { // find lowest bitwise 1
bits >>= 1u; // shift all zero lower bits
}
if (0 != (bits & 1uLL)) {
bits >>= 1u; // shift first set bit too
}
return 0 == bits; // remained bits except lowest 1
}
// unused: bool nonZero() {return 0!=getBitSet();}
bool isSet(unsigned int bit) const {
return 0 != (getBitSet() & (1uLL << bit));
}
};
} // namespace FMCS
} // namespace RDKit
RDKit::FMCS::Composition2N::getBitSet
BitSet getBitSet() const
Definition Composition2N.h:26
RDKit::FMCS::Composition2N::Composition2N
Composition2N(BitSet maxValue, BitSet valueMask)
Definition Composition2N.h:19
RDKit::FMCS::Composition2N::generateNext
bool generateNext()
Definition Composition2N.h:31
RDKit::FMCS::Composition2N::is2Power
bool is2Power() const
Definition Composition2N.h:39
RDKit::FMCS::Composition2N::compute2N
static void compute2N(unsigned int power, BitSet &value)
Definition Composition2N.h:22
RDKit::FMCS::Composition2N::isSet
bool isSet(unsigned int bit) const
Definition Composition2N.h:52
export.h
RDKit::FMCS
Definition Composition2N.h:13
RDKit::FMCS::BitSet
unsigned long long BitSet
Definition Composition2N.h:14
RDKit
Std stuff.
Definition Abbreviations.h:19