mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
first pass, using google style
This commit is contained in:
@@ -14,62 +14,63 @@
|
||||
#include "DatastructsException.h"
|
||||
|
||||
namespace RDKit {
|
||||
void _fillDistMat(unsigned int dmat[], unsigned int nBits) {
|
||||
unsigned int i,j, a, b, ta, tb, dist;
|
||||
int temp;
|
||||
unsigned int mask = ((1<<nBits) -1);
|
||||
for (i = 0; i < 256; ++i) {
|
||||
for (j = 0; j < 256; ++j) {
|
||||
dist = 0;
|
||||
a = i;
|
||||
b = j;
|
||||
while (a || b) {
|
||||
ta = a&mask;
|
||||
tb = b&mask;
|
||||
temp = ta-tb;
|
||||
if (temp > 0) {
|
||||
dist += temp;
|
||||
} else {
|
||||
dist -= temp;
|
||||
}
|
||||
a >>= nBits;
|
||||
b >>= nBits;
|
||||
void _fillDistMat(unsigned int dmat[], unsigned int nBits) {
|
||||
unsigned int i, j, a, b, ta, tb, dist;
|
||||
int temp;
|
||||
unsigned int mask = ((1 << nBits) - 1);
|
||||
for (i = 0; i < 256; ++i) {
|
||||
for (j = 0; j < 256; ++j) {
|
||||
dist = 0;
|
||||
a = i;
|
||||
b = j;
|
||||
while (a || b) {
|
||||
ta = a & mask;
|
||||
tb = b & mask;
|
||||
temp = ta - tb;
|
||||
if (temp > 0) {
|
||||
dist += temp;
|
||||
} else {
|
||||
dist -= temp;
|
||||
}
|
||||
dmat[i*256 + j] = dist;
|
||||
a >>= nBits;
|
||||
b >>= nBits;
|
||||
}
|
||||
dmat[i * 256 + j] = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DiscreteDistMat::DiscreteDistMat() {
|
||||
// fill in the distance matrix table
|
||||
DiscreteDistMat::DiscreteDistMat() {
|
||||
// fill in the distance matrix table
|
||||
|
||||
// one bit per value table
|
||||
_fillDistMat(d_oneBitTab, 1);
|
||||
// one bit per value table
|
||||
_fillDistMat(d_oneBitTab, 1);
|
||||
|
||||
// two bits per value table
|
||||
_fillDistMat(d_twoBitTab, 2);
|
||||
// two bits per value table
|
||||
_fillDistMat(d_twoBitTab, 2);
|
||||
|
||||
// four bits per value table
|
||||
_fillDistMat(d_fourBitTab, 4);
|
||||
}
|
||||
// four bits per value table
|
||||
_fillDistMat(d_fourBitTab, 4);
|
||||
}
|
||||
|
||||
unsigned int DiscreteDistMat::getDist(unsigned char v1,
|
||||
unsigned char v2,
|
||||
DiscreteValueVect::DiscreteValueType type) {
|
||||
unsigned int res=0;
|
||||
int temp;
|
||||
unsigned int id = static_cast<unsigned int>(v1)*256 + static_cast<unsigned int>(v2);
|
||||
switch(type) {
|
||||
case DiscreteValueVect::ONEBITVALUE :
|
||||
unsigned int DiscreteDistMat::getDist(
|
||||
unsigned char v1, unsigned char v2,
|
||||
DiscreteValueVect::DiscreteValueType type) {
|
||||
unsigned int res = 0;
|
||||
int temp;
|
||||
unsigned int id =
|
||||
static_cast<unsigned int>(v1) * 256 + static_cast<unsigned int>(v2);
|
||||
switch (type) {
|
||||
case DiscreteValueVect::ONEBITVALUE:
|
||||
res = d_oneBitTab[id];
|
||||
break;
|
||||
case DiscreteValueVect::TWOBITVALUE :
|
||||
case DiscreteValueVect::TWOBITVALUE:
|
||||
res = d_twoBitTab[id];
|
||||
break;
|
||||
case DiscreteValueVect::FOURBITVALUE :
|
||||
case DiscreteValueVect::FOURBITVALUE:
|
||||
res = d_fourBitTab[id];
|
||||
break;
|
||||
case DiscreteValueVect::EIGHTBITVALUE :
|
||||
case DiscreteValueVect::EIGHTBITVALUE:
|
||||
temp = static_cast<unsigned int>(v1) - static_cast<unsigned int>(v2);
|
||||
if (temp < 0) {
|
||||
res -= temp;
|
||||
@@ -80,13 +81,10 @@ namespace RDKit {
|
||||
default:
|
||||
// ummm.. we shouldn't have come here
|
||||
throw DatastructsException("We shouldn't be here");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static DiscreteDistMat discreteDMat;
|
||||
DiscreteDistMat *getDiscreteDistMat() {
|
||||
return &discreteDMat;
|
||||
}
|
||||
|
||||
}
|
||||
static DiscreteDistMat discreteDMat;
|
||||
DiscreteDistMat *getDiscreteDistMat() { return &discreteDMat; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user