RDKit: Composition2N.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
Composition2N.h
Go to the documentation of this file.
1//
2// Copyright (C) 2014 Novartis Institutes for BioMedical Research
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10#include <RDGeneral/export.h>
11#pragma once
12namespace RDKit {
13 namespace FMCS {
14 typedef unsigned long long BitSet;
15 class Composition2N { // generator of 2^N-1 possible bit combinations
16 BitSet Bits, InverseBits;
17 BitSet MaxValue, ValueMask; // need for inverse bitset must be 2^N-1
18 public:
19 Composition2N(BitSet maxValue, BitSet valueMask)
20 : Bits(0), InverseBits(0), MaxValue(maxValue), ValueMask(valueMask) {}
21
22 static void compute2N(unsigned int power, BitSet &value) {
23 value = 1uLL << power;
24 }
25
26 BitSet getBitSet() const {
27 return InverseBits; // inverse to generate biggest seed first and then
28 // decrease number of external bonds
29 }
30
31 bool generateNext() {
32 if ((++Bits) <= MaxValue) {
33 InverseBits = (~Bits + 1) & ValueMask;
34 return true;
35 } else {
36 return false;
37 }
38 }
39 bool is2Power() const { // one bit is set only
40 BitSet bits = getBitSet();
41 unsigned int n = 0;
42 while (0 == (bits & 1uLL) &&
43 ++n < sizeof(bits) * 8) { // find lowest bitwise 1
44 bits >>= 1u; // shift all zero lower bits
45 }
46 if (0 != (bits & 1uLL)) {
47 bits >>= 1u; // shift first set bit too
48 }
49 return 0 == bits; // remained bits except lowest 1
50 }
51 // unused: bool nonZero() {return 0!=getBitSet();}
52 bool isSet(unsigned int bit) const {
53 return 0 != (getBitSet() & (1uLL << bit));
54 }
55};
56} // namespace FMCS
57} // 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