| 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 |
#ifdef KONCLUDE_REDLAND_INTEGRATION |
| 22 |
|
| 23 |
#ifndef KONCLUDE_REASONER_TRIPLES_CREDLANDURIHASHER_H |
| 24 |
#define KONCLUDE_REASONER_TRIPLES_CREDLANDURIHASHER_H |
| 25 |
|
| 26 |
// Libraries includes |
| 27 |
#include <QHash> |
| 28 |
#include <Redland.h> |
| 29 |
|
| 30 |
// Namespace includes |
| 31 |
#include "TriplesSettings.h" |
| 32 |
|
| 33 |
|
| 34 |
// Other includes |
| 35 |
#include "Utilities/UtilitiesSettings.h" |
| 36 |
|
| 37 |
|
| 38 |
// Logger includes |
| 39 |
#include "Logger/CLogger.h" |
| 40 |
|
| 41 |
|
| 42 |
namespace Konclude { |
| 43 |
|
| 44 |
using namespace Utilities; |
| 45 |
|
| 46 |
namespace Reasoner { |
| 47 |
|
| 48 |
namespace Triples { |
| 49 |
|
| 50 |
|
| 51 |
/*! |
| 52 |
* |
| 53 |
* \class CRedlandUriHasher |
| 54 |
* \author Andreas Steigmiller |
| 55 |
* \version 0.1 |
| 56 |
* \brief TODO |
| 57 |
* |
| 58 |
*/ |
| 59 |
class CRedlandUriHasher { |
| 60 |
// public methods |
| 61 |
public: |
| 62 |
//! Constructor |
| 63 |
CRedlandUriHasher(librdf_uri* uri) { |
| 64 |
mUri = uri; |
| 65 |
mHashValue = hash_c_string((const char*)librdf_uri_as_string(mUri)); |
| 66 |
} |
| 67 |
|
| 68 |
cint64 getUriHashValue() const { |
| 69 |
return mHashValue; |
| 70 |
} |
| 71 |
|
| 72 |
bool operator==(const CRedlandUriHasher& uriHasher) const { |
| 73 |
if (mHashValue != uriHasher.getUriHashValue()) { |
| 74 |
return false; |
| 75 |
} |
| 76 |
if (!librdf_uri_equals(mUri, uriHasher.mUri)) { |
| 77 |
return false; |
| 78 |
} |
| 79 |
return true; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
cint64 hash_c_string(const char* p) { |
| 84 |
cint64 result = 0; |
| 85 |
const cint64 prime = 31; |
| 86 |
for (cint64 i = 0; p[i] != 0; ++i) { |
| 87 |
result = p[i] + (result * prime); |
| 88 |
} |
| 89 |
return result; |
| 90 |
} |
| 91 |
|
| 92 |
// protected methods |
| 93 |
protected: |
| 94 |
|
| 95 |
// protected variables |
| 96 |
protected: |
| 97 |
librdf_uri* mUri; |
| 98 |
cint64 mHashValue; |
| 99 |
|
| 100 |
// private methods |
| 101 |
private: |
| 102 |
|
| 103 |
// private variables |
| 104 |
private: |
| 105 |
|
| 106 |
}; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
inline uint qHash(const CRedlandUriHasher& uriHasher) { |
| 112 |
qint64 key = (qint64)uriHasher.getUriHashValue(); |
| 113 |
if (sizeof(quint64) > sizeof(uint)) { |
| 114 |
return uint((key >> (8 * sizeof(uint) - 1)) ^ key); |
| 115 |
} else { |
| 116 |
return uint(key); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
}; // end namespace Triples |
| 122 |
|
| 123 |
}; // end namespace Reasoner |
| 124 |
|
| 125 |
}; // end namespace Konclude |
| 126 |
|
| 127 |
|
| 128 |
#endif // KONCLUDE_REASONER_TRIPLES_CREDLANDURIHASHER_H |
| 129 |
|
| 130 |
#endif // !KONCLUDE_REDLAND_INTEGRATION |