Debian Codegraph @

Source/Reasoner/Kernel/Cache/COccurrenceStatisticsCacheOntologyData.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 "COccurrenceStatisticsCacheOntologyData.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Cache {
31
32
33 COccurrenceStatisticsCacheOntologyData::COccurrenceStatisticsCacheOntologyData() {
34 mUsageCounter.store(0);
35 mConceptDataVecLinker = nullptr;
36 mRoleDataVecLinker = nullptr;
37 }
38
39
40 COccurrenceStatisticsCacheOntologyData::~COccurrenceStatisticsCacheOntologyData() {
41 CXLinker < COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData>* >* conceptDataVecLinkerIt = mConceptDataVecLinker;
42 while (conceptDataVecLinkerIt) {
43 CXLinker < COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData>* >* tmpConceptDataVecLinkerIt = conceptDataVecLinkerIt;
44 conceptDataVecLinkerIt = conceptDataVecLinkerIt->getNext();
45 delete tmpConceptDataVecLinkerIt->getData();
46 delete tmpConceptDataVecLinkerIt;
47 }
48
49 CXLinker < COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData>* >* roleDataVecLinkerIt = mRoleDataVecLinker;
50 while (roleDataVecLinkerIt) {
51 CXLinker < COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData>* >* tmpRoleDataVecLinkerIt = roleDataVecLinkerIt;
52 roleDataVecLinkerIt = roleDataVecLinkerIt->getNext();
53 delete tmpRoleDataVecLinkerIt->getData();
54 delete tmpRoleDataVecLinkerIt;
55 }
56
57 }
58
59 cint64 COccurrenceStatisticsCacheOntologyData::getUsageCount() {
60 return mUsageCounter;
61 }
62
63 COccurrenceStatisticsCacheOntologyData* COccurrenceStatisticsCacheOntologyData::incUsageCount() {
64 mUsageCounter.ref();
65 return this;
66 }
67
68 COccurrenceStatisticsCacheOntologyData* COccurrenceStatisticsCacheOntologyData::decUsageCount() {
69 mUsageCounter.deref();
70 return this;
71 }
72
73 COccurrenceStatisticsRoleData COccurrenceStatisticsCacheOntologyData::getAccummulatedRoleDataOccurrenceStatistics(cint64 id) {
74 COccurrenceStatisticsRoleData accData;
75 for (CXLinker < COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData>* >* roleDataVecLinkerIt = mRoleDataVecLinker; roleDataVecLinkerIt; roleDataVecLinkerIt = roleDataVecLinkerIt->getNext()) {
76 COccurrenceStatisticsRoleData* data = roleDataVecLinkerIt->getData()->getOccurrenceStatisticsData(id);
77 if (data) {
78 accData.incDeterministicInstanceOccurrencesCount(data->getDeterministicInstanceOccurrencesCount());
79 accData.incNonDeterministicInstanceOccurrencesCount(data->getNonDeterministicInstanceOccurrencesCount());
80 accData.incExistentialInstanceOccurrencesCount(data->getExistentialInstanceOccurrencesCount());
81 accData.incIndividualInstanceOccurrencesCount(data->getIndividualInstanceOccurrencesCount());
82 accData.incIncomingNodeInstanceOccurrencesCount(data->getIncomingNodeInstanceOccurrencesCount());
83 accData.incOutgoingNodeInstanceOccurrencesCount(data->getOutgoingNodeInstanceOccurrencesCount());
84 }
85 }
86 return accData;
87 }
88
89 COccurrenceStatisticsConceptData COccurrenceStatisticsCacheOntologyData::getAccummulatedConceptDataOccurrenceStatistics(cint64 id) {
90 COccurrenceStatisticsConceptData accData;
91 for (CXLinker < COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData>* >* conceptDataVecLinkerIt = mConceptDataVecLinker; conceptDataVecLinkerIt; conceptDataVecLinkerIt = conceptDataVecLinkerIt->getNext()) {
92 COccurrenceStatisticsConceptData* data = conceptDataVecLinkerIt->getData()->getOccurrenceStatisticsData(id);
93 if (data) {
94 accData.incDeterministicInstanceOccurrencesCount(data->getDeterministicInstanceOccurrencesCount());
95 accData.incNonDeterministicInstanceOccurrencesCount(data->getNonDeterministicInstanceOccurrencesCount());
96 accData.incExistentialInstanceOccurrencesCount(data->getExistentialInstanceOccurrencesCount());
97 accData.incIndividualInstanceOccurrencesCount(data->getIndividualInstanceOccurrencesCount());
98 }
99 }
100 return accData;
101 }
102
103 COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData>* COccurrenceStatisticsCacheOntologyData::getWriteableConceptDataVector(cint64 conCount) {
104 COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData>* vec = nullptr;
105 if (!mFreeConceptDataVecList.isEmpty()) {
106 vec = mFreeConceptDataVecList.takeLast();
107 }
108 if (!vec) {
109 vec = new COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData>(conCount);
110 CXLinker<COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData>*>* linker = new CXLinker<COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData> *>(vec);
111 linker->initLinker(vec, nullptr);
112 mConceptDataVecLinker = linker->append(mConceptDataVecLinker);
113 }
114 return vec;
115 }
116
117
118 COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData>* COccurrenceStatisticsCacheOntologyData::getWriteableRoleDataVector(cint64 roleCount) {
119 COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData>* vec = nullptr;
120 if (!mFreeRoleDataVecList.isEmpty()) {
121 vec = mFreeRoleDataVecList.takeLast();
122 }
123 if (!vec) {
124 vec = new COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData>(roleCount);
125 CXLinker<COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData>*>* linker = new CXLinker<COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData> *>();
126 linker->initLinker(vec, nullptr);
127 mRoleDataVecLinker = linker->append(mRoleDataVecLinker);
128 }
129 return vec;
130 }
131
132 COccurrenceStatisticsCacheOntologyData* COccurrenceStatisticsCacheOntologyData::releaseWrittenConceptDataVector(COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsConceptData>* vec) {
133 mFreeConceptDataVecList.append(vec);
134 return this;
135 }
136
137 COccurrenceStatisticsCacheOntologyData* COccurrenceStatisticsCacheOntologyData::releaseWrittenRoleDataVector(COccurrenceStatisticsCacheOntologyDataVector<COccurrenceStatisticsRoleData>* vec) {
138 mFreeRoleDataVecList.append(vec);
139 return this;
140 }
141
142
143
144 }; // end namespace Cache
145
146 }; // end namespace Kernel
147
148 }; // end namespace Reasoner
149
150 }; // end namespace Konclude