Debian Codegraph @

Source/Reasoner/Kernel/Process/CRepresentativeVariableBindingPathSetHash.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 "CRepresentativeVariableBindingPathSetHash.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32
33 CRepresentativeVariableBindingPathSetHash::CRepresentativeVariableBindingPathSetHash(CProcessContext* processContext) : mProcessContext(processContext),CPROCESSHASH<cint64,CRepresentativeVariableBindingPathSetHashData>(processContext) {
34 }
35
36 CRepresentativeVariableBindingPathSetHash* CRepresentativeVariableBindingPathSetHash::initRepresentativeVariableBindingPathSetHash(CRepresentativeVariableBindingPathSetHash* prevMap) {
37 if (prevMap) {
38 CPROCESSHASH<cint64, CRepresentativeVariableBindingPathSetHashData>::operator =(*prevMap);
39 } else {
40 CPROCESSHASH<cint64,CRepresentativeVariableBindingPathSetHashData>::clear();
41 }
42 return this;
43 }
44
45
46 CRepresentativeVariableBindingPathSetHash* CRepresentativeVariableBindingPathSetHash::insertRepresentativeVariableBindingPathSetData(CRepresentativeVariableBindingPathSetData* repSetData) {
47 cint64 key = repSetData->getRepresentativeKey();
48 CRepresentativeVariableBindingPathSetHashData& data = CPROCESSHASH<cint64,CRepresentativeVariableBindingPathSetHashData>::operator[](key);
49 data.mLocDataLinker = repSetData->append(data.mUseDataLinker);
50 data.mUseDataLinker = data.mLocDataLinker;
51 return this;
52 }
53
54 CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetHash::getRepresentativeVariableBindingPathSetData(CRepresentativeVariableBindingPathSetData* repSetData, bool createOrLocalize) {
55 CRepresentativeVariableBindingPathSetData* repData = nullptr;
56 cint64 key = repSetData->getRepresentativeKey();
57 if (createOrLocalize) {
58 CRepresentativeVariableBindingPathSetHashData& data = CPROCESSHASH<cint64,CRepresentativeVariableBindingPathSetHashData>::operator[](key);
59
60 CRepresentativeVariableBindingPathSetData* foundDataLinker = nullptr;
61
62 for (CRepresentativeVariableBindingPathSetData* dataLinkerIt = data.mUseDataLinker; dataLinkerIt && !foundDataLinker; dataLinkerIt = dataLinkerIt->getNext()) {
63 if (dataLinkerIt->getRepresentativeID() == repSetData->getRepresentativeID()) {
64 foundDataLinker = dataLinkerIt;
65 }
66 }
67
68
69 CRepresentativeVariableBindingPathSetData* incLocDataLinker = nullptr;
70 if (foundDataLinker) {
71 incLocDataLinker = foundDataLinker;
72 }
73
74
75 if (incLocDataLinker) {
76 CRepresentativeVariableBindingPathSetData* returnDataLinker = nullptr;
77 CRepresentativeVariableBindingPathSetData* nextIncLocDataLinker = incLocDataLinker->getNext();
78 CRepresentativeVariableBindingPathSetData* newLocDataLinker = nullptr;
79 CRepresentativeVariableBindingPathSetData* lastNewLocDataLinker = nullptr;
80 for (CRepresentativeVariableBindingPathSetData* dataLinkerIt = data.mUseDataLinker; dataLinkerIt != nextIncLocDataLinker; dataLinkerIt = dataLinkerIt->getNext()) {
81 CRepresentativeVariableBindingPathSetData* locLinker = dataLinkerIt;
82 if (!dataLinkerIt->isLocalizationTagUpToDate(mProcessContext->getProcessTagger())) {
83 locLinker = CObjectParameterizingAllocator<CRepresentativeVariableBindingPathSetData,CProcessContext*>::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext);
84 locLinker->initRepresentativeVariableBindingPathData(dataLinkerIt);
85 }
86 if (dataLinkerIt == incLocDataLinker) {
87 returnDataLinker = locLinker;
88 }
89 if (lastNewLocDataLinker) {
90 lastNewLocDataLinker->setNext(locLinker);
91 lastNewLocDataLinker = locLinker;
92 } else {
93 lastNewLocDataLinker = locLinker;
94 newLocDataLinker = locLinker;
95 }
96 }
97
98 data.mLocDataLinker = newLocDataLinker;
99 data.mUseDataLinker = newLocDataLinker;
100 return returnDataLinker;
101 } else {
102 CRepresentativeVariableBindingPathSetData* locLinker = CObjectParameterizingAllocator<CRepresentativeVariableBindingPathSetData,CProcessContext*>::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext);
103 locLinker->initRepresentativeVariableBindingPathData(nullptr);
104 locLinker->setNext(data.mUseDataLinker);
105 data.mLocDataLinker = locLinker;
106 data.mUseDataLinker = locLinker;
107
108 return data.mLocDataLinker;
109 }
110
111 } else {
112 const CRepresentativeVariableBindingPathSetHashData& data = CPROCESSHASH<cint64,CRepresentativeVariableBindingPathSetHashData>::value(key);
113
114 for (CRepresentativeVariableBindingPathSetData* dataLinkerIt = data.mUseDataLinker; dataLinkerIt; dataLinkerIt = dataLinkerIt->getNext()) {
115 if (dataLinkerIt->getRepresentativeID() == repSetData->getRepresentativeID()) {
116 return dataLinkerIt;
117 }
118 }
119 }
120 return nullptr;
121 }
122
123
124
125 CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetHash::getRepresentativeVariableBindingPathSetData(CRepresentativePropagationSet* repPropSet, bool createOrLocalize) {
126 CRepresentativeVariableBindingPathSetData* repData = nullptr;
127 cint64 key = repPropSet->getIncomingRepresentativePropagationSignatureKey();
128 if (createOrLocalize) {
129 CRepresentativeVariableBindingPathSetHashData& data = CPROCESSHASH<cint64,CRepresentativeVariableBindingPathSetHashData>::operator[](key);
130
131 CRepresentativeVariableBindingPathSetData* selectedDataLinker = nullptr;
132 CRepresentativeVariableBindingPathSetData* foundDataLinker = nullptr;
133
134 for (CRepresentativeVariableBindingPathSetData* dataLinkerIt = data.mUseDataLinker; dataLinkerIt && !foundDataLinker; dataLinkerIt = dataLinkerIt->getNext()) {
135 if (!dataLinkerIt->hasMigrateData()) {
136 if (!selectedDataLinker) {
137 selectedDataLinker = dataLinkerIt;
138 }
139 } else {
140 // test identical
141 CRepresentativeVariableBindingPathSetMigrateData* migrateData = dataLinkerIt->getMigrateData(false);
142
143 CRepresentativeContainingMap* repContMap = migrateData->getRepresentativeContainingMap();
144 CRepresentativePropagationMap* repPropMap = repPropSet->getRepresentativePropagationMap();
145
146 if (isRepresentativePropagationMapIdenticalToRepresentativeContainingMap(repPropMap,repContMap)) {
147 foundDataLinker = dataLinkerIt;
148 }
149 }
150 }
151
152
153 CRepresentativeVariableBindingPathSetData* incLocDataLinker = nullptr;
154 if (foundDataLinker) {
155 incLocDataLinker = foundDataLinker;
156 } else if (selectedDataLinker) {
157 incLocDataLinker = selectedDataLinker;
158 }
159
160
161 if (incLocDataLinker) {
162 CRepresentativeVariableBindingPathSetData* returnDataLinker = nullptr;
163 CRepresentativeVariableBindingPathSetData* nextIncLocDataLinker = incLocDataLinker->getNext();
164 CRepresentativeVariableBindingPathSetData* newLocDataLinker = nullptr;
165 CRepresentativeVariableBindingPathSetData* lastNewLocDataLinker = nullptr;
166 for (CRepresentativeVariableBindingPathSetData* dataLinkerIt = data.mUseDataLinker; dataLinkerIt != nextIncLocDataLinker; dataLinkerIt = dataLinkerIt->getNext()) {
167 CRepresentativeVariableBindingPathSetData* locLinker = dataLinkerIt;
168 if (!dataLinkerIt->isLocalizationTagUpToDate(mProcessContext->getProcessTagger())) {
169 locLinker = CObjectParameterizingAllocator<CRepresentativeVariableBindingPathSetData,CProcessContext*>::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext);
170 locLinker->initRepresentativeVariableBindingPathData(dataLinkerIt);
171 }
172 if (dataLinkerIt == incLocDataLinker) {
173 returnDataLinker = locLinker;
174 }
175 if (lastNewLocDataLinker) {
176 lastNewLocDataLinker->setNext(locLinker);
177 lastNewLocDataLinker = locLinker;
178 } else {
179 lastNewLocDataLinker = locLinker;
180 newLocDataLinker = locLinker;
181 }
182 }
183
184 data.mLocDataLinker = newLocDataLinker;
185 data.mUseDataLinker = newLocDataLinker;
186 return returnDataLinker;
187 } else {
188 CRepresentativeVariableBindingPathSetData* locLinker = CObjectParameterizingAllocator<CRepresentativeVariableBindingPathSetData,CProcessContext*>::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext);
189 locLinker->initRepresentativeVariableBindingPathData(nullptr);
190 locLinker->setNext(data.mUseDataLinker);
191 data.mLocDataLinker = locLinker;
192 data.mUseDataLinker = locLinker;
193
194 return data.mLocDataLinker;
195 }
196
197 } else {
198 const CRepresentativeVariableBindingPathSetHashData& data = CPROCESSHASH<cint64,CRepresentativeVariableBindingPathSetHashData>::value(key);
199
200 for (CRepresentativeVariableBindingPathSetData* dataLinkerIt = data.mUseDataLinker; dataLinkerIt; dataLinkerIt = dataLinkerIt->getNext()) {
201 if (dataLinkerIt->hasMigrateData()) {
202
203 CRepresentativeVariableBindingPathSetMigrateData* migrateData = dataLinkerIt->getMigrateData(false);
204 CRepresentativeContainingMap* repContMap = migrateData->getRepresentativeContainingMap();
205 CRepresentativePropagationMap* repPropMap = repPropSet->getRepresentativePropagationMap();
206
207 if (isRepresentativePropagationMapIdenticalToRepresentativeContainingMap(repPropMap,repContMap)) {
208 return dataLinkerIt;
209 }
210 }
211 }
212 }
213 return nullptr;
214 }
215
216
217 bool CRepresentativeVariableBindingPathSetHash::isRepresentativePropagationMapIdenticalToRepresentativeContainingMap(CRepresentativePropagationMap* repPropMap, CRepresentativeContainingMap* repContMap) {
218 if (repPropMap->count() != repContMap->count()) {
219 return false;
220 }
221
222 CRepresentativePropagationMap::const_iterator repPropIt = repPropMap->constBegin(), repPropItEnd = repPropMap->constEnd();
223 CRepresentativeContainingMap::const_iterator repContIt = repContMap->constBegin(), repContItEnd = repContMap->constEnd();
224 while (repPropIt != repPropItEnd) {
225 if (repPropIt.key() != repContIt.key()) {
226 return false;
227 }
228 ++repPropIt;
229 ++repContIt;
230 }
231 return true;
232 }
233
234 }; // end namespace Process
235
236 }; // end namespace Kernel
237
238 }; // end namespace Reasoner
239
240 }; // end namespace Konclude