Debian Codegraph @

Source/Reasoner/Kernel/Process/CRepresentativeVariableBindingPathJoiningKeyData.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CRepresentativeVariableBindingPathJoiningKeyData.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32 CRepresentativeVariableBindingPathJoiningKeyData::CRepresentativeVariableBindingPathJoiningKeyData() {
33 }
34
35
36
37 CRepresentativeVariableBindingPathJoiningKeyData* CRepresentativeVariableBindingPathJoiningKeyData::initVariableBindingPathJoiningData(CRepresentativeVariableBindingPathJoiningKeyData* prevJoinData) {
38 if (prevJoinData) {
39 mKeyVarBindDesLinker = prevJoinData->mKeyVarBindDesLinker;
40 mHashValueCalculated = prevJoinData->mHashValueCalculated;
41 mCalculatedHashValue = prevJoinData->mCalculatedHashValue;
42 mJoiningKey = prevJoinData->mJoiningKey;
43 } else {
44 mKeyVarBindDesLinker = nullptr;
45 mHashValueCalculated = false;
46 mCalculatedHashValue = 0;
47 mJoiningKey = 0;
48 }
49 return this;
50 }
51
52
53 CRepresentativeVariableBindingPathJoiningKeyData* CRepresentativeVariableBindingPathJoiningKeyData::initVariableBindingPathJoiningData(CVariableBindingDescriptor* keyVarBindDesLinker, cint64 joiningKey) {
54 mJoiningKey = joiningKey;
55 mKeyVarBindDesLinker = keyVarBindDesLinker;
56 mHashValueCalculated = false;
57 mCalculatedHashValue = getCalculatedHashValue();
58 return this;
59 }
60
61 CVariableBindingDescriptor* CRepresentativeVariableBindingPathJoiningKeyData::getKeyVariableBindingDescriptorLinker() const {
62 return mKeyVarBindDesLinker;
63 }
64
65
66 cint64 CRepresentativeVariableBindingPathJoiningKeyData::getJoiningKey() const {
67 return mJoiningKey;
68 }
69
70
71 cint64 CRepresentativeVariableBindingPathJoiningKeyData::getCalculatedHashValue() const {
72 if (!mHashValueCalculated) {
73 mHashValueCalculated = true;
74 mCalculatedHashValue = 0;
75 cint64 multiplier = 13;
76 for (CVariableBindingDescriptor* linkerIt = mKeyVarBindDesLinker; linkerIt; linkerIt = linkerIt->getNext()) {
77 CVariableBinding* variableBinding = linkerIt->getVariableBinding();
78 mCalculatedHashValue += multiplier*(cint64)variableBinding;
79 multiplier = multiplier*2+1;
80 }
81 }
82 return mCalculatedHashValue;
83 }
84
85 bool CRepresentativeVariableBindingPathJoiningKeyData::isKeyEquivalentTo(const CRepresentativeVariableBindingPathJoiningKeyData& data) const {
86 if (mJoiningKey != data.mJoiningKey) {
87 return false;
88 }
89 return true;
90 }
91
92 bool CRepresentativeVariableBindingPathJoiningKeyData::isKeyEquivalentTo(CVariableBindingPath* varBindPath) const {
93 CVariableBindingDescriptor* linkerIt1 = mKeyVarBindDesLinker;
94 CVariableBindingDescriptor* linkerIt2 = varBindPath->getVariableBindingDescriptorLinker();
95 while (linkerIt2 && linkerIt1) {
96 if (linkerIt2->getVariableBinding()->getBindedVariable() < linkerIt1->getVariableBinding()->getBindedVariable()) {
97 linkerIt2 = linkerIt2->getNext();
98 } else {
99 if (linkerIt1->getVariableBinding() != linkerIt2->getVariableBinding()) {
100 return false;
101 }
102 linkerIt1 = linkerIt1->getNext();
103 linkerIt2 = linkerIt2->getNext();
104 }
105 }
106 if (linkerIt1) {
107 return false;
108 }
109 return true;
110 }
111
112
113
114 }; // end namespace Process
115
116 }; // end namespace Kernel
117
118 }; // end namespace Reasoner
119
120 }; // end namespace Konclude