rippled
Loading...
Searching...
No Matches
include
xrpl
beast
xor_shift_engine.h
1
#ifndef BEAST_RANDOM_XOR_SHIFT_ENGINE_H_INCLUDED
2
#define BEAST_RANDOM_XOR_SHIFT_ENGINE_H_INCLUDED
3
4
#include <
cstdint
>
5
#include <
limits
>
6
#include <
stdexcept
>
7
8
namespace
beast
{
9
10
namespace
detail {
11
12
template
<
class
=
void
>
13
class
xor_shift_engine
14
{
15
public
:
16
using
result_type
=
std::uint64_t
;
17
18
xor_shift_engine
(
xor_shift_engine
const
&) =
default
;
19
xor_shift_engine
&
20
operator=
(
xor_shift_engine
const
&) =
default
;
21
22
explicit
xor_shift_engine
(
result_type
val = 1977u);
23
24
void
25
seed
(
result_type
seed
);
26
27
result_type
28
operator()
();
29
30
static
result_type
constexpr
min
()
31
{
32
return
std::numeric_limits<result_type>::min
();
33
}
34
35
static
result_type
constexpr
max
()
36
{
37
return
std::numeric_limits<result_type>::max
();
38
}
39
40
private
:
41
result_type
s_
[2];
42
43
static
result_type
44
murmurhash3
(
result_type
x);
45
};
46
47
template
<
class
_>
48
xor_shift_engine<_>::xor_shift_engine
(
result_type
val)
49
{
50
seed(val);
51
}
52
53
template
<
class
_>
54
void
55
xor_shift_engine<_>::seed
(
result_type
seed)
56
{
57
if
(seed == 0)
58
throw
std::domain_error
(
"invalid seed"
);
59
s_[0] = murmurhash3(seed);
60
s_[1] = murmurhash3(s_[0]);
61
}
62
63
template
<
class
_>
64
auto
65
xor_shift_engine<_>::operator()
() ->
result_type
66
{
67
result_type
s1 = s_[0];
68
result_type
const
s0 = s_[1];
69
s_[0] = s0;
70
s1 ^= s1 << 23;
71
return
(s_[1] = (s1 ^ s0 ^ (s1 >> 17) ^ (s0 >> 26))) + s0;
72
}
73
74
template
<
class
_>
75
auto
76
xor_shift_engine<_>::murmurhash3
(
result_type
x) ->
result_type
77
{
78
x ^= x >> 33;
79
x *= 0xff51afd7ed558ccdULL;
80
x ^= x >> 33;
81
x *= 0xc4ceb9fe1a85ec53ULL;
82
return
x ^= x >> 33;
83
}
84
85
}
// namespace detail
86
95
using
xor_shift_engine
=
detail::xor_shift_engine<>
;
96
97
}
// namespace beast
98
99
#endif
beast::detail::xor_shift_engine
Definition
xor_shift_engine.h:14
beast::detail::xor_shift_engine::min
static result_type constexpr min()
Definition
xor_shift_engine.h:30
beast::detail::xor_shift_engine::operator()
result_type operator()()
Definition
xor_shift_engine.h:65
beast::detail::xor_shift_engine::seed
void seed(result_type seed)
Definition
xor_shift_engine.h:55
beast::detail::xor_shift_engine::max
static result_type constexpr max()
Definition
xor_shift_engine.h:35
beast::detail::xor_shift_engine::operator=
xor_shift_engine & operator=(xor_shift_engine const &)=default
beast::detail::xor_shift_engine::xor_shift_engine
xor_shift_engine(xor_shift_engine const &)=default
beast::detail::xor_shift_engine::murmurhash3
static result_type murmurhash3(result_type x)
Definition
xor_shift_engine.h:76
beast::detail::xor_shift_engine::s_
result_type s_[2]
Definition
xor_shift_engine.h:41
cstdint
std::domain_error
std::uint64_t
limits
std::numeric_limits::max
T max(T... args)
std::numeric_limits::min
T min(T... args)
beast
Definition
base_uint.h:653
stdexcept
Generated by
1.9.8