| 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 "CTrackedClashedDescriptorHasher.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Algorithm { |
| 31 |
|
| 32 |
CTrackedClashedDescriptorHasher::CTrackedClashedDescriptorHasher(CTrackedClashedDescriptor* trackedClashedDescriptor) { |
| 33 |
mTrackedClashedDes = trackedClashedDescriptor; |
| 34 |
mHashValue = calculateDescriptorHashValue(mTrackedClashedDes); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
CTrackedClashedDescriptorHasher::CTrackedClashedDescriptorHasher(const CTrackedClashedDescriptorHasher& hasher) { |
| 39 |
mHashValue = hasher.mHashValue; |
| 40 |
mTrackedClashedDes = hasher.mTrackedClashedDes; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
cint64 CTrackedClashedDescriptorHasher::getDescriptorHashValue() const { |
| 46 |
return mHashValue; |
| 47 |
} |
| 48 |
|
| 49 |
cint64 CTrackedClashedDescriptorHasher::calculateDescriptorHashValue(CTrackedClashedDescriptor* des) { |
| 50 |
cint64 hashValue = 0; |
| 51 |
hashValue += des->getAppropriatedIndividualID(); |
| 52 |
if (des->getConceptDescriptor()) { |
| 53 |
hashValue += (cint64)des->getConceptDescriptor()->getConcept(); |
| 54 |
if (des->getConceptDescriptor()->getNegation()) { |
| 55 |
hashValue = (hashValue << 1)+13; |
| 56 |
} |
| 57 |
} |
| 58 |
hashValue += (cint64)des->getDependencyTrackPoint(); |
| 59 |
hashValue += (cint64)des->getVariableBindingPath(); |
| 60 |
return hashValue; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
bool CTrackedClashedDescriptorHasher::operator==(const CTrackedClashedDescriptorHasher& clashedDesHasher) const { |
| 65 |
if (mHashValue != clashedDesHasher.mHashValue) { |
| 66 |
return false; |
| 67 |
} |
| 68 |
if (mTrackedClashedDes->getAppropriatedIndividualID() != clashedDesHasher.mTrackedClashedDes->getAppropriatedIndividualID()) { |
| 69 |
return false; |
| 70 |
} |
| 71 |
if (mTrackedClashedDes->getConceptDescriptor() && clashedDesHasher.mTrackedClashedDes->getConceptDescriptor()) { |
| 72 |
if (mTrackedClashedDes->getConceptDescriptor()->getConcept() != clashedDesHasher.mTrackedClashedDes->getConceptDescriptor()->getConcept()) { |
| 73 |
return false; |
| 74 |
} |
| 75 |
if (mTrackedClashedDes->getConceptDescriptor()->getNegation() != clashedDesHasher.mTrackedClashedDes->getConceptDescriptor()->getNegation()) { |
| 76 |
return false; |
| 77 |
} |
| 78 |
} else { |
| 79 |
if (mTrackedClashedDes->getConceptDescriptor() || clashedDesHasher.mTrackedClashedDes->getConceptDescriptor()) { |
| 80 |
return false; |
| 81 |
} |
| 82 |
} |
| 83 |
if (mTrackedClashedDes->getDependencyTrackPoint() != clashedDesHasher.mTrackedClashedDes->getDependencyTrackPoint()) { |
| 84 |
return false; |
| 85 |
} |
| 86 |
if (mTrackedClashedDes->getVariableBindingPath() != clashedDesHasher.mTrackedClashedDes->getVariableBindingPath()) { |
| 87 |
return false; |
| 88 |
} |
| 89 |
return true; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
}; // end namespace Algorithm |
| 94 |
|
| 95 |
}; // end namespace Kernel |
| 96 |
|
| 97 |
}; // end namespace Reasoner |
| 98 |
|
| 99 |
}; // end namespace Konclude |