The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
QuasiRandom.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11// Include files
12#include <string>
13
14// local
16
17namespace Gaudi {
18 namespace Utils {
19 namespace QuasiRandom {
20
21 uint32_t mix( uint32_t state ) {
22 state += ( state << 16 );
23 state ^= ( state >> 13 );
24 state += ( state << 4 );
25 state ^= ( state >> 7 );
26 state += ( state << 10 );
27 state ^= ( state >> 5 );
28 state += ( state << 8 );
29 state ^= ( state >> 16 );
30 return state;
31 }
32
33 uint32_t mix32( uint32_t state, uint32_t extra ) { return mix( state + extra ); }
34
35 uint32_t mix64( uint32_t state, uint64_t extra ) {
36 typedef boost::low_bits_mask_t<32> mask_t;
37 state = mix32( state, uint32_t( extra & mask_t::sig_bits_fast ) );
38 return mix32( state, uint32_t( ( extra >> 32 ) & mask_t::sig_bits_fast ) );
39 }
40
41 uint32_t mixString( uint32_t state, const std::string& extra ) {
42 // prefix name with ' ' until the size is a multiple of 4.
43 std::string s = std::string( ( 4 - extra.size() % 4 ) % 4, ' ' ) + extra;
44 for ( size_t i = 0; i < s.size() / 4; ++i ) {
45 // FIXME: this might do something different on big endian vs. small endian machines...
46 uint32_t x = uint32_t( s[i * 4] ) | uint32_t( s[i * 4 + 1] ) << 8 | uint32_t( s[i * 4 + 2] ) << 16 |
47 uint32_t( s[i * 4 + 3] ) << 24;
48 state = mix32( state, x );
49 }
50 return state;
51 }
52 } // namespace QuasiRandom
53 } // namespace Utils
54} // namespace Gaudi
uint32_t mix64(uint32_t state, uint64_t extra)
mix some 'extra' entropy into 'state' and return result
uint32_t mix32(uint32_t state, uint32_t extra)
mix some 'extra' entropy into 'state' and return result
uint32_t mixString(uint32_t state, const std::string &extra)
mix some 'extra' entropy into 'state' and return result
uint32_t mix(uint32_t state)
Create a hash with a large avalanche effect from a 32 bit integer.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1