| 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 "CSignatureSatisfiableExpanderCacheHasher.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Cache { |
| 31 |
|
| 32 |
|
| 33 |
CSignatureSatisfiableExpanderCacheHasher::CSignatureSatisfiableExpanderCacheHasher(CCACHINGSET<CCacheValue>* cacheValueSet) { |
| 34 |
mCacheValueSet = cacheValueSet; |
| 35 |
mHashValue = 0; |
| 36 |
mCacheValueCount = cacheValueSet->count(); |
| 37 |
mCacheValueLinker = nullptr; |
| 38 |
calculateHashValue(mCacheValueSet); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
CSignatureSatisfiableExpanderCacheHasher::CSignatureSatisfiableExpanderCacheHasher(CExpanderCacheValueLinker* cacheValueLinker, cint64 count) { |
| 43 |
mCacheValueSet = nullptr; |
| 44 |
mHashValue = 0; |
| 45 |
mCacheValueCount = count; |
| 46 |
mCacheValueLinker = cacheValueLinker; |
| 47 |
calculateHashValue(mCacheValueLinker,mCacheValueCount); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
CSignatureSatisfiableExpanderCacheHasher::CSignatureSatisfiableExpanderCacheHasher(const CSignatureSatisfiableExpanderCacheHasher& hasher) { |
| 53 |
mHashValue = hasher.mHashValue; |
| 54 |
mCacheValueSet = hasher.mCacheValueSet; |
| 55 |
mCacheValueLinker = hasher.mCacheValueLinker; |
| 56 |
mCacheValueCount = hasher.mCacheValueCount; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
cint64 CSignatureSatisfiableExpanderCacheHasher::getHashValue() const { |
| 61 |
return mHashValue; |
| 62 |
} |
| 63 |
|
| 64 |
bool CSignatureSatisfiableExpanderCacheHasher::operator==(const CSignatureSatisfiableExpanderCacheHasher& hasher) const { |
| 65 |
if (mHashValue != hasher.mHashValue) { |
| 66 |
return false; |
| 67 |
} |
| 68 |
if (mCacheValueCount != hasher.mCacheValueCount) { |
| 69 |
return false; |
| 70 |
} |
| 71 |
if (mCacheValueLinker && hasher.mCacheValueLinker) { |
| 72 |
if (!hasEqualCacheValues(mCacheValueLinker,hasher.mCacheValueLinker,mCacheValueCount)) { |
| 73 |
return false; |
| 74 |
} |
| 75 |
} else if (mCacheValueSet && hasher.mCacheValueSet) { |
| 76 |
if (!hasEqualCacheValues(mCacheValueSet,hasher.mCacheValueSet)) { |
| 77 |
return false; |
| 78 |
} |
| 79 |
} else if (mCacheValueLinker && hasher.mCacheValueSet) { |
| 80 |
if (!hasEqualCacheValues(mCacheValueLinker,hasher.mCacheValueSet,mCacheValueCount)) { |
| 81 |
return false; |
| 82 |
} |
| 83 |
} else { |
| 84 |
if (!hasEqualCacheValues(hasher.mCacheValueLinker,mCacheValueSet,mCacheValueCount)) { |
| 85 |
return false; |
| 86 |
} |
| 87 |
} |
| 88 |
return false; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
void CSignatureSatisfiableExpanderCacheHasher::calculateHashValue(CCACHINGSET<CCacheValue>* cacheValueSet) { |
| 93 |
mHashValue = 0; |
| 94 |
for (CCACHINGSET<CCacheValue>::const_iterator it = cacheValueSet->constBegin(), itEnd = cacheValueSet->constEnd(); it != itEnd; ++it) { |
| 95 |
CCacheValue cacheValue(*it); |
| 96 |
extendHashValue(&cacheValue); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
void CSignatureSatisfiableExpanderCacheHasher::calculateHashValue(CExpanderCacheValueLinker* cacheValueLinker, cint64 count) { |
| 101 |
mHashValue = 0; |
| 102 |
CExpanderCacheValueLinker* cacheValueLinkerIt = cacheValueLinker; |
| 103 |
cint64 nr = 0; |
| 104 |
while (cacheValueLinkerIt && nr++ < count) { |
| 105 |
extendHashValue(cacheValueLinkerIt->getCacheValue()); |
| 106 |
cacheValueLinkerIt = cacheValueLinkerIt->getNext(); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
void CSignatureSatisfiableExpanderCacheHasher::extendHashValue(CCacheValue* cacheValue) { |
| 112 |
uint nextHashValue = qHash(*cacheValue); |
| 113 |
mHashValue += nextHashValue; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
bool CSignatureSatisfiableExpanderCacheHasher::hasEqualCacheValues(CExpanderCacheValueLinker* cacheValueLinker, CExpanderCacheValueLinker* cacheValueLinker2, cint64 count) const { |
| 118 |
cint64 nr = 0; |
| 119 |
while (cacheValueLinker && cacheValueLinker2 && nr++ < count) { |
| 120 |
if (*cacheValueLinker->getCacheValue() != *cacheValueLinker2->getCacheValue()) { |
| 121 |
return false; |
| 122 |
} |
| 123 |
cacheValueLinker = cacheValueLinker->getNext(); |
| 124 |
cacheValueLinker2 = cacheValueLinker2->getNext(); |
| 125 |
} |
| 126 |
if (nr < count) { |
| 127 |
if (cacheValueLinker || cacheValueLinker2) { |
| 128 |
return false; |
| 129 |
} |
| 130 |
} |
| 131 |
return true; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
bool CSignatureSatisfiableExpanderCacheHasher::hasEqualCacheValues(CCACHINGSET<CCacheValue>* cacheValueSet, CCACHINGSET<CCacheValue>* cacheValueSet2) const { |
| 136 |
CCACHINGSET<CCacheValue>::const_iterator it1 = cacheValueSet->constBegin(), it1End = cacheValueSet->constEnd(); |
| 137 |
CCACHINGSET<CCacheValue>::const_iterator it2 = cacheValueSet2->constBegin(), it2End = cacheValueSet2->constEnd(); |
| 138 |
while (it1 != it1End) { |
| 139 |
if (*it1 != *it2) { |
| 140 |
return false; |
| 141 |
} |
| 142 |
++it1; |
| 143 |
++it2; |
| 144 |
} |
| 145 |
return true; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
bool CSignatureSatisfiableExpanderCacheHasher::hasEqualCacheValues(CExpanderCacheValueLinker* cacheValueLinker, CCACHINGSET<CCacheValue>* cacheValueSet, cint64 count) const { |
| 150 |
CExpanderCacheValueLinker* cacheValueLinkerIt = cacheValueLinker; |
| 151 |
cint64 nr = 0; |
| 152 |
while (cacheValueLinkerIt && nr++ < count) { |
| 153 |
if (!cacheValueSet->contains(*cacheValueLinkerIt->getCacheValue())) { |
| 154 |
return false; |
| 155 |
} |
| 156 |
cacheValueLinkerIt = cacheValueLinkerIt->getNext(); |
| 157 |
} |
| 158 |
return true; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
}; // end namespace Cache |
| 163 |
|
| 164 |
}; // end namespace Kernel |
| 165 |
|
| 166 |
}; // end namespace Reasoner |
| 167 |
|
| 168 |
}; // end namespace Konclude |