Debian Codegraph @

Source/Reasoner/Kernel/Process/CRepresentativeVariableBindingPathJoiningKeyHash.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 "CRepresentativeVariableBindingPathJoiningKeyHash.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32 CRepresentativeVariableBindingPathJoiningKeyHash::CRepresentativeVariableBindingPathJoiningKeyHash(CProcessContext* context) : CPROCESSHASH<CRepresentativeVariableBindingPathJoiningKeyHasher,CRepresentativeVariableBindingPathJoiningKeyHashData>(context) {
33 mContext = context;
34 }
35
36
37 CRepresentativeVariableBindingPathJoiningKeyHash* CRepresentativeVariableBindingPathJoiningKeyHash::initRepresentativeVariableBindingPathJoiningKeyHash(CRepresentativeVariableBindingPathJoiningKeyHash* prevHash) {
38 if (prevHash) {
39 CPROCESSHASH<CRepresentativeVariableBindingPathJoiningKeyHasher, CRepresentativeVariableBindingPathJoiningKeyHashData>::operator=(*prevHash);
40 mNextRepVarBindPathJoiningKeyTag = prevHash->mNextRepVarBindPathJoiningKeyTag;
41 } else {
42 CPROCESSHASH<CRepresentativeVariableBindingPathJoiningKeyHasher,CRepresentativeVariableBindingPathJoiningKeyHashData>::clear();
43 mNextRepVarBindPathJoiningKeyTag = 1;
44 }
45 return this;
46 }
47
48
49 CVariableBindingDescriptor* CRepresentativeVariableBindingPathJoiningKeyHash::createVariableBindingHashKeyDescriptor(CVariableBindingPath* varBindPath, CSortedLinker<CVariable*>* keyVars) {
50 CMemoryAllocationManager* taskMemMan = mContext->getUsedMemoryAllocationManager();
51
52 CVariableBindingDescriptor* keyVarBindDesLinker = nullptr;
53 CVariableBindingDescriptor* lastKeyVarBindDesLinker = nullptr;
54 CSortedLinker<CVariable*>* varLinkerIt = keyVars;
55 CVariableBindingDescriptor* varBindDesIt = varBindPath->getVariableBindingDescriptorLinker();
56 while (varLinkerIt) {
57 CVariableBinding* varBind = varBindDesIt->getVariableBinding();
58 if (varBind->getBindedVariable() == varLinkerIt->getData()) {
59 CVariableBindingDescriptor* nextKeyVarBindDesLinker = CObjectAllocator< CVariableBindingDescriptor >::allocateAndConstruct(taskMemMan);
60 nextKeyVarBindDesLinker->initVariableBindingDescriptor(varBind);
61
62 if (lastKeyVarBindDesLinker) {
63 lastKeyVarBindDesLinker->setNext(nextKeyVarBindDesLinker);
64 lastKeyVarBindDesLinker = nextKeyVarBindDesLinker;
65 } else {
66 keyVarBindDesLinker = lastKeyVarBindDesLinker = nextKeyVarBindDesLinker;
67 }
68 varLinkerIt = varLinkerIt->getNext();
69 varBindDesIt = varBindDesIt->getNext();
70 } else {
71 varBindDesIt = varBindDesIt->getNext();
72 }
73 }
74 return keyVarBindDesLinker;
75 }
76
77
78 CRepresentativeVariableBindingPathJoiningKeyData* CRepresentativeVariableBindingPathJoiningKeyHash::getRepresentativeVariableBindingPathJoiningKeyData(CVariableBindingPath* varBindPath, CSortedLinker<CVariable*>* keyVars, bool create) {
79 CRepresentativeVariableBindingPathJoiningKeyData* varBindPathJoiningData = nullptr;
80 CRepresentativeVariableBindingPathJoiningKeyHasher hasher(varBindPath,keyVars);
81 const CRepresentativeVariableBindingPathJoiningKeyHashData& data = CPROCESSHASH<CRepresentativeVariableBindingPathJoiningKeyHasher,CRepresentativeVariableBindingPathJoiningKeyHashData>::value(hasher);
82 varBindPathJoiningData = data.mVarBindPathJoiningData;
83 if (!varBindPathJoiningData && create) {
84 varBindPathJoiningData = CObjectAllocator< CRepresentativeVariableBindingPathJoiningKeyData >::allocateAndConstruct(mContext->getUsedMemoryAllocationManager());
85 CVariableBindingDescriptor* keyVarBindDesLinker = createVariableBindingHashKeyDescriptor(varBindPath,keyVars);
86 varBindPathJoiningData->initVariableBindingPathJoiningData(keyVarBindDesLinker,mNextRepVarBindPathJoiningKeyTag++);
87 CRepresentativeVariableBindingPathJoiningKeyHashData& data = CPROCESSHASH<CRepresentativeVariableBindingPathJoiningKeyHasher,CRepresentativeVariableBindingPathJoiningKeyHashData>::operator[](CRepresentativeVariableBindingPathJoiningKeyHasher(varBindPathJoiningData));
88 data.mVarBindPathJoiningData = varBindPathJoiningData;
89 }
90 return varBindPathJoiningData;
91 }
92
93
94 cint64 CRepresentativeVariableBindingPathJoiningKeyHash::getRepresentativeVariableBindingPathJoiningKey(CVariableBindingPath* varBindPath, CSortedLinker<CVariable*>* keyVars, bool create) {
95 CRepresentativeVariableBindingPathJoiningKeyData* varBindPathJoiningData = getRepresentativeVariableBindingPathJoiningKeyData(varBindPath,keyVars,create);
96 if (varBindPathJoiningData) {
97 return varBindPathJoiningData->getJoiningKey();
98 } else {
99 return 0;
100 }
101 }
102
103
104 }; // end namespace Process
105
106 }; // end namespace Kernel
107
108 }; // end namespace Reasoner
109
110 }; // end namespace Konclude