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