| 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 "COptimizedComplexConceptInstanziatedIndividualItemHash.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Answerer { |
| 29 |
|
| 30 |
|
| 31 |
COptimizedComplexConceptInstanziatedIndividualItemHash::COptimizedComplexConceptInstanziatedIndividualItemHash() { |
| 32 |
mAddedLinker = nullptr; |
| 33 |
mTmpLinker = nullptr; |
| 34 |
mMemManContext = new CMemoryPoolNewAllocationIncreasingContext(500, 500000, 2); |
| 35 |
mIndiRefLinkerHash = CObjectParameterizingAllocator< CQtManagedRestrictedModificationHash<COptimizedComplexConceptInstanziatedIndividualItemHasher, COptimizedComplexConceptInstanziatedIndividualItemLinker*>, CContext* >::allocateAndConstructAndParameterize(getInstancesMemoryAllocationManager(), mMemManContext); |
| 36 |
} |
| 37 |
|
| 38 |
COptimizedComplexConceptInstanziatedIndividualItemHash::~COptimizedComplexConceptInstanziatedIndividualItemHash() { |
| 39 |
if (mMemManContext) { |
| 40 |
CMemoryPool* memPools = mMemManContext->getMemoryPools(); |
| 41 |
CMemoryPool* memPoolsIt = memPools; |
| 42 |
while (memPoolsIt) { |
| 43 |
CMemoryPool* tmpMemPool = memPoolsIt; |
| 44 |
memPoolsIt = memPoolsIt->getNext(); |
| 45 |
delete[] tmpMemPool->getMemoryBlockData(); |
| 46 |
delete tmpMemPool; |
| 47 |
} |
| 48 |
delete mMemManContext; |
| 49 |
mMemManContext = nullptr; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
CMemoryAllocationManager* COptimizedComplexConceptInstanziatedIndividualItemHash::getInstancesMemoryAllocationManager() { |
| 55 |
return mMemManContext->getMemoryAllocationManager(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
COptimizedComplexConceptInstanziatedIndividualItemHash* COptimizedComplexConceptInstanziatedIndividualItemHash::addRealizationIndividualInstanceItemReference(const CRealizationIndividualInstanceItemReference& itemRef) { |
| 60 |
if (!mTmpLinker) { |
| 61 |
mTmpLinker = CObjectAllocator<COptimizedComplexConceptInstanziatedIndividualItemLinker>::allocateAndConstruct(getInstancesMemoryAllocationManager()); |
| 62 |
mTmpLinker->initLinker(itemRef); |
| 63 |
} else { |
| 64 |
mTmpLinker->initLinker(itemRef); |
| 65 |
} |
| 66 |
COptimizedComplexConceptInstanziatedIndividualItemLinker*& insertedLinker = mIndiRefLinkerHash->operator[](mTmpLinker); |
| 67 |
if (!insertedLinker) { |
| 68 |
insertedLinker = mTmpLinker; |
| 69 |
mAddedLinker = mTmpLinker->append(mAddedLinker); |
| 70 |
mTmpLinker = nullptr; |
| 71 |
} |
| 72 |
return this; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
CQtManagedRestrictedModificationHash<COptimizedComplexConceptInstanziatedIndividualItemHasher, COptimizedComplexConceptInstanziatedIndividualItemLinker*>* COptimizedComplexConceptInstanziatedIndividualItemHash::getIndividualInstanceItemReferenceLinkerHash() { |
| 77 |
return mIndiRefLinkerHash; |
| 78 |
} |
| 79 |
|
| 80 |
COptimizedComplexConceptInstanziatedIndividualItemHash* COptimizedComplexConceptInstanziatedIndividualItemHash::remove(COptimizedComplexConceptInstanziatedIndividualItemLinker* linker) { |
| 81 |
mIndiRefLinkerHash->remove(linker); |
| 82 |
return this; |
| 83 |
} |
| 84 |
|
| 85 |
COptimizedComplexConceptInstanziatedIndividualItemLinker* COptimizedComplexConceptInstanziatedIndividualItemHash::getAddedRealizationIndividualInstanceItemReferenceLinker() { |
| 86 |
return mAddedLinker; |
| 87 |
} |
| 88 |
|
| 89 |
cint64 COptimizedComplexConceptInstanziatedIndividualItemHash::getMemoryConsumption() { |
| 90 |
return mMemManContext->getMemorySize(); |
| 91 |
} |
| 92 |
|
| 93 |
cint64 COptimizedComplexConceptInstanziatedIndividualItemHash::size() { |
| 94 |
return mIndiRefLinkerHash->size(); |
| 95 |
} |
| 96 |
|
| 97 |
bool COptimizedComplexConceptInstanziatedIndividualItemHash::isEmpty() { |
| 98 |
return mIndiRefLinkerHash->isEmpty(); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
}; // end namespace Answerer |
| 103 |
|
| 104 |
}; // end namespace Reasoner |
| 105 |
|
| 106 |
}; // end namespace Konclude |