Debian Codegraph @

Source/Reasoner/Kernel/Cache/CSignatureSatisfiableExpanderCacheReader.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 "CSignatureSatisfiableExpanderCacheReader.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Cache {
31
32
33 CSignatureSatisfiableExpanderCacheReader::CSignatureSatisfiableExpanderCacheReader() : CLinkerBase<CSignatureSatisfiableExpanderCacheReader*,CSignatureSatisfiableExpanderCacheReader>(this) {
34 mCurrentSlot = nullptr;
35 }
36
37
38 CSignatureSatisfiableExpanderCacheReader* CSignatureSatisfiableExpanderCacheReader::updateSlot(CSignatureSatisfiableExpanderCacheSlotItem* updatedSlot) {
39 CSignatureSatisfiableExpanderCacheSlotItem* prevSlot = mUpdatedSlot.fetchAndStoreOrdered(updatedSlot);
40 if (prevSlot != nullptr) {
41 prevSlot->decReader();
42 }
43 return this;
44 }
45
46
47 bool CSignatureSatisfiableExpanderCacheReader::hasUpdatedSlotItem() {
48 return mUpdatedSlot.fetchAndAddRelaxed(0) != nullptr;
49 }
50
51
52 bool CSignatureSatisfiableExpanderCacheReader::switchToUpdatedSlotItem() {
53 CSignatureSatisfiableExpanderCacheSlotItem* updatedSlot = mUpdatedSlot.fetchAndStoreOrdered(nullptr);
54 if (updatedSlot) {
55 CSignatureSatisfiableExpanderCacheSlotItem* prevSlot = mCurrentSlot;
56 mCurrentSlot = updatedSlot;
57 if (prevSlot != nullptr) {
58 prevSlot->decReader();
59 }
60 return true;
61 }
62 return false;
63 }
64
65
66 bool CSignatureSatisfiableExpanderCacheReader::hasCacheEntry(cint64 signature) {
67 if (hasUpdatedSlotItem()) {
68 switchToUpdatedSlotItem();
69 }
70 if (mCurrentSlot) {
71 CCACHINGHASH<cint64,CSignatureSatisfiableExpanderCacheRedirectionItem*>* sigItemHash = mCurrentSlot->getSignatureItemHash();
72 if (sigItemHash) {
73 return sigItemHash->contains(signature);
74 }
75 }
76 return false;
77 }
78
79
80
81 CSignatureSatisfiableExpanderCacheEntry* CSignatureSatisfiableExpanderCacheReader::getCacheEntry(cint64 signature) {
82 CSignatureSatisfiableExpanderCacheEntry* entry = nullptr;
83 if (hasUpdatedSlotItem()) {
84 switchToUpdatedSlotItem();
85 }
86 if (mCurrentSlot) {
87 CCACHINGHASH<cint64,CSignatureSatisfiableExpanderCacheRedirectionItem*>* sigItemHash = mCurrentSlot->getSignatureItemHash();
88 if (sigItemHash) {
89 CSignatureSatisfiableExpanderCacheRedirectionItem* item = sigItemHash->value(signature,nullptr);
90 if (item) {
91 entry = item->getCacheEntry();
92 }
93 }
94 }
95 return entry;
96 }
97
98
99
100 CSignatureSatisfiableExpanderCacheEntry* CSignatureSatisfiableExpanderCacheReader::getCacheEntry(CCACHINGSET<CCacheValue>* cacheValueSet) {
101 CSignatureSatisfiableExpanderCacheEntry* entry = nullptr;
102 if (hasUpdatedSlotItem()) {
103 switchToUpdatedSlotItem();
104 }
105 if (mCurrentSlot) {
106 CCACHINGHASH<CSignatureSatisfiableExpanderCacheHasher,CSignatureSatisfiableExpanderCacheRedirectionItem*>* hasherItemHash = mCurrentSlot->getHasherItemHash();
107 if (hasherItemHash) {
108 CSignatureSatisfiableExpanderCacheHasher hashValue(cacheValueSet);
109 CSignatureSatisfiableExpanderCacheRedirectionItem* item = hasherItemHash->value(hashValue,nullptr);
110 if (item) {
111 entry = item->getCacheEntry();
112 }
113 }
114 }
115 return entry;
116 }
117
118
119
120 }; // end namespace Cache
121
122 }; // end namespace Kernel
123
124 }; // end namespace Reasoner
125
126 }; // end namespace Konclude