Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
HashFunction.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* HashFunction.h (C) 2000-2024 */
9/* */
10/* Hash function. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_HASHFUNCTION_H
13#define ARCANE_UTILS_HASHFUNCTION_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*!
29 * \internal
30 * \brief Functor for a hash function.
31 */
32template <class Type>
34{
35};
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40/*!
41 * \internal
42 * \brief Hashing function for a 32-bit integer.
43
44 Thomas Wang (http://www.cris.com/~Ttwang/tech/inthash.htm)
45*/
46template <>
48{
49 public:
50
51 static constexpr ARCCORE_HOST_DEVICE Int32 hashfunc(Int32 key)
52 {
53 key += ~(key << 15);
54 key ^= (key >> 10);
55 key += (key << 3);
56 key ^= (key >> 6);
57 key += ~(key << 11);
58 key ^= (key >> 16);
59 return key;
60 }
61};
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66/*!
67 * \internal
68 * \brief Hashing function for a 64-bit integer.
69
70 Thomas Wang (http://www.cris.com/~Ttwang/tech/inthash.htm)
71*/
72template <>
74{
75 public:
76
77 static constexpr ARCCORE_HOST_DEVICE Int64 hashfunc(Int64 key)
78 {
79 key += ~(key << 32);
80 key ^= (key >> 22);
81 key += ~(key << 13);
82 key ^= (key >> 8);
83 key += (key << 3);
84 key ^= (key >> 15);
85 key += ~(key << 27);
86 key ^= (key >> 31);
87 return key;
88 }
89};
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94/*!
95 * \internal
96 * \brief Hashing function for a string.
97 */
98template <>
100{
101 public:
102
103 ARCANE_UTILS_EXPORT static Int64 hashfunc(StringView str);
104};
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108/*!
109 * \internal
110 */
111template <typename KeyType>
113{
114 public:
115
116 typedef const KeyType& KeyTypeConstRef;
117 typedef KeyType& KeyTypeRef;
118 typedef KeyType KeyTypeValue;
119 typedef KeyType HashValueType;
120 typedef FalseType Printable;
121
122 public:
123
124 static HashValueType hashFunction(KeyTypeConstRef key);
125};
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
130/*!
131 * \internal
132 * \brief Specialization for Int32
133 */
134template <>
136{
137 public:
138
139 typedef Int32 KeyTypeConstRef;
140 typedef Int32& KeyTypeRef;
141 typedef Int32 KeyTypeValue;
142 typedef TrueType Printable;
143 typedef Int32 HashValueType;
144
145 public:
146
147 static constexpr ARCCORE_HOST_DEVICE Int32 hashFunction(Int32 key)
148 {
150 }
151};
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156/*!
157 * \internal
158 * \brief Specialization for Int64
159 */
160template <>
162{
163 public:
164
165 typedef Int64 KeyTypeConstRef;
166 typedef Int64& KeyTypeRef;
167 typedef Int64 KeyTypeValue;
168 typedef Int64 HashValueType;
169 typedef TrueType Printable;
170
171 public:
172
173 static constexpr ARCCORE_HOST_DEVICE Int64 hashFunction(Int64 key)
174 {
176 }
177};
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182} // End namespace Arcane
183
184/*---------------------------------------------------------------------------*/
185/*---------------------------------------------------------------------------*/
186
187#endif
Arcane configuration file.
View of a UTF-8 character string.
Definition StringView.h:44
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
std::int32_t Int32
Signed integer type of 32 bits.