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 {
13namespace FMCS {
14typedef unsigned long long BitSet;
15class 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:
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
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
Composition2N(BitSet maxValue, BitSet valueMask)
static void compute2N(unsigned int power, BitSet &value)
bool isSet(unsigned int bit) const
unsigned long long BitSet
Std stuff.
bool rdvalue_is(const RDValue_cast_t)