RDKit
Open-source cheminformatics and machine learning.
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 #pragma once
11 namespace RDKit {
12 namespace FMCS {
13 typedef unsigned long long BitSet;
14 class Composition2N { // generator of 2^N-1 possible bit combinations
15  BitSet Bits, InverseBits;
16  BitSet MaxValue, ValueMask; // need for inverse bitset must be 2^N-1
17  public:
18  Composition2N(BitSet maxValue, BitSet valueMask)
19  : Bits(0), InverseBits(0), MaxValue(maxValue), ValueMask(valueMask) {}
20 
21  static void compute2N(unsigned power, BitSet& value) {
22  value = 1uLL << power;
23  }
24 
25  BitSet getBitSet() const {
26  return InverseBits; // inverse to generate biggest seed first and then
27  // decrease number of external bonds
28  }
29 
30  bool generateNext() {
31  if ((++Bits) <= MaxValue) {
32  InverseBits = (~Bits + 1) & ValueMask;
33  return true;
34  } else
35  return false;
36  }
37  bool is2Power() const { // one bit is set only
38  BitSet bits = getBitSet();
39  unsigned n = 0;
40  while (0 == (bits & 1uLL) &&
41  ++n < sizeof(bits) * 8) // find lowest bitwise 1
42  bits >>= 1u; // shift all zero lower bits
43  if (0 != (bits & 1uLL)) bits >>= 1u; // shift first set bit too
44  return 0 == bits; // remained bits except lowest 1
45  }
46  // unused: bool nonZero() {return 0!=getBitSet();}
47  bool isSet(unsigned bit) const { return 0 != (getBitSet() & (1uLL << bit)); }
48 };
49 }
50 }
Composition2N(BitSet maxValue, BitSet valueMask)
Definition: Composition2N.h:18
BitSet getBitSet() const
Definition: Composition2N.h:25
bool isSet(unsigned bit) const
Definition: Composition2N.h:47
unsigned long long BitSet
Definition: Composition2N.h:13
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
static void compute2N(unsigned power, BitSet &value)
Definition: Composition2N.h:21