The Gaudi Framework
master (9cc87df9)
Toggle main menu visibility
Loading...
Searching...
No Matches
QuasiRandom.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 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
12
#include <
GaudiUtils/QuasiRandom.h
>
13
14
#include <
cstdint
>
15
#include <
string
>
16
17
namespace
Gaudi::Utils::QuasiRandom
{
18
std::uint32_t
mix
( std::uint32_t state ) {
19
state += ( state << 16 );
20
state ^= ( state >> 13 );
21
state += ( state << 4 );
22
state ^= ( state >> 7 );
23
state += ( state << 10 );
24
state ^= ( state >> 5 );
25
state += ( state << 8 );
26
state ^= ( state >> 16 );
27
return
state;
28
}
29
30
std::uint32_t
mix32
( std::uint32_t state, std::uint32_t extra ) {
return
mix
( state + extra ); }
31
32
std::uint32_t
mix64
( std::uint32_t state, uint64_t extra ) {
33
state =
mix32
( state, std::uint32_t( extra ) );
34
return
mix32
( state, std::uint32_t( ( extra >> 32 ) ) );
35
}
36
37
std::uint32_t
mixString
( std::uint32_t state,
const
std::string& extra ) {
38
// prefix name with ' ' until the size is a multiple of 4.
39
std::string s =
std::string
( ( 4 - extra.
size
() % 4 ) % 4,
' '
) + extra;
40
for
( std::size_t i = 0; i < s.size() / 4; ++i ) {
41
// FIXME: this might do something different on big endian vs. small endian machines...
42
std::uint32_t x = std::uint32_t( s[i * 4] ) | std::uint32_t( s[i * 4 + 1] ) << 8 |
43
std::uint32_t( s[i * 4 + 2] ) << 16 | std::uint32_t( s[i * 4 + 3] ) << 24;
44
state =
mix32
( state, x );
45
}
46
return
state;
47
}
48
}
// namespace Gaudi::Utils::QuasiRandom
QuasiRandom.h
string
cstdint
std::string
basic_string< char > string
std::basic_string::size
size_type size() const noexcept
Gaudi::Utils::QuasiRandom
Create a hash with a large avalanche effect from 32 or 64 bit integers or a string.
Definition
QuasiRandom.h:33
Gaudi::Utils::QuasiRandom::mix64
std::uint32_t mix64(std::uint32_t state, uint64_t extra)
mix some 'extra' entropy into 'state' and return result
Definition
QuasiRandom.cpp:32
Gaudi::Utils::QuasiRandom::mix
std::uint32_t mix(std::uint32_t state)
Create a hash with a large avalanche effect from a 32 bit integer.
Definition
QuasiRandom.cpp:18
Gaudi::Utils::QuasiRandom::mixString
std::uint32_t mixString(std::uint32_t state, const std::string &extra)
mix some 'extra' entropy into 'state' and return result
Definition
QuasiRandom.cpp:37
Gaudi::Utils::QuasiRandom::mix32
std::uint32_t mix32(std::uint32_t state, std::uint32_t extra)
mix some 'extra' entropy into 'state' and return result
Definition
QuasiRandom.cpp:30
GaudiUtils
src
Lib
QuasiRandom.cpp
Generated on
for The Gaudi Framework by
1.18.0