@@ -27,79 +27,81 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
27
namespace cppcore {
28
28
29
29
// -------------------------------------------------------------------------------------------------
30
- // / @class Hash
30
+ // / @class THash
31
31
// / @ingroup CPPCore
32
32
// /
33
33
// / @brief This class is used to calculate the hash value for a given integer or character buffer.
34
34
// -------------------------------------------------------------------------------------------------
35
- class Hash {
35
+ template <class T >
36
+ class THash {
36
37
public:
37
38
// / @brief The default class constructor.
38
- Hash ();
39
+ THash ();
39
40
40
41
// / @brief The class constructor with a given hash value.
41
42
// / @param hash [in] An integer value to compute the hash from.
42
- explicit Hash ( unsigned int hash);
43
+ explicit THash (T hash);
43
44
44
45
// / @brief The class constructor with a given char buffer.
45
46
// / @param value [in] A character buffer to compute the hash from.
46
47
// / @param base [in] The table base.
47
- explicit Hash (const char *buffer, unsigned int base);
48
+ explicit THash (const char *buffer, T base);
48
49
49
50
// / @brief The class constructor with a given unsigned int value.
50
51
// / @param value [in] An unsigned int value to compute the hash from.
51
52
// / @param base [in] The table base.
52
- explicit Hash ( unsigned int value, unsigned int base);
53
+ explicit THash (T value, T base);
53
54
54
55
// / @brief The class destructor.
55
- ~Hash () ;
56
+ ~THash () = default ;
56
57
57
58
// / @brief Computes the hash value for a given character buffer.
58
59
// / @param buffer [in] The buffer.
59
60
// / @param base [in] The table base.
60
61
// / @return The hash value.
61
- static unsigned int toHash (const char *buffer, unsigned int base);
62
+ static T toHash (const char *buffer, T base);
62
63
63
64
// / @brief Computes the hash value for a given unsigned int value.
64
65
// / @param buffer [in] The unsigned int value.
65
66
// / @param base [in] The table base.
66
67
// / @return The hash value.
67
- static unsigned int toHash (unsigned int value, unsigned int base);
68
+ static T toHash (T value, T base);
68
69
69
70
// / brief Returns the stored hash value.
70
71
// / @return The hash value.
71
- unsigned int hashValue () const ;
72
+ T hashValue () const ;
72
73
73
74
private:
74
- unsigned int m_hash;
75
+ T m_hash;
75
76
};
76
77
77
- inline Hash::Hash () :
78
+ template <class T >
79
+ inline THash<T>::THash() :
78
80
m_hash (0 ) {
79
81
// empty
80
82
}
81
83
82
- inline Hash::Hash (unsigned int hash) :
84
+ template <class T >
85
+ inline THash<T>::THash(T hash) :
83
86
m_hash (hash) {
84
87
// empty
85
88
}
86
89
87
- inline Hash::Hash (const char *buffer, unsigned int base) :
88
- m_hash(Hash::toHash(buffer, base)) {
90
+ template <class T >
91
+ inline THash<T>::THash(const char *buffer, T base) :
92
+ m_hash (THash::toHash(buffer, base)) {
89
93
// empty
90
94
}
91
95
92
- inline Hash::Hash (unsigned int value, unsigned int base) :
93
- m_hash(Hash::toHash(value, base)) {
96
+ template <class T >
97
+ inline THash<T>::THash(T value, T base) :
98
+ m_hash (THash::toHash(value, base)) {
94
99
// empty
95
100
}
96
101
97
- inline Hash::~Hash () {
98
- // empty
99
- }
100
-
101
- inline unsigned int Hash::toHash (const char *buffer, unsigned int base) {
102
- unsigned int hash (0 );
102
+ template <class T >
103
+ inline T THash<T>::toHash(const char *buffer, T base) {
104
+ T hash = 0 ;
103
105
if (nullptr == buffer) {
104
106
return hash;
105
107
}
@@ -113,12 +115,14 @@ inline unsigned int Hash::toHash(const char *buffer, unsigned int base) {
113
115
return hash;
114
116
}
115
117
116
- inline unsigned int Hash::toHash (unsigned int value, unsigned int base) {
117
- const unsigned int hash (value % base);
118
+ template <class T >
119
+ inline T THash<T>::toHash(T value, T base) {
120
+ const T hash = value % base;
118
121
return hash;
119
122
}
120
123
121
- inline unsigned int Hash::hashValue () const {
124
+ template <class T >
125
+ inline T THash<T>::hashValue() const {
122
126
return m_hash;
123
127
}
124
128
0 commit comments