| 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 "CBlockingIndividualNodeCandidateIterator.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Process { |
| 31 |
|
| 32 |
|
| 33 |
CBlockingIndividualNodeCandidateIterator::CBlockingIndividualNodeCandidateIterator(CPROCESSMAP<cint64,CIndividualProcessNode*>* candidateMap, cint64 candidateIndividualID) |
| 34 |
: mCandidateMap(candidateMap) { |
| 35 |
|
| 36 |
if (mCandidateMap) { |
| 37 |
mItBegin = mCandidateMap->upperBound(-candidateIndividualID); |
| 38 |
mItEnd = mCandidateMap->end(); |
| 39 |
mItLast = mItBegin; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
bool CBlockingIndividualNodeCandidateIterator::hasNext() { |
| 46 |
return mCandidateMap && mItBegin != mItEnd; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
bool CBlockingIndividualNodeCandidateIterator::hasIndividualCandidates() { |
| 51 |
return mCandidateMap && !mCandidateMap->isEmpty(); |
| 52 |
} |
| 53 |
|
| 54 |
cint64 CBlockingIndividualNodeCandidateIterator::next(bool moveNext) { |
| 55 |
CIndividualProcessNode* indi = nextIndividualCandidate(moveNext); |
| 56 |
if (indi) { |
| 57 |
return indi->getIndividualNodeID(); |
| 58 |
} |
| 59 |
return 0; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
CIndividualProcessNode* CBlockingIndividualNodeCandidateIterator::nextIndividualCandidate(bool moveNext) { |
| 64 |
CIndividualProcessNode* indi = nullptr; |
| 65 |
if (mCandidateMap && mItBegin != mItEnd) { |
| 66 |
indi = mItBegin.value(); |
| 67 |
mItLast = mItBegin; |
| 68 |
if (moveNext) { |
| 69 |
++mItBegin; |
| 70 |
} |
| 71 |
} |
| 72 |
return indi; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
bool CBlockingIndividualNodeCandidateIterator::removeLastIndividualCandidate() { |
| 77 |
if (mItLast != mItEnd) { |
| 78 |
mItBegin = mCandidateMap->erase(mItLast); |
| 79 |
mItLast = mItBegin; |
| 80 |
return true; |
| 81 |
} |
| 82 |
return false; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
bool CBlockingIndividualNodeCandidateIterator::hasIndividualCandidate(cint64 indiID) { |
| 87 |
return mCandidateMap && mCandidateMap->contains(-indiID); |
| 88 |
} |
| 89 |
|
| 90 |
bool CBlockingIndividualNodeCandidateIterator::hasIndividualCandidate(CIndividualProcessNode* indi) { |
| 91 |
return hasIndividualCandidate(indi->getIndividualNodeID()); |
| 92 |
} |
| 93 |
|
| 94 |
}; // end namespace Process |
| 95 |
|
| 96 |
}; // end namespace Kernel |
| 97 |
|
| 98 |
}; // end namespace Reasoner |
| 99 |
|
| 100 |
}; // end namespace Konclude |