Debian Codegraph @

Source/Reasoner/Kernel/Process/CConnectionSuccessorSet.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 "CConnectionSuccessorSet.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32
33 CConnectionSuccessorSet::CConnectionSuccessorSet(CProcessContext* context) : mContext(context) {
34 mAncConnID = CINT64_MIN;
35 mConnSet = nullptr;
36 mPrevConnSet = nullptr;
37 }
38
39 CConnectionSuccessorSet* CConnectionSuccessorSet::initConnectionSuccessorSet(CConnectionSuccessorSet* connSuccSet) {
40 if (connSuccSet) {
41 mAncConnID = connSuccSet->mAncConnID;
42 if (connSuccSet->mConnSet) {
43
44 if (!mConnSet) {
45 mConnSet = CObjectParameterizingAllocator< CPROCESSSET<cint64>, CContext* >::allocateAndConstructAndParameterize(mContext->getUsedMemoryAllocationManager(), mContext);
46 } else {
47 mConnSet->clear();
48 }
49
50
51 if (!connSuccSet->mPrevConnSet && connSuccSet->mConnSet->size() <= 100) {
52 *mConnSet = *connSuccSet->mConnSet;
53 mPrevConnSet = nullptr;
54 } else if (!connSuccSet->mPrevConnSet && connSuccSet->mConnSet->size() > 100) {
55 mPrevConnSet = connSuccSet->mConnSet;
56 } else {
57 if (connSuccSet->mConnSet->size() * 10 > connSuccSet->mPrevConnSet->size()) {
58 *mConnSet = *connSuccSet->mPrevConnSet;
59 for (CPROCESSSET<cint64>::const_iterator it = connSuccSet->mConnSet->constBegin(), itEnd = connSuccSet->mConnSet->constEnd(); it != itEnd; ++it) {
60 cint64 indiId = *it;
61 mConnSet->insert(indiId);
62 }
63 mPrevConnSet = nullptr;
64 } else {
65 *mConnSet = *connSuccSet->mConnSet;
66 mPrevConnSet = connSuccSet->mPrevConnSet;
67 }
68
69 }
70
71 }
72 } else {
73 mAncConnID = CINT64_MIN;
74 if (mConnSet) {
75 mConnSet->clear();
76 }
77 mPrevConnSet = nullptr;
78 }
79 return this;
80 }
81
82
83
84 bool CConnectionSuccessorSet::hasConnectionSuccessor(cint64 indiID) {
85 if (mPrevConnSet && mPrevConnSet->contains(indiID)) {
86 return true;
87 }
88 if (mConnSet) {
89 return mConnSet->contains(indiID);
90 }
91 return mAncConnID == indiID;
92 }
93
94
95 CConnectionSuccessorSet* CConnectionSuccessorSet::insertConnectionSuccessor(cint64 indiID) {
96 if (mAncConnID != indiID) {
97 if (mAncConnID != CINT64_MIN) {
98 if (!mConnSet) {
99 mConnSet = CObjectParameterizingAllocator< CPROCESSSET<cint64>,CContext* >::allocateAndConstructAndParameterize(mContext->getUsedMemoryAllocationManager(),mContext);
100 mConnSet->insert(mAncConnID);
101 }
102 if (!mPrevConnSet || !mPrevConnSet->contains(indiID)) {
103 mConnSet->insert(indiID);
104 }
105 } else {
106 mAncConnID = indiID;
107 }
108 }
109 return this;
110 }
111
112
113 CConnectionSuccessorSet* CConnectionSuccessorSet::removeConnection(cint64 indiID) {
114 if (mPrevConnSet) {
115 if (mPrevConnSet->contains(indiID)) {
116 for (CPROCESSSET<cint64>::const_iterator it = mPrevConnSet->constBegin(), itEnd = mPrevConnSet->constEnd(); it != itEnd; ++it) {
117 cint64 indiId = *it;
118 mConnSet->insert(indiId);
119 }
120 mPrevConnSet = nullptr;
121 }
122 }
123 if (mConnSet) {
124 mConnSet->remove(indiID);
125 } else if (mAncConnID == indiID) {
126 mAncConnID = CINT64_MIN;
127 }
128 return this;
129 }
130
131
132 CConnectionSuccessorSetIterator CConnectionSuccessorSet::getConnectionSuccessorIterator() {
133 if (mPrevConnSet) {
134 return CConnectionSuccessorSetIterator(mConnSet->begin(), mConnSet->end(), mPrevConnSet->begin(), mPrevConnSet->end());
135 } else if (mConnSet) {
136 return CConnectionSuccessorSetIterator(mConnSet->begin(), mConnSet->end());
137 } else {
138 return CConnectionSuccessorSetIterator(mAncConnID);
139 }
140 }
141
142
143 cint64 CConnectionSuccessorSet::getConnectionSuccessorCount() {
144 if (!mConnSet) {
145 if(mAncConnID != CINT64_MIN) {
146 return 1;
147 } else {
148 return 0;
149 }
150 } else if (mPrevConnSet) {
151 return mConnSet->count() + mPrevConnSet->count();
152 } else {
153 return mConnSet->count();
154 }
155 }
156
157
158
159 }; // end namespace Process
160
161 }; // end namespace Kernel
162
163 }; // end namespace Reasoner
164
165 }; // end namespace Konclude