/src/rdkit/Code/Query/NullQueryAlgebra.h
Line | Count | Source |
1 | | // |
2 | | // |
3 | | // Copyright (C) 2019 Greg Landrum and T5 Informatics GmbH |
4 | | // |
5 | | // @@ All Rights Reserved @@ |
6 | | // This file is part of the RDKit. |
7 | | // The contents are covered by the terms of the BSD license |
8 | | // which is included in the file license.txt, found at the root |
9 | | // of the RDKit source tree. |
10 | | // |
11 | | #ifndef RD_NULLQUERYALGEBRA_H |
12 | | #define RD_NULLQUERYALGEBRA_H |
13 | | |
14 | | #include <GraphMol/QueryOps.h> |
15 | | |
16 | | namespace RDKit { |
17 | | namespace { |
18 | | template <class T> |
19 | | void mergeBothNullQ(T *&returnQuery, T *&otherNullQ, |
20 | 37.8k | Queries::CompositeQueryType how) { |
21 | 37.8k | bool negatedQ = returnQuery->getNegation(); |
22 | 37.8k | bool negatedOtherQ = otherNullQ->getNegation(); |
23 | | |
24 | 37.8k | if (how == Queries::COMPOSITE_AND) { |
25 | | // This is the only case in which we need to do anything |
26 | 30.5k | if (!negatedQ && negatedOtherQ) { |
27 | 4.99k | returnQuery->setNegation(true); |
28 | 4.99k | } |
29 | 30.5k | } else if (how == Queries::COMPOSITE_OR) { |
30 | | // This is the only case in which we need to do anything |
31 | 7.31k | if (negatedQ && !negatedOtherQ) { |
32 | 1.88k | returnQuery->setNegation(false); |
33 | 1.88k | } |
34 | 7.31k | } else if (how == Queries::COMPOSITE_XOR) { |
35 | 0 | if (!negatedQ && !negatedOtherQ) { |
36 | 0 | returnQuery->setNegation(true); |
37 | 0 | } else if (negatedQ + negatedOtherQ == 1) { |
38 | 0 | returnQuery->setNegation(false); |
39 | 0 | } |
40 | 0 | } |
41 | 37.8k | } QueryAtom.cpp:void RDKit::(anonymous namespace)::mergeBothNullQ<Queries::Query<int, RDKit::Atom const*, true> >(Queries::Query<int, RDKit::Atom const*, true>*&, Queries::Query<int, RDKit::Atom const*, true>*&, Queries::CompositeQueryType) Line | Count | Source | 20 | 22.9k | Queries::CompositeQueryType how) { | 21 | 22.9k | bool negatedQ = returnQuery->getNegation(); | 22 | 22.9k | bool negatedOtherQ = otherNullQ->getNegation(); | 23 | | | 24 | 22.9k | if (how == Queries::COMPOSITE_AND) { | 25 | | // This is the only case in which we need to do anything | 26 | 16.6k | if (!negatedQ && negatedOtherQ) { | 27 | 3.97k | returnQuery->setNegation(true); | 28 | 3.97k | } | 29 | 16.6k | } else if (how == Queries::COMPOSITE_OR) { | 30 | | // This is the only case in which we need to do anything | 31 | 6.32k | if (negatedQ && !negatedOtherQ) { | 32 | 1.73k | returnQuery->setNegation(false); | 33 | 1.73k | } | 34 | 6.32k | } else if (how == Queries::COMPOSITE_XOR) { | 35 | 0 | if (!negatedQ && !negatedOtherQ) { | 36 | 0 | returnQuery->setNegation(true); | 37 | 0 | } else if (negatedQ + negatedOtherQ == 1) { | 38 | 0 | returnQuery->setNegation(false); | 39 | 0 | } | 40 | 0 | } | 41 | 22.9k | } |
QueryBond.cpp:void RDKit::(anonymous namespace)::mergeBothNullQ<Queries::Query<int, RDKit::Bond const*, true> >(Queries::Query<int, RDKit::Bond const*, true>*&, Queries::Query<int, RDKit::Bond const*, true>*&, Queries::CompositeQueryType) Line | Count | Source | 20 | 14.9k | Queries::CompositeQueryType how) { | 21 | 14.9k | bool negatedQ = returnQuery->getNegation(); | 22 | 14.9k | bool negatedOtherQ = otherNullQ->getNegation(); | 23 | | | 24 | 14.9k | if (how == Queries::COMPOSITE_AND) { | 25 | | // This is the only case in which we need to do anything | 26 | 13.9k | if (!negatedQ && negatedOtherQ) { | 27 | 1.02k | returnQuery->setNegation(true); | 28 | 1.02k | } | 29 | 13.9k | } else if (how == Queries::COMPOSITE_OR) { | 30 | | // This is the only case in which we need to do anything | 31 | 987 | if (negatedQ && !negatedOtherQ) { | 32 | 150 | returnQuery->setNegation(false); | 33 | 150 | } | 34 | 987 | } else if (how == Queries::COMPOSITE_XOR) { | 35 | 0 | if (!negatedQ && !negatedOtherQ) { | 36 | 0 | returnQuery->setNegation(true); | 37 | 0 | } else if (negatedQ + negatedOtherQ == 1) { | 38 | 0 | returnQuery->setNegation(false); | 39 | 0 | } | 40 | 0 | } | 41 | 14.9k | } |
|
42 | | |
43 | | template <class T> |
44 | | void mergeNullQFirst(T *&returnQuery, T *&otherQ, |
45 | 54.4k | Queries::CompositeQueryType how) { |
46 | 54.4k | bool negatedQ = returnQuery->getNegation(); |
47 | | |
48 | 54.4k | if (how == Queries::COMPOSITE_AND) { |
49 | 44.1k | if (!negatedQ) { |
50 | 30.8k | std::swap(returnQuery, otherQ); |
51 | 30.8k | } |
52 | 44.1k | } else if (how == Queries::COMPOSITE_OR) { |
53 | 10.3k | if (negatedQ) { |
54 | 4.42k | std::swap(returnQuery, otherQ); |
55 | 4.42k | } |
56 | 10.3k | } else if (how == Queries::COMPOSITE_XOR) { |
57 | 0 | std::swap(returnQuery, otherQ); |
58 | 0 | if (!negatedQ) { |
59 | 0 | returnQuery->setNegation(!returnQuery->getNegation()); |
60 | 0 | } |
61 | 0 | } |
62 | 54.4k | } QueryAtom.cpp:void RDKit::(anonymous namespace)::mergeNullQFirst<Queries::Query<int, RDKit::Atom const*, true> >(Queries::Query<int, RDKit::Atom const*, true>*&, Queries::Query<int, RDKit::Atom const*, true>*&, Queries::CompositeQueryType) Line | Count | Source | 45 | 39.7k | Queries::CompositeQueryType how) { | 46 | 39.7k | bool negatedQ = returnQuery->getNegation(); | 47 | | | 48 | 39.7k | if (how == Queries::COMPOSITE_AND) { | 49 | 32.0k | if (!negatedQ) { | 50 | 21.1k | std::swap(returnQuery, otherQ); | 51 | 21.1k | } | 52 | 32.0k | } else if (how == Queries::COMPOSITE_OR) { | 53 | 7.69k | if (negatedQ) { | 54 | 4.05k | std::swap(returnQuery, otherQ); | 55 | 4.05k | } | 56 | 7.69k | } else if (how == Queries::COMPOSITE_XOR) { | 57 | 0 | std::swap(returnQuery, otherQ); | 58 | 0 | if (!negatedQ) { | 59 | 0 | returnQuery->setNegation(!returnQuery->getNegation()); | 60 | 0 | } | 61 | 0 | } | 62 | 39.7k | } |
QueryBond.cpp:void RDKit::(anonymous namespace)::mergeNullQFirst<Queries::Query<int, RDKit::Bond const*, true> >(Queries::Query<int, RDKit::Bond const*, true>*&, Queries::Query<int, RDKit::Bond const*, true>*&, Queries::CompositeQueryType) Line | Count | Source | 45 | 14.6k | Queries::CompositeQueryType how) { | 46 | 14.6k | bool negatedQ = returnQuery->getNegation(); | 47 | | | 48 | 14.6k | if (how == Queries::COMPOSITE_AND) { | 49 | 12.0k | if (!negatedQ) { | 50 | 9.71k | std::swap(returnQuery, otherQ); | 51 | 9.71k | } | 52 | 12.0k | } else if (how == Queries::COMPOSITE_OR) { | 53 | 2.62k | if (negatedQ) { | 54 | 367 | std::swap(returnQuery, otherQ); | 55 | 367 | } | 56 | 2.62k | } else if (how == Queries::COMPOSITE_XOR) { | 57 | 0 | std::swap(returnQuery, otherQ); | 58 | 0 | if (!negatedQ) { | 59 | 0 | returnQuery->setNegation(!returnQuery->getNegation()); | 60 | 0 | } | 61 | 0 | } | 62 | 14.6k | } |
|
63 | | |
64 | | } // namespace |
65 | | |
66 | | template <class T> |
67 | | void mergeNullQueries(T *&returnQuery, bool isQueryNull, T *&otherQuery, |
68 | 92.3k | bool isOtherQNull, Queries::CompositeQueryType how) { |
69 | 92.3k | PRECONDITION(returnQuery, "bad query"); |
70 | 92.3k | PRECONDITION(otherQuery, "bad query"); |
71 | 92.3k | PRECONDITION(how == Queries::COMPOSITE_AND || how == Queries::COMPOSITE_OR || |
72 | 92.3k | how == Queries::COMPOSITE_XOR, |
73 | 92.3k | "bad combination op"); |
74 | | |
75 | 92.3k | if (isQueryNull && isOtherQNull) { |
76 | 37.8k | mergeBothNullQ(returnQuery, otherQuery, how); |
77 | 54.4k | } else if (isQueryNull) { |
78 | 31.0k | mergeNullQFirst(returnQuery, otherQuery, how); |
79 | 31.0k | } else if (isOtherQNull) { |
80 | 23.3k | std::swap(returnQuery, otherQuery); |
81 | 23.3k | mergeNullQFirst(returnQuery, otherQuery, how); |
82 | 23.3k | } |
83 | 92.3k | } void RDKit::mergeNullQueries<Queries::Query<int, RDKit::Atom const*, true> >(Queries::Query<int, RDKit::Atom const*, true>*&, bool, Queries::Query<int, RDKit::Atom const*, true>*&, bool, Queries::CompositeQueryType) Line | Count | Source | 68 | 62.7k | bool isOtherQNull, Queries::CompositeQueryType how) { | 69 | 62.7k | PRECONDITION(returnQuery, "bad query"); | 70 | 62.7k | PRECONDITION(otherQuery, "bad query"); | 71 | 62.7k | PRECONDITION(how == Queries::COMPOSITE_AND || how == Queries::COMPOSITE_OR || | 72 | 62.7k | how == Queries::COMPOSITE_XOR, | 73 | 62.7k | "bad combination op"); | 74 | | | 75 | 62.7k | if (isQueryNull && isOtherQNull) { | 76 | 22.9k | mergeBothNullQ(returnQuery, otherQuery, how); | 77 | 39.7k | } else if (isQueryNull) { | 78 | 24.1k | mergeNullQFirst(returnQuery, otherQuery, how); | 79 | 24.1k | } else if (isOtherQNull) { | 80 | 15.6k | std::swap(returnQuery, otherQuery); | 81 | 15.6k | mergeNullQFirst(returnQuery, otherQuery, how); | 82 | 15.6k | } | 83 | 62.7k | } |
void RDKit::mergeNullQueries<Queries::Query<int, RDKit::Bond const*, true> >(Queries::Query<int, RDKit::Bond const*, true>*&, bool, Queries::Query<int, RDKit::Bond const*, true>*&, bool, Queries::CompositeQueryType) Line | Count | Source | 68 | 29.5k | bool isOtherQNull, Queries::CompositeQueryType how) { | 69 | 29.5k | PRECONDITION(returnQuery, "bad query"); | 70 | 29.5k | PRECONDITION(otherQuery, "bad query"); | 71 | 29.5k | PRECONDITION(how == Queries::COMPOSITE_AND || how == Queries::COMPOSITE_OR || | 72 | 29.5k | how == Queries::COMPOSITE_XOR, | 73 | 29.5k | "bad combination op"); | 74 | | | 75 | 29.5k | if (isQueryNull && isOtherQNull) { | 76 | 14.9k | mergeBothNullQ(returnQuery, otherQuery, how); | 77 | 14.9k | } else if (isQueryNull) { | 78 | 6.92k | mergeNullQFirst(returnQuery, otherQuery, how); | 79 | 7.74k | } else if (isOtherQNull) { | 80 | 7.74k | std::swap(returnQuery, otherQuery); | 81 | 7.74k | mergeNullQFirst(returnQuery, otherQuery, how); | 82 | 7.74k | } | 83 | 29.5k | } |
|
84 | | } // namespace RDKit |
85 | | |
86 | | #endif |