diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:25 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:25 +0300 |
commit | 344ea37b4a345701ab0e67de2266a1c1bd7baf2d (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/random | |
parent | 706b83ed7de5a473436620367af31fc0ceecde07 (diff) | |
download | ydb-344ea37b4a345701ab0e67de2266a1c1bd7baf2d.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 2 of 2.
Diffstat (limited to 'util/random')
-rw-r--r-- | util/random/common_ops.h | 20 | ||||
-rw-r--r-- | util/random/common_ops_ut.cpp | 2 | ||||
-rw-r--r-- | util/random/easy.h | 2 | ||||
-rw-r--r-- | util/random/fast.cpp | 6 | ||||
-rw-r--r-- | util/random/fast.h | 12 | ||||
-rw-r--r-- | util/random/lcg_engine.cpp | 6 | ||||
-rw-r--r-- | util/random/lcg_engine.h | 18 | ||||
-rw-r--r-- | util/random/mersenne.h | 6 | ||||
-rw-r--r-- | util/random/mersenne32.cpp | 6 | ||||
-rw-r--r-- | util/random/mersenne32.h | 12 | ||||
-rw-r--r-- | util/random/mersenne64.cpp | 6 | ||||
-rw-r--r-- | util/random/mersenne64.h | 10 | ||||
-rw-r--r-- | util/random/normal_ut.cpp | 2 | ||||
-rw-r--r-- | util/random/shuffle_ut.cpp | 4 |
14 files changed, 56 insertions, 56 deletions
diff --git a/util/random/common_ops.h b/util/random/common_ops.h index a88a5aa150..602eede351 100644 --- a/util/random/common_ops.h +++ b/util/random/common_ops.h @@ -33,7 +33,7 @@ namespace NPrivate { } template <class T> - static inline ui64 ToRand64(T&& rng, ui32 x) noexcept { + static inline ui64 ToRand64(T&& rng, ui32 x) noexcept { return ((ui64)x) | (((ui64)rng.GenRand()) << 32); } @@ -65,7 +65,7 @@ struct TCommonRNG { using TResult = TRandType; using result_type = TRandType; - inline T& Engine() noexcept { + inline T& Engine() noexcept { return static_cast<T&>(*this); } @@ -81,42 +81,42 @@ struct TCommonRNG { } /* generates uniformly distributed random number on [0, t) interval */ - inline TResult Uniform(TResult t) noexcept { + inline TResult Uniform(TResult t) noexcept { return ::NPrivate::GenUniform(t, Engine()); } /* generates uniformly distributed random number on [f, t) interval */ - inline TResult Uniform(TResult f, TResult t) noexcept { + inline TResult Uniform(TResult f, TResult t) noexcept { return f + Uniform(t - f); } /* generates 64-bit random number for current(may be 32 bit) rng */ - inline ui64 GenRand64() noexcept { + inline ui64 GenRand64() noexcept { return ::NPrivate::ToRand64(Engine(), Engine().GenRand()); } /* generates a random number on [0, 1]-real-interval */ - inline double GenRandReal1() noexcept { + inline double GenRandReal1() noexcept { return ::NPrivate::ToRandReal1(Engine().GenRand()); } /* generates a random number on [0, 1)-real-interval */ - inline double GenRandReal2() noexcept { + inline double GenRandReal2() noexcept { return ::NPrivate::ToRandReal2(Engine().GenRand()); } /* generates a random number on (0, 1)-real-interval */ - inline double GenRandReal3() noexcept { + inline double GenRandReal3() noexcept { return ::NPrivate::ToRandReal3(Engine().GenRand()); } /* generates a random number on [0, 1) with 53-bit resolution */ - inline double GenRandReal4() noexcept { + inline double GenRandReal4() noexcept { return ::NPrivate::ToRandReal4(Engine().GenRand64()); } //compatibility stuff - inline TResult operator()() noexcept { + inline TResult operator()() noexcept { return Engine().GenRand(); } diff --git a/util/random/common_ops_ut.cpp b/util/random/common_ops_ut.cpp index f88a58d847..905912bd1e 100644 --- a/util/random/common_ops_ut.cpp +++ b/util/random/common_ops_ut.cpp @@ -10,7 +10,7 @@ Y_UNIT_TEST_SUITE(TestCommonRNG) { template <class T> struct TRng: public TCommonRNG<T, TRng<T>> { - inline T GenRand() noexcept { + inline T GenRand() noexcept { return IntHash(C_++); } diff --git a/util/random/easy.h b/util/random/easy.h index 275d160710..fd5b826fbe 100644 --- a/util/random/easy.h +++ b/util/random/easy.h @@ -42,6 +42,6 @@ namespace NPrivate { }; } -static inline ::NPrivate::TRandom Random() noexcept { +static inline ::NPrivate::TRandom Random() noexcept { return {}; } diff --git a/util/random/fast.cpp b/util/random/fast.cpp index 43cc1f53b6..2f98dfc5d3 100644 --- a/util/random/fast.cpp +++ b/util/random/fast.cpp @@ -2,7 +2,7 @@ #include <util/stream/input.h> -static inline ui32 FixSeq(ui32 seq1, ui32 seq2) noexcept { +static inline ui32 FixSeq(ui32 seq1, ui32 seq2) noexcept { const ui32 mask = (~(ui32)(0)) >> 1; if ((seq1 & mask) == (seq2 & mask)) { @@ -12,13 +12,13 @@ static inline ui32 FixSeq(ui32 seq1, ui32 seq2) noexcept { return seq2; } -TFastRng64::TFastRng64(ui64 seed1, ui32 seq1, ui64 seed2, ui32 seq2) noexcept +TFastRng64::TFastRng64(ui64 seed1, ui32 seq1, ui64 seed2, ui32 seq2) noexcept : R1_(seed1, seq1) , R2_(seed2, FixSeq(seq1, seq2)) { } -TFastRng64::TArgs::TArgs(ui64 seed) noexcept { +TFastRng64::TArgs::TArgs(ui64 seed) noexcept { TReallyFastRng32 rng(seed); Seed1 = rng.GenRand64(); diff --git a/util/random/fast.h b/util/random/fast.h index 8aad8a489d..ddc5711641 100644 --- a/util/random/fast.h +++ b/util/random/fast.h @@ -9,7 +9,7 @@ // based on http://www.pcg-random.org/. See T*FastRng* family below. struct TPCGMixer { - static inline ui32 Mix(ui64 x) noexcept { + static inline ui32 Mix(ui64 x) noexcept { const ui32 xorshifted = ((x >> 18u) ^ x) >> 27u; const ui32 rot = x >> 59u; @@ -44,7 +44,7 @@ struct TReallyFastRng32: public TCommonRNG<ui32, TReallyFastRng32>, public TReal class TFastRng64: public TCommonRNG<ui64, TFastRng64> { public: struct TArgs { - TArgs(ui64 seed) noexcept; + TArgs(ui64 seed) noexcept; TArgs(IInputStream& entropy); ui64 Seed1; @@ -53,26 +53,26 @@ public: ui32 Seq2; }; - TFastRng64(ui64 seed1, ui32 seq1, ui64 seed2, ui32 seq2) noexcept; + TFastRng64(ui64 seed1, ui32 seq1, ui64 seed2, ui32 seq2) noexcept; /* * simplify constructions like * TFastRng64 rng(17); * TFastRng64 rng(Seek()); //from any IInputStream */ - inline TFastRng64(const TArgs& args) noexcept + inline TFastRng64(const TArgs& args) noexcept : TFastRng64(args.Seed1, args.Seq1, args.Seed2, args.Seq2) { } - inline ui64 GenRand() noexcept { + inline ui64 GenRand() noexcept { const ui64 x = R1_.GenRand(); const ui64 y = R2_.GenRand(); return (x << 32) | y; } - inline void Advance(ui64 delta) noexcept { + inline void Advance(ui64 delta) noexcept { R1_.Advance(delta); R2_.Advance(delta); } diff --git a/util/random/lcg_engine.cpp b/util/random/lcg_engine.cpp index 01075e388a..e1469104fa 100644 --- a/util/random/lcg_engine.cpp +++ b/util/random/lcg_engine.cpp @@ -2,7 +2,7 @@ namespace NPrivate { template <typename T> - T LcgAdvance(T seed, T lcgBase, T lcgAddend, T delta) noexcept { + T LcgAdvance(T seed, T lcgBase, T lcgAddend, T delta) noexcept { // seed[n+1] = A * seed[n] + B, A = lcgBase, B = lcgAddend // seed[n] = A**n * seed[0] + (A**n - 1) / (A - 1) * B // (initial value of n) = m * 2**k + (lower bits of n) @@ -25,6 +25,6 @@ namespace NPrivate { return seed * apow + lcgAddend * adiv; } - template ui32 LcgAdvance<ui32>(ui32, ui32, ui32, ui32) noexcept; - template ui64 LcgAdvance<ui64>(ui64, ui64, ui64, ui64) noexcept; + template ui32 LcgAdvance<ui32>(ui32, ui32, ui32, ui32) noexcept; + template ui64 LcgAdvance<ui64>(ui64, ui64, ui64, ui64) noexcept; } diff --git a/util/random/lcg_engine.h b/util/random/lcg_engine.h index a73d7aa7fc..08cc93c845 100644 --- a/util/random/lcg_engine.h +++ b/util/random/lcg_engine.h @@ -8,7 +8,7 @@ namespace NPrivate { template <typename T> - T LcgAdvance(T seed, T lcgBase, T lcgAddend, T delta) noexcept; + T LcgAdvance(T seed, T lcgBase, T lcgAddend, T delta) noexcept; }; template <typename T, T A, T C> @@ -19,23 +19,23 @@ struct TFastLcgIterator { return x * A + C; } - static inline T IterateMultiple(T x, T delta) noexcept { + static inline T IterateMultiple(T x, T delta) noexcept { return ::NPrivate::LcgAdvance(x, A, C, delta); } }; template <typename T, T A> struct TLcgIterator { - inline TLcgIterator(T seq) noexcept + inline TLcgIterator(T seq) noexcept : C((seq << 1u) | (T)1) // C must be odd { } - inline T Iterate(T x) noexcept { + inline T Iterate(T x) noexcept { return x * A + C; } - inline T IterateMultiple(T x, T delta) noexcept { + inline T IterateMultiple(T x, T delta) noexcept { return ::NPrivate::LcgAdvance(x, A, C, delta); } @@ -44,8 +44,8 @@ struct TLcgIterator { template <class TIterator, class TMixer> struct TLcgRngBase: public TIterator, public TMixer { - using TStateType = decltype(std::declval<TIterator>().Iterate(0)); - using TResultType = decltype(std::declval<TMixer>().Mix(TStateType())); + using TStateType = decltype(std::declval<TIterator>().Iterate(0)); + using TResultType = decltype(std::declval<TMixer>().Mix(TStateType())); template <typename... Args> inline TLcgRngBase(TStateType seed, Args&&... args) @@ -54,11 +54,11 @@ struct TLcgRngBase: public TIterator, public TMixer { { } - inline TResultType GenRand() noexcept { + inline TResultType GenRand() noexcept { return this->Mix(X = this->Iterate(X)); } - inline void Advance(TStateType delta) noexcept { + inline void Advance(TStateType delta) noexcept { X = this->IterateMultiple(X, delta); } diff --git a/util/random/mersenne.h b/util/random/mersenne.h index 9e94c6e2f9..b2044604ac 100644 --- a/util/random/mersenne.h +++ b/util/random/mersenne.h @@ -26,10 +26,10 @@ class TMersenne: public TCommonRNG<T, TMersenne<T>>, public ::NPrivate::TMersenn public: using TBase = typename ::NPrivate::TMersenneTraits<T>::TImpl; - inline TMersenne() noexcept { + inline TMersenne() noexcept { } - inline TMersenne(T seed) noexcept + inline TMersenne(T seed) noexcept : TBase(seed) { } @@ -39,7 +39,7 @@ public: { } - inline TMersenne(const T* keys, size_t len) noexcept + inline TMersenne(const T* keys, size_t len) noexcept : TBase(keys, len) { } diff --git a/util/random/mersenne32.cpp b/util/random/mersenne32.cpp index cc708702cc..cb8aad8b03 100644 --- a/util/random/mersenne32.cpp +++ b/util/random/mersenne32.cpp @@ -10,7 +10,7 @@ using namespace NPrivate; #define UPPER_MASK 0x80000000UL #define LOWER_MASK 0x7fffffffUL -void TMersenne32::InitGenRand(ui32 s) noexcept { +void TMersenne32::InitGenRand(ui32 s) noexcept { mt[0] = s; for (mti = 1; mti < N; ++mti) { @@ -18,7 +18,7 @@ void TMersenne32::InitGenRand(ui32 s) noexcept { } } -void TMersenne32::InitByArray(const ui32 init_key[], size_t key_length) noexcept { +void TMersenne32::InitByArray(const ui32 init_key[], size_t key_length) noexcept { InitGenRand(19650218UL); ui32 i = 1; @@ -55,7 +55,7 @@ void TMersenne32::InitByArray(const ui32 init_key[], size_t key_length) noexcept mt[0] = 0x80000000UL; } -void TMersenne32::InitNext() noexcept { +void TMersenne32::InitNext() noexcept { int kk; ui32 y; ui32 mag01[2] = { diff --git a/util/random/mersenne32.h b/util/random/mersenne32.h index 5192f4b9d6..861f3a3d38 100644 --- a/util/random/mersenne32.h +++ b/util/random/mersenne32.h @@ -9,13 +9,13 @@ namespace NPrivate { static constexpr int N = 624; public: - inline TMersenne32(ui32 s = 19650218UL) noexcept + inline TMersenne32(ui32 s = 19650218UL) noexcept : mti(N + 1) { InitGenRand(s); } - inline TMersenne32(const ui32* init_key, size_t key_length) noexcept + inline TMersenne32(const ui32* init_key, size_t key_length) noexcept : mti(N + 1) { InitByArray(init_key, key_length); @@ -23,7 +23,7 @@ namespace NPrivate { TMersenne32(IInputStream& input); - inline ui32 GenRand() noexcept { + inline ui32 GenRand() noexcept { if (mti >= N) { InitNext(); } @@ -39,9 +39,9 @@ namespace NPrivate { } private: - void InitNext() noexcept; - void InitGenRand(ui32 s) noexcept; - void InitByArray(const ui32* init_key, size_t key_length) noexcept; + void InitNext() noexcept; + void InitGenRand(ui32 s) noexcept; + void InitByArray(const ui32* init_key, size_t key_length) noexcept; private: ui32 mt[N]; diff --git a/util/random/mersenne64.cpp b/util/random/mersenne64.cpp index c74d726020..4ede2c6dca 100644 --- a/util/random/mersenne64.cpp +++ b/util/random/mersenne64.cpp @@ -10,7 +10,7 @@ using namespace NPrivate; -void TMersenne64::InitGenRand(ui64 seed) noexcept { +void TMersenne64::InitGenRand(ui64 seed) noexcept { mt[0] = seed; for (mti = 1; mti < NN; ++mti) { @@ -18,7 +18,7 @@ void TMersenne64::InitGenRand(ui64 seed) noexcept { } } -void TMersenne64::InitByArray(const ui64* init_key, size_t key_length) noexcept { +void TMersenne64::InitByArray(const ui64* init_key, size_t key_length) noexcept { ui64 i = 1; ui64 j = 0; ui64 k; @@ -57,7 +57,7 @@ void TMersenne64::InitByArray(const ui64* init_key, size_t key_length) noexcept mt[0] = ULL(1) << 63; } -void TMersenne64::InitNext() noexcept { +void TMersenne64::InitNext() noexcept { int i; ui64 x; ui64 mag01[2] = { diff --git a/util/random/mersenne64.h b/util/random/mersenne64.h index b4b03895d2..12ca43b6af 100644 --- a/util/random/mersenne64.h +++ b/util/random/mersenne64.h @@ -15,7 +15,7 @@ namespace NPrivate { InitGenRand(s); } - inline TMersenne64(const ui64* keys, size_t len) noexcept + inline TMersenne64(const ui64* keys, size_t len) noexcept : mti(NN + 1) { InitByArray(keys, len); @@ -23,7 +23,7 @@ namespace NPrivate { TMersenne64(IInputStream& input); - inline ui64 GenRand() noexcept { + inline ui64 GenRand() noexcept { if (mti >= NN) { InitNext(); } @@ -39,9 +39,9 @@ namespace NPrivate { } private: - void InitNext() noexcept; - void InitGenRand(ui64 seed) noexcept; - void InitByArray(const ui64* init_key, size_t key_length) noexcept; + void InitNext() noexcept; + void InitGenRand(ui64 seed) noexcept; + void InitByArray(const ui64* init_key, size_t key_length) noexcept; private: ui64 mt[NN]; diff --git a/util/random/normal_ut.cpp b/util/random/normal_ut.cpp index 77e8050d24..42b6cc4ba2 100644 --- a/util/random/normal_ut.cpp +++ b/util/random/normal_ut.cpp @@ -16,7 +16,7 @@ Y_UNIT_TEST_SUITE(TestNormalDistribution) { template <class T> static void TestMD(std::function<T()> f, T m, T d) { - TVector<T> v; + TVector<T> v; v.reserve(20000); diff --git a/util/random/shuffle_ut.cpp b/util/random/shuffle_ut.cpp index 45f9baa262..87cbae94c0 100644 --- a/util/random/shuffle_ut.cpp +++ b/util/random/shuffle_ut.cpp @@ -9,7 +9,7 @@ Y_UNIT_TEST_SUITE(TRandUtilsTest) { template <typename... A> static void TestRange(A&&... args) { - TString s0, s1; + TString s0, s1; ShuffleRange(s1, args...); s1 = "0"; ShuffleRange(s1, args...); @@ -23,7 +23,7 @@ Y_UNIT_TEST_SUITE(TRandUtilsTest) { template <typename... A> static void TestIter(A&&... args) { - TString s0, s1; + TString s0, s1; auto f = [&]() { auto b = s1.begin(); |