12
12
// the low end of the hashtable otherwise. LKRhash applies this internally
13
13
// to all hash signatures for exactly this reason.
14
14
15
- inline DWORD
15
+ inline constexpr DWORD
16
16
HashScramble (DWORD dwHash)
17
17
{
18
18
// Here are 10 primes slightly greater than 10^9
19
19
// 1000000007, 1000000009, 1000000021, 1000000033, 1000000087,
20
20
// 1000000093, 1000000097, 1000000103, 1000000123, 1000000181.
21
21
22
22
// default value for "scrambling constant"
23
- const DWORD RANDOM_CONSTANT = 314159269UL ;
23
+ constexpr DWORD RANDOM_CONSTANT = 314159269UL ;
24
24
// large prime number, also used for scrambling
25
- const DWORD RANDOM_PRIME = 1000000007UL ;
25
+ constexpr DWORD RANDOM_PRIME = 1000000007UL ;
26
26
27
27
return (RANDOM_CONSTANT * dwHash) % RANDOM_PRIME ;
28
28
}
29
29
30
30
31
31
// Faster scrambling function suggested by Eric Jacobsen
32
32
33
- inline DWORD
33
+ inline DWORD constexpr
34
34
HashRandomizeBits (DWORD dw)
35
35
{
36
36
return (((dw * 1103515245 + 12345 ) >> 16 )
@@ -39,7 +39,7 @@ HashRandomizeBits(DWORD dw)
39
39
40
40
41
41
// Small prime number used as a multiplier in the supplied hash functions
42
- const DWORD HASH_MULTIPLIER = 101 ;
42
+ constexpr DWORD HASH_MULTIPLIER = 101 ;
43
43
44
44
#undef HASH_SHIFT_MULTIPLY
45
45
@@ -273,51 +273,51 @@ Hash(
273
273
}
274
274
275
275
// Identity hash functions: scalar values map to themselves
276
- inline DWORD Hash (char c )
276
+ inline constexpr DWORD Hash (char c)
277
277
{ return c; }
278
278
279
- inline DWORD Hash (unsigned char uc )
279
+ inline constexpr DWORD Hash (unsigned char uc)
280
280
{ return uc; }
281
281
282
- inline DWORD Hash (signed char sc )
282
+ inline constexpr DWORD Hash (signed char sc)
283
283
{ return sc; }
284
284
285
- inline DWORD Hash (short sh )
285
+ inline constexpr DWORD Hash (short sh)
286
286
{ return sh; }
287
287
288
- inline DWORD Hash (unsigned short ush )
288
+ inline constexpr DWORD Hash (unsigned short ush)
289
289
{ return ush; }
290
290
291
- inline DWORD Hash (int i )
291
+ inline constexpr DWORD Hash (int i)
292
292
{ return i; }
293
293
294
- inline DWORD Hash (unsigned int u )
294
+ inline constexpr DWORD Hash (unsigned int u)
295
295
{ return u; }
296
296
297
- inline DWORD Hash (long l )
297
+ inline constexpr DWORD Hash (long l)
298
298
{ return l; }
299
299
300
- inline DWORD Hash (unsigned long ul )
300
+ inline constexpr DWORD Hash (unsigned long ul)
301
301
{ return ul; }
302
302
303
- inline DWORD Hash (float f )
303
+ inline constexpr DWORD Hash (float f)
304
304
{
305
305
// be careful of rounding errors when computing keys
306
306
union {
307
307
float f;
308
308
DWORD dw;
309
- } u ;
309
+ } u{} ;
310
310
u.f = f;
311
311
return u.dw ;
312
312
}
313
313
314
- inline DWORD Hash (double dbl )
314
+ inline constexpr DWORD Hash (double dbl)
315
315
{
316
316
// be careful of rounding errors when computing keys
317
317
union {
318
318
double dbl;
319
319
DWORD dw[2 ];
320
- } u ;
320
+ } u{} ;
321
321
u.dbl = dbl;
322
322
return u.dw [0 ] * HASH_MULTIPLIER + u.dw [1 ];
323
323
}
0 commit comments