Debian Codegraph @

Source/Reasoner/Kernel/Process/CProcessSetHasher.h

raw
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 #ifndef KONCLUDE_REASONER_KERNEL_PROCESS_CPROCESSSETHASHER_H
22 #define KONCLUDE_REASONER_KERNEL_PROCESS_CPROCESSSETHASHER_H
23
24 // Libraries includes
25 #include <QHash>
26
27 // Namespace includes
28 #include "ProcessSettings.h"
29
30
31 // Other includes
32
33
34 // Logger includes
35 #include "Logger/CLogger.h"
36
37
38 namespace Konclude {
39
40 using namespace Utilities::Container;
41
42 namespace Reasoner {
43
44 namespace Kernel {
45
46 namespace Process {
47
48 /*!
49 *
50 * \class CProcessSetHasher
51 * \author Andreas Steigmiller
52 * \version 0.1
53 * \brief TODO
54 *
55 */
56 template<class T>
57 class CProcessSetHasher {
58 // public methods
59 public:
60 //! Constructor
61 CProcessSetHasher(CPROCESSSET<T>* processSet) {
62 mProcessSet = processSet;
63 mHashValue = 0;
64 if (mProcessSet) {
65 for (typename CPROCESSSET<T>::const_iterator it = processSet->constBegin(), itEnd = processSet->constEnd(); it != itEnd; ++it) {
66 mHashValue += qHash(*it);
67 }
68 }
69 }
70
71 cint64 getNodeHashValue() const {
72 return mHashValue;
73 }
74
75 bool operator==(const CProcessSetHasher& processSetHasher) const {
76 if (mHashValue != processSetHasher.getNodeHashValue()) {
77 return false;
78 }
79 return mProcessSet->operator==(*processSetHasher.mProcessSet);
80 }
81
82
83 // protected methods
84 protected:
85
86 // protected variables
87 protected:
88 CPROCESSSET<T>* mProcessSet;
89 cint64 mHashValue;
90
91 // private methods
92 private:
93
94 // private variables
95 private:
96
97 };
98
99
100 template<class T>
101 inline uint qHash(const CProcessSetHasher<T>& processSetHasher) {
102 qint64 key = (qint64)processSetHasher.getNodeHashValue();
103 if (sizeof(quint64) > sizeof(uint)) {
104 return uint((key >> (8 * sizeof(uint) - 1)) ^ key);
105 } else {
106 return uint(key);
107 }
108 }
109
110 }; // end namespace Process
111
112 }; // end namespace Kernel
113
114 }; // end namespace Reasoner
115
116 }; // end namespace Konclude
117
118 #endif // KONCLUDE_REASONER_KERNEL_PROCESS_CPROCESSSETHASHER_H