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