Debian Codegraph @

Source/Reasoner/Kernel/Process/CRepresentativeVariableBindingPathJoiningKeyHasher.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 "CRepresentativeVariableBindingPathJoiningKeyHasher.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32 CRepresentativeVariableBindingPathJoiningKeyHasher::CRepresentativeVariableBindingPathJoiningKeyHasher(CRepresentativeVariableBindingPathJoiningKeyData* data) {
33 mVarBindPath = nullptr;
34 mKeyVars = nullptr;
35 mJoiningData = data;
36 mHashValue = mJoiningData->getCalculatedHashValue();
37 }
38
39
40 CRepresentativeVariableBindingPathJoiningKeyHasher::CRepresentativeVariableBindingPathJoiningKeyHasher(CVariableBindingPath* varBindPath, CSortedLinker<CVariable*>* keyVars) {
41 mJoiningData = nullptr;
42 mVarBindPath = varBindPath;
43 mKeyVars = keyVars;
44 mHashValue = calculateHashValue(mVarBindPath,mKeyVars);
45 }
46
47
48 cint64 CRepresentativeVariableBindingPathJoiningKeyHasher::calculateHashValue(CVariableBindingPath* varBindPath, CSortedLinker<CVariable*>* keyVars) {
49 cint64 hashValue = 0;
50 CSortedLinker<CVariable*>* keyVarsIt = keyVars;
51 cint64 multiplier = 13;
52 for (CVariableBindingDescriptor* linkerIt = varBindPath->getVariableBindingDescriptorLinker(); keyVarsIt && linkerIt; linkerIt = linkerIt->getNext()) {
53 CVariableBinding* variableBinding = linkerIt->getVariableBinding();
54 CVariable* variable = variableBinding->getBindedVariable();
55 CVariable* keyVariable = keyVarsIt->getData();
56 if (variable == keyVariable) {
57 hashValue += multiplier*(cint64)variableBinding;
58 multiplier = multiplier*2+1;
59 keyVarsIt = keyVarsIt->getNext();
60 }
61 }
62 return hashValue;
63 }
64
65
66 cint64 CRepresentativeVariableBindingPathJoiningKeyHasher::getHashValue() const {
67 return mHashValue;
68 }
69
70 bool CRepresentativeVariableBindingPathJoiningKeyHasher::operator==(const CRepresentativeVariableBindingPathJoiningKeyHasher& hasher) const {
71 if (mJoiningData && hasher.mJoiningData) {
72 return mJoiningData->isKeyEquivalentTo(*hasher.mJoiningData);
73 } else if (mJoiningData && hasher.mVarBindPath) {
74 return mJoiningData->isKeyEquivalentTo(hasher.mVarBindPath);
75 } else if (mVarBindPath && hasher.mJoiningData) {
76 return hasher.mJoiningData->isKeyEquivalentTo(mVarBindPath);
77 }
78 return false;
79 }
80
81 }; // end namespace Process
82
83 }; // end namespace Kernel
84
85 }; // end namespace Reasoner
86
87 }; // end namespace Konclude