| 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 "COccurrenceUnsatisfiableCacheEntry.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Cache { |
| 31 |
|
| 32 |
|
| 33 |
COccurrenceUnsatisfiableCacheEntry::COccurrenceUnsatisfiableCacheEntry(const CCacheValue &cacheValue, COccurrenceUnsatisfiableCacheEntry *prevUnsatCacheEntry, qint64 writeUpdateSlotCount, qint64 currentActiveSlot, qint64 readCountVecSize) { |
| 34 |
prevEntry = prevUnsatCacheEntry; |
| 35 |
cacheVal = cacheValue; |
| 36 |
updateSlotCount = writeUpdateSlotCount; |
| 37 |
activeSlot = currentActiveSlot; |
| 38 |
lastCacheEntriesHash = 0; |
| 39 |
unsatTerm = false; |
| 40 |
maxItemEntry = Q_INT64_C(0x8000000000000000); |
| 41 |
minItemEntry = Q_INT64_C(0x7FFFFFFFFFFFFFFF); |
| 42 |
|
| 43 |
cacheEntriesHashes = new COccurrenceUnsatisfiableCacheEntriesHash *[updateSlotCount]; |
| 44 |
for (qint64 idx = 0; idx < updateSlotCount; ++idx) { |
| 45 |
cacheEntriesHashes[idx] = 0; |
| 46 |
} |
| 47 |
|
| 48 |
readCountCount = readCountVecSize; |
| 49 |
if (readCountCount > 0) { |
| 50 |
readCountVec = new qint64[readCountCount]; |
| 51 |
} else { |
| 52 |
readCountVec = 0; |
| 53 |
} |
| 54 |
|
| 55 |
serialized = false; |
| 56 |
cacheTermValuesList = 0; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
COccurrenceUnsatisfiableCacheEntry::~COccurrenceUnsatisfiableCacheEntry() { |
| 61 |
delete cacheEntriesHashes; |
| 62 |
if (readCountVec) { |
| 63 |
delete[] readCountVec; |
| 64 |
} |
| 65 |
if (cacheTermValuesList) { |
| 66 |
delete cacheTermValuesList; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
bool COccurrenceUnsatisfiableCacheEntry::isSerialized() { |
| 72 |
return serialized; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
COccurrenceUnsatisfiableCacheEntry *COccurrenceUnsatisfiableCacheEntry::getPreviousUnsatisfiableCacheEntry() { |
| 77 |
return prevEntry; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
COccurrenceUnsatisfiableCacheEntriesHash *COccurrenceUnsatisfiableCacheEntry::setCacheEntriesHashSlotGetPrevious(qint64 slotIndex, COccurrenceUnsatisfiableCacheEntriesHash *entriesHash) { |
| 82 |
COccurrenceUnsatisfiableCacheEntriesHash *tmpHash = cacheEntriesHashes[slotIndex]; |
| 83 |
cacheEntriesHashes[slotIndex] = entriesHash; |
| 84 |
lastCacheEntriesHash = entriesHash; |
| 85 |
return tmpHash; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
COccurrenceUnsatisfiableCacheEntriesHash *COccurrenceUnsatisfiableCacheEntry::updateSlotCacheHashGetPrevious(qint64 slotIndex) { |
| 90 |
COccurrenceUnsatisfiableCacheEntriesHash *prevHash = 0; |
| 91 |
if (cacheEntriesHashes[slotIndex] != lastCacheEntriesHash) { |
| 92 |
prevHash = cacheEntriesHashes[slotIndex]; |
| 93 |
cacheEntriesHashes[slotIndex] = lastCacheEntriesHash; |
| 94 |
lastCacheEntriesHash->incReferenceCount(); |
| 95 |
} |
| 96 |
return prevHash; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
void COccurrenceUnsatisfiableCacheEntry::removeSlotCacheEntriesHash(qint64 slotIndex) { |
| 101 |
cacheEntriesHashes[slotIndex] = 0; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
void COccurrenceUnsatisfiableCacheEntry::setActiveSlot(qint64 slotIndex) { |
| 106 |
activeSlot = slotIndex; |
| 107 |
} |
| 108 |
|
| 109 |
void COccurrenceUnsatisfiableCacheEntry::setMinimumCandidate(qint64 value) { |
| 110 |
minItemEntry = qMin(minItemEntry,value); |
| 111 |
} |
| 112 |
|
| 113 |
void COccurrenceUnsatisfiableCacheEntry::setMaximumCandidate(qint64 value) { |
| 114 |
maxItemEntry = qMax(maxItemEntry,value); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
qint64 COccurrenceUnsatisfiableCacheEntry::getMaxTag() { |
| 119 |
return maxItemEntry; |
| 120 |
} |
| 121 |
|
| 122 |
qint64 COccurrenceUnsatisfiableCacheEntry::getMinTag() { |
| 123 |
return minItemEntry; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
COccurrenceUnsatisfiableCacheEntriesHash *COccurrenceUnsatisfiableCacheEntry::getCacheEntriesHash() { |
| 129 |
return lastCacheEntriesHash; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
COccurrenceUnsatisfiableCacheEntriesHash *COccurrenceUnsatisfiableCacheEntry::getSlotCacheEntriesHash(qint64 slotIndex) { |
| 134 |
return cacheEntriesHashes[slotIndex]; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
bool COccurrenceUnsatisfiableCacheEntry::isUnsatisfiableTermination() { |
| 139 |
return unsatTerm; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
CCacheValue COccurrenceUnsatisfiableCacheEntry::getCacheValue() { |
| 144 |
return cacheVal; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
qint64 COccurrenceUnsatisfiableCacheEntry::getTotalReadCount() { |
| 149 |
qint64 readCount = 0; |
| 150 |
for (qint64 i = 0; i < readCountCount; ++i) { |
| 151 |
readCount += readCountVec[i]; |
| 152 |
} |
| 153 |
return readCount; |
| 154 |
} |
| 155 |
|
| 156 |
void COccurrenceUnsatisfiableCacheEntry::incReadCount(qint64 readCountIndex) { |
| 157 |
if (readCountIndex >= 0 && readCountIndex < readCountCount) { |
| 158 |
readCountVec[readCountIndex] = readCountVec[readCountIndex]+1; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
COccurrenceUnsatisfiableCacheEntry *COccurrenceUnsatisfiableCacheEntry::setCacheTerminationValuesList(QList<CCacheValue> *cacheTerminationValuesList) { |
| 163 |
if (cacheTermValuesList) { |
| 164 |
delete cacheTermValuesList; |
| 165 |
} |
| 166 |
cacheTermValuesList = cacheTerminationValuesList; |
| 167 |
unsatTerm = cacheTermValuesList != 0; |
| 168 |
return this; |
| 169 |
} |
| 170 |
|
| 171 |
COccurrenceUnsatisfiableCacheEntry *COccurrenceUnsatisfiableCacheEntry::copyCacheTerminationValuesList(QList<CCacheValue> *cacheTerminationValuesList) { |
| 172 |
if (cacheTermValuesList) { |
| 173 |
delete cacheTermValuesList; |
| 174 |
} |
| 175 |
if (cacheTerminationValuesList) { |
| 176 |
cacheTermValuesList = new QList<CCacheValue>(*cacheTerminationValuesList); |
| 177 |
} else { |
| 178 |
cacheTermValuesList = 0; |
| 179 |
} |
| 180 |
unsatTerm = cacheTermValuesList != 0; |
| 181 |
return this; |
| 182 |
} |
| 183 |
|
| 184 |
QList<CCacheValue> *COccurrenceUnsatisfiableCacheEntry::getCacheTerminationValuesList() { |
| 185 |
return cacheTermValuesList; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
}; // end namespace Cache |
| 191 |
|
| 192 |
}; // end namespace Kernel |
| 193 |
|
| 194 |
}; // end namespace Reasoner |
| 195 |
|
| 196 |
}; // end namespace Konclude |