| 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 "CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Cache { |
| 31 |
|
| 32 |
|
| 33 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData() { |
| 34 |
mIndiIdLinker = nullptr; |
| 35 |
mCount = 0; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
bool CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::visitNeighbourIndividualIds(function<bool(cint64 id)> visitFunc) { |
| 40 |
bool continueVisiting = true; |
| 41 |
bool visited = false; |
| 42 |
for (CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourIndividualIdLinker* indiIdLinkerIt = mIndiIdLinker; continueVisiting && indiIdLinkerIt; indiIdLinkerIt = indiIdLinkerIt->getNext()) { |
| 43 |
cint64 indiId = indiIdLinkerIt->getIndividualId(); |
| 44 |
continueVisiting &= visitFunc(indiId); |
| 45 |
visited = true; |
| 46 |
} |
| 47 |
return visited; |
| 48 |
} |
| 49 |
|
| 50 |
bool CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::visitNeighbourIndividualIdsFromCursor(function<bool(cint64 id, cint64 cursor)> visitFunc, cint64 cursor) { |
| 51 |
bool continueVisiting = true; |
| 52 |
bool visited = false; |
| 53 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourIndividualIdLinker* indiIdLinkerIt = (CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourIndividualIdLinker*)cursor; |
| 54 |
if (!indiIdLinkerIt) { |
| 55 |
indiIdLinkerIt = mIndiIdLinker; |
| 56 |
} else { |
| 57 |
indiIdLinkerIt = indiIdLinkerIt->getNext(); |
| 58 |
} |
| 59 |
while (continueVisiting && indiIdLinkerIt) { |
| 60 |
cint64 indiId = indiIdLinkerIt->getIndividualId(); |
| 61 |
continueVisiting &= visitFunc(indiId, (cint64)indiIdLinkerIt); |
| 62 |
indiIdLinkerIt = indiIdLinkerIt->getNext(); |
| 63 |
visited = true; |
| 64 |
} |
| 65 |
return visited; |
| 66 |
} |
| 67 |
|
| 68 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourIndividualIdLinker* CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::getIndividualIdLinker() { |
| 69 |
return mIndiIdLinker; |
| 70 |
} |
| 71 |
|
| 72 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData* CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::incIndividualCount(cint64 count) { |
| 73 |
mCount += count; |
| 74 |
return this; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData* CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::decIndividualCount(cint64 count) { |
| 79 |
mCount -= count; |
| 80 |
return this; |
| 81 |
} |
| 82 |
|
| 83 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData* CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::setIndividualIdLinker(CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourIndividualIdLinker* indiIdLinker, bool updateCounter) { |
| 84 |
mIndiIdLinker = indiIdLinker; |
| 85 |
if (updateCounter) { |
| 86 |
mCount = mIndiIdLinker->getCount(); |
| 87 |
} |
| 88 |
return this; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData* CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::addIndividualIdLinker(CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourIndividualIdLinker* indiIdLinker, bool incCounter) { |
| 93 |
if (incCounter) { |
| 94 |
mCount += indiIdLinker->getCount(); |
| 95 |
} |
| 96 |
mIndiIdLinker = indiIdLinker->append(mIndiIdLinker); |
| 97 |
return this; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
cint64 CBackendRepresentativeMemoryCacheIndividualRoleSetNeighbourData::getIndividualCount() { |
| 102 |
return mCount; |
| 103 |
} |
| 104 |
|
| 105 |
}; // end namespace Cache |
| 106 |
|
| 107 |
}; // end namespace Kernel |
| 108 |
|
| 109 |
}; // end namespace Reasoner |
| 110 |
|
| 111 |
}; // end namespace Konclude |