| 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 "CConceptSetSignature.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Process { |
| 31 |
|
| 32 |
CConceptSetSignature::CConceptSetSignature() { |
| 33 |
reset(); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
CConceptSetSignature::~CConceptSetSignature() { |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
CConceptSetSignature* CConceptSetSignature::reset() { |
| 42 |
mSigValue = 0; |
| 43 |
mValue1 = 0; |
| 44 |
mValue2 = 1; |
| 45 |
mValue3 = 0; |
| 46 |
return this; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
cint64 CConceptSetSignature::getSignatureValue() { |
| 51 |
return mSigValue; |
| 52 |
} |
| 53 |
|
| 54 |
CConceptSetSignature* CConceptSetSignature::addConceptSignature(CConcept* concept, bool negation) { |
| 55 |
cint64 conTag = concept->getConceptTag(); |
| 56 |
cint64 conSig = conTag; |
| 57 |
if (negation) { |
| 58 |
conSig = std::numeric_limits<cint64>::max() - conTag; |
| 59 |
} |
| 60 |
mValue1 += conSig; |
| 61 |
mValue2 *= conSig; |
| 62 |
mValue3 += (cint64)concept; |
| 63 |
mSigValue = mValue1 ^ mValue2 ^ mValue3; |
| 64 |
return this; |
| 65 |
} |
| 66 |
|
| 67 |
CConceptSetSignature* CConceptSetSignature::addConceptSignature(CConceptDescriptor* conceptDescriptor) { |
| 68 |
CConcept* concept = conceptDescriptor->getConcept(); |
| 69 |
bool negation = conceptDescriptor->isNegated(); |
| 70 |
addConceptSignature(concept,negation); |
| 71 |
return this; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
bool CConceptSetSignature::operator==(const CConceptSetSignature& conSig) { |
| 76 |
return mSigValue == conSig.mSigValue; |
| 77 |
} |
| 78 |
|
| 79 |
bool CConceptSetSignature::isSignatureEquivalent(const CConceptSetSignature& conSig) { |
| 80 |
return mSigValue == conSig.mSigValue; |
| 81 |
} |
| 82 |
|
| 83 |
bool CConceptSetSignature::isSignatureEquivalent(CConceptSetSignature* conSig) { |
| 84 |
return conSig && mSigValue == conSig->mSigValue; |
| 85 |
} |
| 86 |
|
| 87 |
}; // end namespace Process |
| 88 |
|
| 89 |
}; // end namespace Kernel |
| 90 |
|
| 91 |
}; // end namespace Reasoner |
| 92 |
|
| 93 |
}; // end namespace Konclude |