| 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 "CReuseCompletionGraphCacheHandler.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Algorithm { |
| 31 |
|
| 32 |
CReuseCompletionGraphCacheHandler::CReuseCompletionGraphCacheHandler(CReuseCompletionGraphCacheReader* reuseCompGraphCacheReader, CReuseCompletionGraphCacheWriter* reuseCompGraphCacheWriter) { |
| 33 |
mReuseCompGraphCacheReader = reuseCompGraphCacheReader; |
| 34 |
mReuseCompGraphCacheWriter = reuseCompGraphCacheWriter; |
| 35 |
|
| 36 |
mTmpContext = nullptr; |
| 37 |
mMemAllocMan = nullptr; |
| 38 |
mWriteData = nullptr; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
CReuseCompletionGraphCacheHandler::~CReuseCompletionGraphCacheHandler() { |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
CReuseCompletionGraphCacheEntry* CReuseCompletionGraphCacheHandler::getReuseCompletionGraphEntry(CIndividualProcessNode* indiProcNode, bool* minimalCompletionGraph, bool* deterministicConnection, CCalculationAlgorithmContext* calcAlgContext) { |
| 47 |
CReuseCompletionGraphCacheEntry* cacheEntry = nullptr; |
| 48 |
if (mReuseCompGraphCacheReader) { |
| 49 |
CProcessingDataBox* dataBox = calcAlgContext->getUsedProcessingDataBox(); |
| 50 |
if (indiProcNode) { |
| 51 |
CConcept* initConcept = nullptr; |
| 52 |
CXSortedNegLinker<CConcept*>* initConceptLinkerIt = indiProcNode->getProcessInitializingConceptLinker(); |
| 53 |
|
| 54 |
while (!initConcept && initConceptLinkerIt) { |
| 55 |
if (!initConceptLinkerIt->isNegated()) { |
| 56 |
CConcept* tmpConcept = initConceptLinkerIt->getData(); |
| 57 |
if (tmpConcept->hasClassName()) { |
| 58 |
initConcept = tmpConcept; |
| 59 |
} |
| 60 |
} |
| 61 |
initConceptLinkerIt = initConceptLinkerIt->getNext(); |
| 62 |
} |
| 63 |
if (initConcept) { |
| 64 |
cacheEntry = mReuseCompGraphCacheReader->getCacheEntry(initConcept,minimalCompletionGraph,deterministicConnection); |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
return cacheEntry; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
bool CReuseCompletionGraphCacheHandler::prepareCacheMessages(CCalculationAlgorithmContext* calcAlgContext) { |
| 74 |
if (!mMemAllocMan) { |
| 75 |
CTaskMemoryPoolAllocationManager reuseCacheMemManCreaterMemMan(&mMemPoolCon,calcAlgContext->getTemporaryMemoryAllocationManager()); |
| 76 |
mMemAllocMan = CObjectAllocator<CTaskMemoryPoolAllocationManager>::allocateAndConstruct(&reuseCacheMemManCreaterMemMan); |
| 77 |
mMemAllocMan->initTaskMemoryPoolAllocationManager(&mMemPoolCon,calcAlgContext->getTemporaryMemoryAllocationManager()); |
| 78 |
mTmpContext = CObjectParameterizingAllocator< CContextBase,CMemoryAllocationManager* >::allocateAndConstructAndParameterize(mMemAllocMan,mMemAllocMan); |
| 79 |
return true; |
| 80 |
} |
| 81 |
return false; |
| 82 |
} |
| 83 |
|
| 84 |
bool CReuseCompletionGraphCacheHandler::commitCacheMessages(CCalculationAlgorithmContext* calcAlgContext) { |
| 85 |
if (mWriteData) { |
| 86 |
CReuseCompletionGraphCacheEntryWriteData* commitWriteData = nullptr; |
| 87 |
CReuseCompletionGraphCacheEntryWriteData* writeDataIt = mWriteData; |
| 88 |
while (writeDataIt) { |
| 89 |
CReuseCompletionGraphCacheEntryWriteData* tmpWriteData = writeDataIt; |
| 90 |
writeDataIt = (CReuseCompletionGraphCacheEntryWriteData*)writeDataIt->getNext(); |
| 91 |
tmpWriteData->clearNext(); |
| 92 |
if (commitWriteData) { |
| 93 |
commitWriteData = (CReuseCompletionGraphCacheEntryWriteData*)tmpWriteData->append(commitWriteData); |
| 94 |
} else { |
| 95 |
commitWriteData = tmpWriteData; |
| 96 |
} |
| 97 |
} |
| 98 |
mReuseCompGraphCacheWriter->writeExpandCache(commitWriteData,mMemPoolCon.takeMemoryPools()); |
| 99 |
mWriteData = nullptr; |
| 100 |
mMemAllocMan = nullptr; |
| 101 |
mTmpContext = nullptr; |
| 102 |
return true; |
| 103 |
} |
| 104 |
return false; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
bool CReuseCompletionGraphCacheHandler::addCacheMessages(CReuseCompletionGraphCacheEntryWriteData* expandWriteData, CCalculationAlgorithmContext* calcAlgContext) { |
| 110 |
if (mWriteData) { |
| 111 |
mWriteData = (CReuseCompletionGraphCacheEntryWriteData*)expandWriteData->append(mWriteData); |
| 112 |
} else { |
| 113 |
mWriteData = expandWriteData; |
| 114 |
} |
| 115 |
return true; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
}; // end namespace Algorithm |
| 124 |
|
| 125 |
}; // end namespace Kernel |
| 126 |
|
| 127 |
}; // end namespace Reasoner |
| 128 |
|
| 129 |
}; // end namespace Konclude |