1212// the low end of the hashtable otherwise. LKRhash applies this internally
1313// to all hash signatures for exactly this reason.
1414
15- inline DWORD
15+ inline constexpr DWORD
1616HashScramble (DWORD dwHash)
1717{
1818 // Here are 10 primes slightly greater than 10^9
1919 // 1000000007, 1000000009, 1000000021, 1000000033, 1000000087,
2020 // 1000000093, 1000000097, 1000000103, 1000000123, 1000000181.
2121
2222 // default value for "scrambling constant"
23- const DWORD RANDOM_CONSTANT = 314159269UL ;
23+ constexpr DWORD RANDOM_CONSTANT = 314159269UL ;
2424 // large prime number, also used for scrambling
25- const DWORD RANDOM_PRIME = 1000000007UL ;
25+ constexpr DWORD RANDOM_PRIME = 1000000007UL ;
2626
2727 return (RANDOM_CONSTANT * dwHash) % RANDOM_PRIME ;
2828}
2929
3030
3131// Faster scrambling function suggested by Eric Jacobsen
3232
33- inline DWORD
33+ inline DWORD constexpr
3434HashRandomizeBits (DWORD dw)
3535{
3636 return (((dw * 1103515245 + 12345 ) >> 16 )
@@ -39,7 +39,7 @@ HashRandomizeBits(DWORD dw)
3939
4040
4141// Small prime number used as a multiplier in the supplied hash functions
42- const DWORD HASH_MULTIPLIER = 101 ;
42+ constexpr DWORD HASH_MULTIPLIER = 101 ;
4343
4444#undef HASH_SHIFT_MULTIPLY
4545
@@ -273,51 +273,51 @@ Hash(
273273}
274274
275275// Identity hash functions: scalar values map to themselves
276- inline DWORD Hash (char c )
276+ inline constexpr DWORD Hash (char c)
277277{ return c; }
278278
279- inline DWORD Hash (unsigned char uc )
279+ inline constexpr DWORD Hash (unsigned char uc)
280280{ return uc; }
281281
282- inline DWORD Hash (signed char sc )
282+ inline constexpr DWORD Hash (signed char sc)
283283{ return sc; }
284284
285- inline DWORD Hash (short sh )
285+ inline constexpr DWORD Hash (short sh)
286286{ return sh; }
287287
288- inline DWORD Hash (unsigned short ush )
288+ inline constexpr DWORD Hash (unsigned short ush)
289289{ return ush; }
290290
291- inline DWORD Hash (int i )
291+ inline constexpr DWORD Hash (int i)
292292{ return i; }
293293
294- inline DWORD Hash (unsigned int u )
294+ inline constexpr DWORD Hash (unsigned int u)
295295{ return u; }
296296
297- inline DWORD Hash (long l )
297+ inline constexpr DWORD Hash (long l)
298298{ return l; }
299299
300- inline DWORD Hash (unsigned long ul )
300+ inline constexpr DWORD Hash (unsigned long ul)
301301{ return ul; }
302302
303- inline DWORD Hash (float f )
303+ inline constexpr DWORD Hash (float f)
304304{
305305 // be careful of rounding errors when computing keys
306306 union {
307307 float f;
308308 DWORD dw;
309- } u ;
309+ } u{} ;
310310 u.f = f;
311311 return u.dw ;
312312}
313313
314- inline DWORD Hash (double dbl )
314+ inline constexpr DWORD Hash (double dbl)
315315{
316316 // be careful of rounding errors when computing keys
317317 union {
318318 double dbl;
319319 DWORD dw[2 ];
320- } u ;
320+ } u{} ;
321321 u.dbl = dbl;
322322 return u.dw [0 ] * HASH_MULTIPLIER + u.dw [1 ];
323323}
0 commit comments