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
25namespace Poco {
26
27
28std::size_t Foundation_API hash(Int8 n);
29std::size_t Foundation_API hash(UInt8 n);
30std::size_t Foundation_API hash(Int16 n);
31std::size_t Foundation_API hash(UInt16 n);
32std::size_t Foundation_API hash(Int32 n);
33std::size_t Foundation_API hash(UInt32 n);
34std::size_t Foundation_API hash(Int64 n);
35std::size_t Foundation_API hash(UInt64 n);
36std::size_t Foundation_API hash(const std::string& str);
37
38
39template <class T>
40struct 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//
54inline std::size_t hash(Int8 n)
55{
56 return static_cast<std::size_t>(n)*2654435761U;
57}
58
59
60inline std::size_t hash(UInt8 n)
61{
62 return static_cast<std::size_t>(n)*2654435761U;
63}
64
65
66inline std::size_t hash(Int16 n)
67{
68 return static_cast<std::size_t>(n)*2654435761U;
69}
70
71
72inline std::size_t hash(UInt16 n)
73{
74 return static_cast<std::size_t>(n)*2654435761U;
75}
76
77
78inline std::size_t hash(Int32 n)
79{
80 return static_cast<std::size_t>(n)*2654435761U;
81}
82
83
84inline std::size_t hash(UInt32 n)
85{
86 return static_cast<std::size_t>(n)*2654435761U;
87}
88
89
90inline std::size_t hash(Int64 n)
91{
92 return static_cast<std::size_t>(n)*2654435761U;
93}
94
95
96inline 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