Debian Codegraph @

Source/Reasoner/Kernel/Process/CSuccessorIterator.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 "CSuccessorIterator.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32
33
34 CSuccessorIterator::CSuccessorIterator() {
35 mLastSucc = CINT64_MIN;
36 mIterator1 = false;
37 mIterator2 = false;
38 }
39
40
41 CSuccessorIterator::CSuccessorIterator(const CPROCESSHASH<cint64,CIndividualLinkEdge*>::iterator& beginIt, const CPROCESSHASH<cint64,CIndividualLinkEdge*>::iterator& endIt)
42 : mBeginIt1(beginIt),mEndIt1(endIt) {
43
44 mLastSucc = CINT64_MIN;
45 mIterator1 = true;
46 mIterator2 = false;
47 while (mBeginIt1 != mEndIt1 && mBeginIt1.value() == nullptr) {
48 ++mBeginIt1;
49 }
50 }
51
52
53 CSuccessorIterator::CSuccessorIterator(const CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& beginIt1, const CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& endIt1, const CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& beginIt2, const CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& endIt2, const CPROCESSHASH<cint64, CIndividualLinkEdge*>* it2ValHash)
54 : mBeginIt1(beginIt1), mEndIt1(endIt1), mBeginIt2(beginIt2), mEndIt2(endIt2) {
55
56 mLastSucc = CINT64_MIN;
57 mIterator1 = true;
58 mIterator2 = true;
59 while (mBeginIt1 != mEndIt1 && mBeginIt1.value() == nullptr) {
60 ++mBeginIt1;
61 }
62 mIt2ValHash = it2ValHash;
63 while (mBeginIt2 != mEndIt2 && mBeginIt2.value() == nullptr && (!mIt2ValHash || mIt2ValHash->contains(mBeginIt2.key()))) {
64 ++mBeginIt2;
65 }
66 }
67
68
69 bool CSuccessorIterator::hasNext() {
70 return mIterator1 && mBeginIt1 != mEndIt1 || mIterator2 && mBeginIt2 != mEndIt2;
71 }
72
73 CIndividualLinkEdge* CSuccessorIterator::nextLink(bool moveNext) {
74 CIndividualLinkEdge* link = nullptr;
75 cint64 indiID = 0;
76 if (mIterator1 && mBeginIt1 != mEndIt1) {
77 iterate(link, indiID, moveNext, mBeginIt1, mEndIt1, nullptr);
78 } else if (mIterator2 && mBeginIt2 != mEndIt2) {
79 iterate(link, indiID, moveNext, mBeginIt2, mEndIt2, mIt2ValHash);
80 }
81 return link;
82 }
83
84
85 cint64 CSuccessorIterator::nextIndividualID(bool moveNext) {
86 CIndividualLinkEdge* link = nullptr;
87 cint64 indiID = 0;
88 if (mIterator1 && mBeginIt1 != mEndIt1) {
89 iterate(link, indiID, moveNext, mBeginIt1, mEndIt1, nullptr);
90 } else if (mIterator2 && mBeginIt2 != mEndIt2) {
91 iterate(link, indiID, moveNext, mBeginIt2, mEndIt2, mIt2ValHash);
92 }
93 return indiID;
94 }
95
96 bool CSuccessorIterator::iterate(CIndividualLinkEdge*& link, cint64& indiId, bool moveNext, CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& beginIt, CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& endIt, const CPROCESSHASH<cint64, CIndividualLinkEdge*>* itValHash) {
97 link = beginIt.value();
98 indiId = beginIt.key();
99 mLastSucc = beginIt.key();
100 if (moveNext) {
101 ++beginIt;
102 while (beginIt != endIt && (beginIt.value() == nullptr || mLastSucc == beginIt.key()) && (!itValHash || itValHash->contains(beginIt.key()))) {
103 ++beginIt;
104 }
105 }
106 return true;
107 }
108
109 }; // end namespace Process
110
111 }; // end namespace Kernel
112
113 }; // end namespace Reasoner
114
115 }; // end namespace Konclude