1 | // |
---|---|
2 | // Hash.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Hashing |
6 | // Module: Hash |
7 | // |
8 | // Definition of the Hash class. |
9 | // |
10 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_Hash_INCLUDED |
18 | #define Foundation_Hash_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include <cstddef> |
23 | |
24 | |
25 | namespace Poco { |
26 | |
27 | |
28 | std::size_t Foundation_API hash(Int8 n); |
29 | std::size_t Foundation_API hash(UInt8 n); |
30 | std::size_t Foundation_API hash(Int16 n); |
31 | std::size_t Foundation_API hash(UInt16 n); |
32 | std::size_t Foundation_API hash(Int32 n); |
33 | std::size_t Foundation_API hash(UInt32 n); |
34 | std::size_t Foundation_API hash(Int64 n); |
35 | std::size_t Foundation_API hash(UInt64 n); |
36 | std::size_t Foundation_API hash(const std::string& str); |
37 | |
38 | |
39 | template <class T> |
40 | struct Hash |
41 | /// A generic hash function. |
42 | { |
43 | std::size_t operator () (T value) const |
44 | /// Returns the hash for the given value. |
45 | { |
46 | return Poco::hash(value); |
47 | } |
48 | }; |
49 | |
50 | |
51 | // |
52 | // inlines |
53 | // |
54 | inline std::size_t hash(Int8 n) |
55 | { |
56 | return static_cast<std::size_t>(n)*2654435761U; |
57 | } |
58 | |
59 | |
60 | inline std::size_t hash(UInt8 n) |
61 | { |
62 | return static_cast<std::size_t>(n)*2654435761U; |
63 | } |
64 | |
65 | |
66 | inline std::size_t hash(Int16 n) |
67 | { |
68 | return static_cast<std::size_t>(n)*2654435761U; |
69 | } |
70 | |
71 | |
72 | inline std::size_t hash(UInt16 n) |
73 | { |
74 | return static_cast<std::size_t>(n)*2654435761U; |
75 | } |
76 | |
77 | |
78 | inline std::size_t hash(Int32 n) |
79 | { |
80 | return static_cast<std::size_t>(n)*2654435761U; |
81 | } |
82 | |
83 | |
84 | inline std::size_t hash(UInt32 n) |
85 | { |
86 | return static_cast<std::size_t>(n)*2654435761U; |
87 | } |
88 | |
89 | |
90 | inline std::size_t hash(Int64 n) |
91 | { |
92 | return static_cast<std::size_t>(n)*2654435761U; |
93 | } |
94 | |
95 | |
96 | inline std::size_t hash(UInt64 n) |
97 | { |
98 | return static_cast<std::size_t>(n)*2654435761U; |
99 | } |
100 | |
101 | |
102 | } // namespace Poco |
103 | |
104 | |
105 | #endif // Foundation_Hash_INCLUDED |
106 |