Debian Codegraph @

Source/Reasoner/Kernel/Cache/CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash.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 "CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Cache {
31
32
33 CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash::CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash(CBackendRepresentativeMemoryCacheContext* context) {
34 mContext = context;
35 mNeighbourRoleSetLabelHash = CObjectParameterizingAllocator< CCACHINGHASH<cint64, CBackendRepresentativeMemoryLabelCacheItem*>, CContext* >::allocateAndConstructAndParameterize(mContext->getMemoryAllocationManager(), mContext);
36 mPrevNeighbourRoleSetLabelHash = nullptr;
37 }
38
39 CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash* CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash::initNeighbourRoleSetHash(CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash* neighbourRoleSetHash, bool detach) {
40 if (neighbourRoleSetHash) {
41 if (detach) {
42
43 if (neighbourRoleSetHash->mPrevNeighbourRoleSetLabelHash) {
44 *mNeighbourRoleSetLabelHash = *neighbourRoleSetHash->mPrevNeighbourRoleSetLabelHash;
45 mNeighbourRoleSetLabelHash->detach();
46 for (CCACHINGHASH<cint64, CBackendRepresentativeMemoryLabelCacheItem*>::const_iterator it = neighbourRoleSetHash->mNeighbourRoleSetLabelHash->constBegin(), itEnd = neighbourRoleSetHash->mNeighbourRoleSetLabelHash->constEnd(); it != itEnd; ++it) {
47 cint64 neighbourId = it.key();
48 CBackendRepresentativeMemoryLabelCacheItem* item = it.value();
49 mNeighbourRoleSetLabelHash->insert(neighbourId, item);
50 }
51 } else {
52 *mNeighbourRoleSetLabelHash = *neighbourRoleSetHash->mNeighbourRoleSetLabelHash;
53 mNeighbourRoleSetLabelHash->detach();
54 }
55 mPrevNeighbourRoleSetLabelHash = nullptr;
56
57 } else {
58
59 if (!neighbourRoleSetHash->mPrevNeighbourRoleSetLabelHash && neighbourRoleSetHash->mNeighbourRoleSetLabelHash->size() <= 20) {
60 *mNeighbourRoleSetLabelHash = *neighbourRoleSetHash->mNeighbourRoleSetLabelHash;
61 mPrevNeighbourRoleSetLabelHash = nullptr;
62 } else if (!neighbourRoleSetHash->mPrevNeighbourRoleSetLabelHash && neighbourRoleSetHash->mNeighbourRoleSetLabelHash->size() > 20) {
63 mPrevNeighbourRoleSetLabelHash = neighbourRoleSetHash->mNeighbourRoleSetLabelHash;
64 } else {
65
66 if (neighbourRoleSetHash->mNeighbourRoleSetLabelHash->size() > neighbourRoleSetHash->mPrevNeighbourRoleSetLabelHash->size()) {
67 *mNeighbourRoleSetLabelHash = *neighbourRoleSetHash->mPrevNeighbourRoleSetLabelHash;
68
69 for (CCACHINGHASH<cint64, CBackendRepresentativeMemoryLabelCacheItem*>::const_iterator it = neighbourRoleSetHash->mNeighbourRoleSetLabelHash->constBegin(), itEnd = neighbourRoleSetHash->mNeighbourRoleSetLabelHash->constEnd(); it != itEnd; ++it) {
70 cint64 neighbourId = it.key();
71 CBackendRepresentativeMemoryLabelCacheItem* item = it.value();
72 mNeighbourRoleSetLabelHash->insert(neighbourId, item);
73 }
74 mPrevNeighbourRoleSetLabelHash = nullptr;
75 } else {
76 *mNeighbourRoleSetLabelHash = *neighbourRoleSetHash->mNeighbourRoleSetLabelHash;
77 mPrevNeighbourRoleSetLabelHash = neighbourRoleSetHash->mPrevNeighbourRoleSetLabelHash;
78 }
79
80 }
81 }
82 }
83 return this;
84 }
85
86
87 CBackendRepresentativeMemoryLabelCacheItem* CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash::getNeighbourRoleSetLabel(cint64 neighbourIndiId) {
88 CBackendRepresentativeMemoryLabelCacheItem* item = mNeighbourRoleSetLabelHash->value(neighbourIndiId);
89 if (!item && mPrevNeighbourRoleSetLabelHash) {
90 item = mPrevNeighbourRoleSetLabelHash->value(neighbourIndiId);
91 }
92 return item;
93 }
94
95 cint64 CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash::getNeighbourCount() {
96 cint64 count = mNeighbourRoleSetLabelHash->size();
97 if (mPrevNeighbourRoleSetLabelHash) {
98 count += mPrevNeighbourRoleSetLabelHash->size();
99 }
100 return count;
101 }
102
103
104 CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash* CBackendRepresentativeMemoryCacheIndividualNeighbourRoleSetHash::setNeighbourRoleSetLabel(cint64 neighbourIndiId, CBackendRepresentativeMemoryLabelCacheItem* neighbourRoleSetLabel) {
105 mNeighbourRoleSetLabelHash->insert(neighbourIndiId, neighbourRoleSetLabel);
106 return this;
107 }
108
109
110 }; // end namespace Cache
111
112 }; // end namespace Kernel
113
114 }; // end namespace Reasoner
115
116 }; // end namespace Konclude