File: types.cpp

package info (click to toggle)
rdkit 201203-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 37,840 kB
  • sloc: cpp: 93,902; python: 51,897; java: 5,192; ansic: 3,497; xml: 2,499; sql: 1,641; yacc: 1,518; lex: 1,076; makefile: 325; fortran: 183; sh: 153; cs: 51
file content (92 lines) | stat: -rw-r--r-- 2,197 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// $Id: types.cpp 1625 2011-01-13 04:22:56Z glandrum $
//
//                 Copyright 2001-2006
//                   Rational Discovery LLC 
//
//  @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
//


#include "types.h"

namespace RDKit{
//  template <typename T>
//  T larger_of(T arg1,T arg2) { return arg1>arg2 ? arg1 : arg2; };

double round(double num){
  double floorVal = floor(num);
  double ceilVal = ceil(num);
  return num-floorVal > ceilVal-num ? ceilVal : floorVal;
};


  void Union(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res) {
    res.resize(0);
    res = r1;
    INT_VECT_CI ri;
    for (ri = r2.begin(); ri != r2.end(); ri++) {
      if (std::find(res.begin(), res.end(), (*ri)) == res.end()){
	res.push_back(*ri);
      }
    }
  }

  void Intersect(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res) {
    res.resize(0);
    INT_VECT_CI ri;
    for (ri = r1.begin(); ri != r1.end(); ri++) {
      if (std::find(r2.begin(), r2.end(), (*ri)) != r2.end()){
	res.push_back(*ri);
      }
    }
  }

  void Union(const VECT_INT_VECT &rings, INT_VECT &res, const INT_VECT *exclude) {
    res.resize(0);
    INT_VECT ring;
    unsigned int id;
    unsigned int nrings = static_cast<unsigned int>(rings.size());
    INT_VECT_CI ri;
    
    for (id = 0; id < nrings; id++) {
      if (exclude) {
	if (std::find(exclude->begin(), exclude->end(), static_cast<int>(id)) != exclude->end()) {
	  continue;
	}
      }
      ring = rings[id];
      for (ri = ring.begin(); ri != ring.end(); ri++) {
	if (std::find(res.begin(), res.end(), (*ri)) == res.end()) {
	  res.push_back(*ri);
	}
      }
    }
  }

  int nextCombination(INT_VECT &comb, int tot) {
    int nelem = static_cast<int>(comb.size());
    int celem = nelem - 1;
    
    while (comb[celem] == (tot - nelem + celem)) {
      celem--;
      if (celem < 0) {
	return -1;
      }
    }

    unsigned int i;
    comb[celem] += 1;
    for (i = celem+1; i < comb.size(); i++) {
      comb[i] = comb[i-1] + 1;
    }
    return celem;
  }

  

}