Debian Codegraph @

Source/Reasoner/Triples/CRedlandNodeHasher.h

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