Debian Codegraph @

Source/Reasoner/Kernel/Cache/CSignatureSatisfiableExpanderCache.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 "CSignatureSatisfiableExpanderCache.h"
22 #include "CSignatureSatisfiableExpanderCacheWriter.h"
23
24
25 namespace Konclude {
26
27 namespace Reasoner {
28
29 namespace Kernel {
30
31 namespace Cache {
32
33
34 CSignatureSatisfiableExpanderCache::CSignatureSatisfiableExpanderCache(CConfiguration* config, QString threadIdentifierName, CWatchDog *watchDogThread) : CThread(threadIdentifierName,watchDogThread) {
35
36 mConfig = config;
37
38 mWriteDataCount = 0;
39 mNextWriteCollectCount = 0;
40 mCollectCount = 0;
41 mStartWriteCollectCount = 1000;
42
43
44 mSlotLinker = nullptr;
45 mReaderLinker = nullptr;
46 mCollectMemoryPools = nullptr;
47 mCollectWriteData = nullptr;
48
49 CMemoryAllocationManager* memMan = mContext.getMemoryAllocationManager();
50 mSigItemHash = CObjectParameterizingAllocator< CCACHINGHASH<cint64,CSignatureSatisfiableExpanderCacheRedirectionItem*>,CContext* >::allocateAndConstructAndParameterize(memMan,&mContext);
51 mIncompatibleSigSet = CObjectParameterizingAllocator< CCACHINGSET<cint64>,CContext* >::allocateAndConstructAndParameterize(memMan,&mContext);
52 mAlreadyExpSigSet = CObjectParameterizingAllocator< CCACHINGSET<cint64>,CContext* >::allocateAndConstructAndParameterize(memMan,&mContext);
53 mSignatureReferCountSet = CObjectParameterizingAllocator< CCACHINGHASH<cint64,cint64>,CContext* >::allocateAndConstructAndParameterize(memMan,&mContext);
54
55
56 mNextMemoryLevelRequiredSignatureRefCount = CConfigDataReader::readConfigInteger(config,"Konclude.Cache.SatisfiableExpander.InitialMemoryLevelForIncreaseRequiredSignatureReferenceCount",200*1024*1024);
57 mNextMemoryLevelIncreaseForRequiredSignatureReferenceCount = CConfigDataReader::readConfigInteger(config,"Konclude.Cache.SatisfiableExpander.NextMemoryLevelIncreaseForIncreaseRequiredSignatureReferenceCount",100*1024*1024);
58 mNextCacheEntryRequiredSignatureRefCount = CConfigDataReader::readConfigInteger(config,"Konclude.Cache.SatisfiableExpander.RequiredSignatureReferenceCountIncrease",1);
59 mNextCacheEntryRequiredSignatureReferenceCountIncrease = CConfigDataReader::readConfigInteger(config,"Konclude.Cache.SatisfiableExpander.RequiredSignatureReferenceCountIncrease",1);
60
61 startThread(QThread::HighestPriority);
62 }
63
64
65 CSignatureSatisfiableExpanderCache::~CSignatureSatisfiableExpanderCache() {
66 }
67
68
69
70 CCacheStatistics* CSignatureSatisfiableExpanderCache::getCacheStatistics() {
71 return &mCacheStat;
72 }
73
74 bool CSignatureSatisfiableExpanderCache::writeExpanderCachingData(CSignatureSatisfiableExpanderCacheContext* context, cint64 prevSignature, cint64 newSignature, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGHASH<cint64,cint64>* depHash) {
75 if (canCreateCacheEntryForSignature(newSignature,context)) {
76 if (!mSigItemHash->contains(newSignature)) {
77 CMemoryAllocationManager* memMan = context->getMemoryAllocationManager();
78 CSignatureSatisfiableExpanderCacheEntry* entry = nullptr;
79 if (prevSignature != 0) {
80 CSignatureSatisfiableExpanderCacheRedirectionItem* prevSigItem = mSigItemHash->value(prevSignature);
81 if (prevSigItem) {
82 entry = prevSigItem->getCacheEntry();
83 if (!isCachingDataExpandable(context,entry,prevSignature,cacheValueList)) {
84 // not compatible, only identical signatures
85 mIncompatibleSigSet->insert(prevSignature);
86 return false;
87 }
88 if (mAlreadyExpSigSet->contains(prevSignature)) {
89 entry->setMultipleExpanded(true);
90 }
91 }
92 }
93
94 if (!entry) {
95 entry = CObjectParameterizingAllocator< CSignatureSatisfiableExpanderCacheEntry,CSignatureSatisfiableExpanderCacheContext* >::allocateAndConstructAndParameterize(memMan,context);
96 }
97
98 writeExpanderCachingData(context,entry,prevSignature != 0,cacheValueList,depHash);
99 CSignatureSatisfiableExpanderCacheRedirectionItem* sigItem = CObjectAllocator< CSignatureSatisfiableExpanderCacheRedirectionItem >::allocateAndConstruct(memMan);
100 sigItem->initRedirectionItem(entry,newSignature,entry->getExpanderCacheValueCount());
101 mSigItemHash->insert(newSignature,sigItem);
102 mAlreadyExpSigSet->insert(prevSignature);
103 //mHasherItemHash.insert(CSignatureSatisfiableExpanderCacheHasher(entry->getExpanderCacheValueLinker(),entry->getExpanderCacheValueCount()),sigItem);
104 return true;
105 } else {
106 mIncompatibleSigSet->insert(newSignature);
107 }
108 }
109 return false;
110 }
111
112
113
114 bool CSignatureSatisfiableExpanderCache::isCachingDataExpandable(CSignatureSatisfiableExpanderCacheContext* context, CSignatureSatisfiableExpanderCacheEntry* entry, cint64 signature, CCACHINGLIST<CCacheValue>* cacheValueList) {
115 if (mIncompatibleSigSet->contains(signature) || entry->hasMultipleExpanded()) {
116 CCACHINGHASH<cint64,CExpanderCacheValueLinker*>* tagHash = entry->getTagExpanderCacheValueHash();
117 cint64 prevCount = entry->getExpanderCacheValueCount();
118 while (prevCount-- > 0 && !cacheValueList->isEmpty()) {
119 const CCacheValue& cacheValue = cacheValueList->takeFirst();
120 cint64 tag = cacheValue.getTag();
121 CExpanderCacheValueLinker* contCacheValue = tagHash->value(tag);
122 if (!contCacheValue || *contCacheValue->getCacheValue() != cacheValue) {
123 return false;
124 }
125 }
126 } else {
127 cint64 prevCount = entry->getExpanderCacheValueCount();
128 while (prevCount-- > 0 && !cacheValueList->isEmpty()) {
129 const CCacheValue& cacheValue = cacheValueList->takeFirst();
130 }
131 }
132 return true;
133 }
134
135
136 void CSignatureSatisfiableExpanderCache::writeExpanderCachingData(CSignatureSatisfiableExpanderCacheContext* context, CSignatureSatisfiableExpanderCacheEntry* entry, bool extending, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGHASH<cint64,cint64>* depHash) {
137 CMemoryAllocationManager* memMan = context->getMemoryAllocationManager();
138 CCACHINGHASH<cint64,CExpanderCacheValueLinker*>* tagHash = entry->getTagExpanderCacheValueHash();
139 CCACHINGHASH<cint64,cint64>::const_iterator itDepEnd = depHash->constEnd();
140
141 CExpanderCacheValueLinker* lastExpCacheValueLinker = nullptr;
142 CExpanderCacheValueLinker* firstExpCacheValueLinker = nullptr;
143
144
145 CCACHINGHASH<cint64,CExpanderCacheValueLinker*>* newTagHash = CObjectParameterizingAllocator< CCACHINGHASH<cint64,CExpanderCacheValueLinker*>,CContext* >::allocateAndConstructAndParameterize(memMan,context);
146 if (tagHash) {
147 *newTagHash = *tagHash;
148 }
149
150 mCacheStat.incCacheEntriesCount();
151
152
153 CCACHINGHASH<cint64,CCacheValue>* tagCacheValueHash = nullptr;
154
155
156 for (CCACHINGLIST<CCacheValue>::const_iterator it = cacheValueList->constBegin(), itEnd = cacheValueList->constEnd(); it != itEnd; ++it) {
157 const CCacheValue& cacheValue = *it;
158 cint64 tag = cacheValue.getTag();
159
160 if (!newTagHash->contains(tag)) {
161 CExpanderCacheValueLinker* expCacheValue = CObjectParameterizingAllocator< CExpanderCacheValueLinker,CSignatureSatisfiableExpanderCacheContext* >::allocateAndConstructAndParameterize(memMan,context);
162 expCacheValue->setCacheValue(cacheValue);
163
164 //if (cacheValue.getIdentification() == 0 || tag == 0) {
165 // bool bug = true;
166 //}
167
168
169 CCACHINGHASH<cint64,cint64>::const_iterator itDep = depHash->constFind(tag);
170 while (itDep != itDepEnd && itDep.key() == tag) {
171
172 cint64 depTag = itDep.value();
173 CExpanderCacheValueLinker* depExpCacheValueLinker = newTagHash->value(depTag);
174 if (!depExpCacheValueLinker) {
175 if (!tagCacheValueHash) {
176 tagCacheValueHash = CObjectParameterizingAllocator< CCACHINGHASH<cint64,CCacheValue>,CContext* >::allocateAndConstructAndParameterize(memMan,context);
177 CCACHINGLIST<CCacheValue>::const_iterator it2 = it;
178 for (++it2; it2 != itEnd; ++it2) {
179 const CCacheValue& cv = *it2;
180 cint64 cvTag = cv.getTag();
181 tagCacheValueHash->insert(cvTag,cv);
182 }
183 }
184 const CCacheValue& depCacheValue = tagCacheValueHash->value(depTag);
185 addExpanderCachingData(context,depCacheValue,newTagHash,depHash,tagCacheValueHash,lastExpCacheValueLinker,firstExpCacheValueLinker);
186 depExpCacheValueLinker = newTagHash->value(depTag);
187 }
188 expCacheValue->addExpanderDependency(depExpCacheValueLinker);
189 ++itDep;
190 }
191
192 newTagHash->insert(tag,expCacheValue);
193
194 if (firstExpCacheValueLinker) {
195 lastExpCacheValueLinker->append(expCacheValue);
196 lastExpCacheValueLinker = expCacheValue;
197 } else {
198 firstExpCacheValueLinker = expCacheValue;
199 lastExpCacheValueLinker = firstExpCacheValueLinker;
200 }
201 }
202 }
203
204 entry->setTagExpanderCacheValueHash(newTagHash);
205 entry->appendExpanderCacheValueLinker(firstExpCacheValueLinker);
206
207 }
208
209
210
211
212 void CSignatureSatisfiableExpanderCache::addExpanderCachingData(CSignatureSatisfiableExpanderCacheContext* context, const CCacheValue& cacheValue, CCACHINGHASH<cint64,CExpanderCacheValueLinker*>* newTagHash, CCACHINGHASH<cint64,cint64>* depHash, CCACHINGHASH<cint64,CCacheValue>* tagCacheValueHash, CExpanderCacheValueLinker*& lastExpCacheValueLinker, CExpanderCacheValueLinker*& firstExpCacheValueLinker) {
213 CMemoryAllocationManager* memMan = context->getMemoryAllocationManager();
214 CCACHINGHASH<cint64,cint64>::const_iterator itDepEnd = depHash->constEnd();
215 cint64 tag = cacheValue.getTag();
216
217 if (!newTagHash->contains(tag)) {
218 CExpanderCacheValueLinker* expCacheValue = CObjectParameterizingAllocator< CExpanderCacheValueLinker,CSignatureSatisfiableExpanderCacheContext* >::allocateAndConstructAndParameterize(memMan,context);
219 expCacheValue->setCacheValue(cacheValue);
220
221 //if (cacheValue.getIdentification() == 0 || tag == 0) {
222 // bool bug = true;
223 //}
224
225 CCACHINGHASH<cint64,cint64>::const_iterator itDep = depHash->constFind(tag);
226 while (itDep != itDepEnd && itDep.key() == tag) {
227 cint64 depTag = itDep.value();
228 CExpanderCacheValueLinker* depExpCacheValueLinker = newTagHash->value(depTag);
229 if (!depExpCacheValueLinker) {
230 const CCacheValue& depCacheValue = tagCacheValueHash->value(depTag);
231 addExpanderCachingData(context,depCacheValue,newTagHash,depHash,tagCacheValueHash,lastExpCacheValueLinker,firstExpCacheValueLinker);
232 depExpCacheValueLinker = newTagHash->value(depTag);
233 }
234 expCacheValue->addExpanderDependency(depExpCacheValueLinker);
235 ++itDep;
236 }
237
238 newTagHash->insert(tag,expCacheValue);
239
240 if (firstExpCacheValueLinker) {
241 lastExpCacheValueLinker->append(expCacheValue);
242 lastExpCacheValueLinker = expCacheValue;
243 } else {
244 firstExpCacheValueLinker = expCacheValue;
245 lastExpCacheValueLinker = firstExpCacheValueLinker;
246 }
247 }
248 }
249
250
251
252
253 bool CSignatureSatisfiableExpanderCache::writeSatisfiableBranchedCachingData(CSignatureSatisfiableExpanderCacheContext* context, cint64 signature, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGLIST<CCacheValue>* branchedValueList) {
254 CMemoryAllocationManager* memMan = context->getMemoryAllocationManager();
255 CSignatureSatisfiableExpanderCacheRedirectionItem* sSigItem = mSigItemHash->value(signature);
256 if (sSigItem) {
257 CSignatureSatisfiableExpanderCacheEntry* entry = sSigItem->getCacheEntry();
258
259 if (isCachingDataExpandable(context,entry,signature,cacheValueList)) {
260
261 if (!branchedValueList || branchedValueList->isEmpty()) {
262 entry->setSatisfiableWithoutBranchedConcepts(true);
263 } else {
264 CExpanderBranchedLinker* expBranch = CObjectParameterizingAllocator< CExpanderBranchedLinker,CSignatureSatisfiableExpanderCacheContext* >::allocateAndConstructAndParameterize(memMan,context);
265 for (CCACHINGLIST<CCacheValue>::const_iterator it = branchedValueList->constBegin(), itEnd = branchedValueList->constEnd(); it != itEnd; ++it) {
266 const CCacheValue& cacheValue = *it;
267 expBranch->appendCacheValue(cacheValue);
268 }
269 entry->appendExpanderBranchedLinker(expBranch);
270 }
271
272 entry->setSatisfiable(true);
273 return true;
274 }
275 }
276 return false;
277 }
278
279
280
281
282 void CSignatureSatisfiableExpanderCache::createReaderSlotUpdate(CSignatureSatisfiableExpanderCacheContext* context) {
283 CMemoryPoolProvider* memProv = context->getMemoryPoolAllocationManager();
284 CSignatureSatisfiableExpanderCacheSlotItem* slot = CObjectMemoryPoolAllocator<CSignatureSatisfiableExpanderCacheSlotItem>::allocateAndConstructWithMemroyPool(memProv);
285 CMemoryPoolContainerAllocationManager slotMemMan(slot,memProv);
286 CMemoryAllocationManager* memMan = &slotMemMan;
287 CContextBase tmpContext(memMan);
288 CCACHINGHASH<cint64,CSignatureSatisfiableExpanderCacheRedirectionItem*>* slotSigItemHash = CObjectParameterizingAllocator< CCACHINGHASH<cint64,CSignatureSatisfiableExpanderCacheRedirectionItem*>,CContext* >::allocateAndConstructAndParameterize(memMan,&tmpContext);
289 *slotSigItemHash = *mSigItemHash;
290 slotSigItemHash->detach();
291 slot->setSignatureItemHash(slotSigItemHash);
292 // currently not used
293 //CCACHINGHASH<CSignatureSatisfiableExpanderCacheHasher,CSignatureSatisfiableExpanderCacheRedirectionItem*>* slotHasherItemHash = CObjectParameterizingAllocator< CCACHINGHASH<CSignatureSatisfiableExpanderCacheHasher,CSignatureSatisfiableExpanderCacheRedirectionItem*>,CContext* >::allocateAndConstructAndParameterize(memMan,&tmpContext);
294 //*slotHasherItemHash = *mHasherItemHash;
295 //slotHasherItemHash->detach();
296 //slot->setHasherItemHash(slotHasherItemHash);
297 if (mSlotLinker) {
298 mSlotLinker->append(slot);
299 } else {
300 mSlotLinker = slot;
301 }
302 CSignatureSatisfiableExpanderCacheReader* readerLinkerIt = mReaderLinker;
303 while (readerLinkerIt) {
304 slot->incReader();
305 readerLinkerIt->updateSlot(slot);
306 readerLinkerIt = readerLinkerIt->getNext();
307 }
308 }
309
310
311 void CSignatureSatisfiableExpanderCache::cleanUnusedSlots(CSignatureSatisfiableExpanderCacheContext* context) {
312 CMemoryPoolAllocationManager* memMan = context->getMemoryPoolAllocationManager();
313 CSignatureSatisfiableExpanderCacheSlotItem* slotLinkerIt = mSlotLinker;
314 CSignatureSatisfiableExpanderCacheSlotItem* lastSlotLinker = nullptr;
315 while (slotLinkerIt) {
316 CSignatureSatisfiableExpanderCacheSlotItem* tmpSlotLinker = nullptr;
317 if (!slotLinkerIt->hasCacheReaders()) {
318 tmpSlotLinker = slotLinkerIt;
319 }
320 CSignatureSatisfiableExpanderCacheSlotItem* nextSlotLinker = slotLinkerIt->getNext();
321 if (tmpSlotLinker) {
322 if (!lastSlotLinker) {
323 mSlotLinker = nextSlotLinker;
324 } else {
325 lastSlotLinker->setNext(nextSlotLinker);
326 }
327 CMemoryPool* memoryPools = tmpSlotLinker->getMemoryPools();
328 memMan->releaseTemporaryMemoryPools(memoryPools);
329 } else {
330 lastSlotLinker = slotLinkerIt;
331 }
332 slotLinkerIt = nextSlotLinker;
333 }
334 }
335
336
337
338 CSignatureSatisfiableExpanderCacheReader* CSignatureSatisfiableExpanderCache::createCacheReader() {
339 CSignatureSatisfiableExpanderCacheReader* reader = new CSignatureSatisfiableExpanderCacheReader();
340 mReaderSyncMutex.lock();
341 mReaderLinker = reader->append(mReaderLinker);
342 mReaderSyncMutex.unlock();
343 return reader;
344 }
345
346
347 CSignatureSatisfiableExpanderCacheWriter* CSignatureSatisfiableExpanderCache::createCacheWriter() {
348 CSignatureSatisfiableExpanderCacheWriter* writer = new CSignatureSatisfiableExpanderCacheWriter(this);
349 return writer;
350 }
351
352
353
354 CSignatureSatisfiableExpanderCache* CSignatureSatisfiableExpanderCache::writeCachedData(CSignatureSatisfiableExpanderCacheEntryWriteData* writeData, CMemoryPool* memoryPools) {
355 #ifdef KONCLUCE_SATISFIBALE_EXPANDER_CACHE_DIRECT_WRITING
356 CSignatureSatisfiableExpanderCacheEntryWriteData* dataLinkerIt = writeData;
357 bool allCachingSuccess = true;
358 bool oneCachingSuccess = false;
359 bool oneCachingExpSuccess = false;
360 while (dataLinkerIt) {
361 if (dataLinkerIt->getCacheWriteDataType() == CSignatureSatisfiableExpanderCacheEntryWriteData::SATEXPANDCACHEWRITEDATATYPE) {
362 CSignatureSatisfiableExpanderCacheEntryExpandWriteData* exWrDa = (CSignatureSatisfiableExpanderCacheEntryExpandWriteData*)dataLinkerIt;
363 cint64 prevSignature = exWrDa->getPrevSignature();
364 cint64 newSignature = exWrDa->getNewSignature();
365 CCACHINGLIST<CCacheValue>* cacheValueList = exWrDa->getCacheValueList();
366 CCACHINGHASH<cint64,cint64>* depHash = exWrDa->getDepHash();
367
368 bool cached = writeExpanderCachingData(&mContext,prevSignature,newSignature,cacheValueList,depHash);
369 allCachingSuccess &= cached;
370 oneCachingSuccess |= cached;
371 oneCachingExpSuccess |= cached;
372 } else {
373 CSignatureSatisfiableExpanderCacheEntrySatisfiableBranchWriteData* saBrWrDa = (CSignatureSatisfiableExpanderCacheEntrySatisfiableBranchWriteData*)dataLinkerIt;
374 cint64 signature = saBrWrDa->getSignature();
375 CCACHINGLIST<CCacheValue>* cacheValueList = saBrWrDa->getCacheValueList();
376 CCACHINGLIST<CCacheValue>* branchedValueList = saBrWrDa->getBranchedValueList();
377
378 bool cached = writeSatisfiableBranchedCachingData(&mContext,signature,cacheValueList,branchedValueList);
379 allCachingSuccess &= cached;
380 oneCachingSuccess |= cached;
381 }
382 dataLinkerIt = (CSignatureSatisfiableExpanderCacheEntryWriteData*)dataLinkerIt->getNext();
383 }
384
385 if (oneCachingExpSuccess) {
386 createReaderSlotUpdate(&mContext);
387 cleanUnusedSlots(&mContext);
388 }
389 #else
390 postEvent(new CWriteCachedDataEvent(writeData,memoryPools));
391 #endif
392 return this;
393 }
394
395
396
397 CSignatureSatisfiableExpanderCache* CSignatureSatisfiableExpanderCache::writeExpandCached(cint64 prevSignature, cint64 newSignature, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGHASH<cint64,cint64>* depHash, CMemoryPool* memoryPools) {
398 #ifdef KONCLUCE_SATISFIBALE_EXPANDER_CACHE_DIRECT_WRITING
399 if (writeExpanderCachingData(&mContext,prevSignature,newSignature,cacheValueList,depHash)) {
400 createReaderSlotUpdate(&mContext);
401 cleanUnusedSlots(&mContext);
402 }
403 #else
404 postEvent(new CWriteExpandCachedEvent(prevSignature,newSignature,cacheValueList,depHash,memoryPools));
405 #endif
406 return this;
407 }
408
409 CSignatureSatisfiableExpanderCache* CSignatureSatisfiableExpanderCache::writeSatisfiableBranchCached(cint64 signature, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGLIST<CCacheValue>* branchedList, CMemoryPool* memoryPools) {
410 #ifdef KONCLUCE_SATISFIBALE_EXPANDER_CACHE_DIRECT_WRITING
411 writeSatisfiableBranchedCachingData(&mContext,signature,cacheValueList,branchedList);
412 #else
413 postEvent(new CWriteSatisfiableBranchCachedEvent(signature,cacheValueList,branchedList,memoryPools));
414 #endif
415 return this;
416 }
417
418
419 bool CSignatureSatisfiableExpanderCache::processCustomsEvents(QEvent::Type type, CCustomEvent *event) {
420 if (CThread::processCustomsEvents(type,event)) {
421 return true;
422 } if (type == EVENTWRITEEXPANDCACHEDENTRY) {
423 CWriteExpandCachedEvent* wece = (CWriteExpandCachedEvent*)event;
424 cint64 prevSignature = wece->getPrevSignature();
425 cint64 newSignature = wece->getNewSignature();
426 CCACHINGLIST<CCacheValue>* cacheValueList = wece->getCacheValueList();
427 CCACHINGHASH<cint64,cint64>* depHash = wece->getDepHash();
428 CMemoryPool* memoryPools = wece->getMemoryPools();
429
430 if (writeExpanderCachingData(&mContext,prevSignature,newSignature,cacheValueList,depHash)) {
431 createReaderSlotUpdate(&mContext);
432 cleanUnusedSlots(&mContext);
433 }
434
435 mContext.getMemoryPoolAllocationManager()->releaseTemporaryMemoryPools(memoryPools);
436 return true;
437
438 } else if (type == EVENTWRITESATISFIABLEBRANCHCACHEDENTRY) {
439 CWriteSatisfiableBranchCachedEvent* wsbce = (CWriteSatisfiableBranchCachedEvent*)event;
440 cint64 signature = wsbce->getSignature();
441 CCACHINGLIST<CCacheValue>* cacheValueList = wsbce->getCacheValueList();
442 CCACHINGLIST<CCacheValue>* branchedValueList = wsbce->getBranchedValueList();
443 CMemoryPool* memoryPools = wsbce->getMemoryPools();
444
445 writeSatisfiableBranchedCachingData(&mContext,signature,cacheValueList,branchedValueList);
446
447 mContext.getMemoryPoolAllocationManager()->releaseTemporaryMemoryPools(memoryPools);
448 return true;
449 } else if (type == EVENTWRITECACHEDDATAENTRY) {
450 CWriteCachedDataEvent* wcde = (CWriteCachedDataEvent*)event;
451 CMemoryPool* memoryPools = wcde->getMemoryPools();
452 CSignatureSatisfiableExpanderCacheEntryWriteData* newWriteData = (CSignatureSatisfiableExpanderCacheEntryWriteData*)wcde->getWriteData();
453 cint64 dataWriteCount = newWriteData->getCount();
454
455 mCollectCount += dataWriteCount;
456 mCollectMemoryPools = memoryPools->append(mCollectMemoryPools);
457 mCollectWriteData = (CSignatureSatisfiableExpanderCacheEntryWriteData*)newWriteData->append(mCollectWriteData);
458
459 if (mCollectCount >= mNextWriteCollectCount) {
460 if (mWriteDataCount > mStartWriteCollectCount) {
461 ++mNextWriteCollectCount;
462 }
463
464 CSignatureSatisfiableExpanderCacheEntryWriteData* dataLinkerIt = mCollectWriteData;
465
466 bool allCachingSuccess = true;
467 bool oneCachingSuccess = false;
468 bool oneCachingExpSuccess = false;
469 while (dataLinkerIt) {
470 if (dataLinkerIt->getCacheWriteDataType() == CSignatureSatisfiableExpanderCacheEntryWriteData::SATEXPANDCACHEWRITEDATATYPE) {
471 CSignatureSatisfiableExpanderCacheEntryExpandWriteData* exWrDa = (CSignatureSatisfiableExpanderCacheEntryExpandWriteData*)dataLinkerIt;
472 cint64 prevSignature = exWrDa->getPrevSignature();
473 cint64 newSignature = exWrDa->getNewSignature();
474 CCACHINGLIST<CCacheValue>* cacheValueList = exWrDa->getCacheValueList();
475 CCACHINGHASH<cint64,cint64>* depHash = exWrDa->getDepHash();
476
477 bool cached = writeExpanderCachingData(&mContext,prevSignature,newSignature,cacheValueList,depHash);
478 allCachingSuccess &= cached;
479 oneCachingSuccess |= cached;
480 oneCachingExpSuccess |= cached;
481 } else {
482 CSignatureSatisfiableExpanderCacheEntrySatisfiableBranchWriteData* saBrWrDa = (CSignatureSatisfiableExpanderCacheEntrySatisfiableBranchWriteData*)dataLinkerIt;
483 cint64 signature = saBrWrDa->getSignature();
484 CCACHINGLIST<CCacheValue>* cacheValueList = saBrWrDa->getCacheValueList();
485 CCACHINGLIST<CCacheValue>* branchedValueList = saBrWrDa->getBranchedValueList();
486
487 bool cached = writeSatisfiableBranchedCachingData(&mContext,signature,cacheValueList,branchedValueList);
488 allCachingSuccess &= cached;
489 oneCachingSuccess |= cached;
490 }
491 dataLinkerIt = (CSignatureSatisfiableExpanderCacheEntryWriteData*)dataLinkerIt->getNext();
492 }
493
494 if (oneCachingExpSuccess) {
495 createReaderSlotUpdate(&mContext);
496 cleanUnusedSlots(&mContext);
497 }
498
499 mContext.releaseTemporaryMemoryPools(mCollectMemoryPools);
500 mCacheStat.setMemoryConsumption(mContext.getMemoryConsumption());
501
502 mCollectWriteData = nullptr;
503 mCollectMemoryPools = nullptr;
504 mCollectCount = 0;
505 }
506
507 ++mWriteDataCount;
508 return true;
509 }
510 return false;
511 }
512
513
514
515
516 cint64 CSignatureSatisfiableExpanderCache::getRequiredSignatureReferCountForNextCacheEntryCreation(CSignatureSatisfiableExpanderCacheContext* context) {
517 if (context->getMemoryConsumption() >= mNextMemoryLevelRequiredSignatureRefCount) {
518 mNextCacheEntryRequiredSignatureRefCount += mNextCacheEntryRequiredSignatureReferenceCountIncrease;
519 mNextMemoryLevelRequiredSignatureRefCount += mNextMemoryLevelIncreaseForRequiredSignatureReferenceCount;
520 }
521 return mNextCacheEntryRequiredSignatureRefCount;
522 }
523
524 cint64 CSignatureSatisfiableExpanderCache::canCreateCacheEntryForSignature(cint64 singature, CSignatureSatisfiableExpanderCacheContext* context) {
525 cint64& refCount = (*mSignatureReferCountSet)[singature];
526 ++refCount;
527 if (refCount >= getRequiredSignatureReferCountForNextCacheEntryCreation(context)) {
528 return true;
529 }
530 return false;
531 }
532
533 }; // end namespace Cache
534
535 }; // end namespace Kernel
536
537 }; // end namespace Reasoner
538
539 }; // end namespace Konclude