Debian Codegraph @

Source/Core/DiscIO/LaggedFibonacciGenerator.h

raw symbols SCIP
1 // SPDX-License-Identifier: CC0-1.0
2
3 #pragma once
4
5 #include <array>
6 #include <cstddef>
7
8 #include "Common/CommonTypes.h"
9
10 namespace DiscIO
11 {
12 class LaggedFibonacciGenerator
13 {
14 public:
15 static constexpr size_t SEED_SIZE = 17;
16
17 // Reconstructs a seed and writes it to seed_out, then returns the number of bytes which can
18 // be reconstructed using that seed. Can return any number between 0 and size, inclusive.
19 // data - data_offset must be 4-byte aligned.
20 static size_t GetSeed(const u8* data, size_t size, size_t data_offset, u32 seed_out[SEED_SIZE]);
21
22 // SetSeed must be called before using the functions below
23 void SetSeed(const u32 seed[SEED_SIZE]);
24 void SetSeed(const u8 seed[SEED_SIZE * sizeof(u32)]);
25
26 // Outputs a number of bytes and advances the internal state by the same amount.
27 void GetBytes(size_t count, u8* out);
28 u8 GetByte();
29
30 // Advances the internal state like GetBytes, but without outputting data. O(N), like GetBytes.
31 void Forward(size_t count);
32
33 private:
34 static bool GetSeed(const u32* data, size_t size, size_t data_offset,
35 LaggedFibonacciGenerator* lfg, u32 seed_out[SEED_SIZE]);
36
37 void Forward();
38 void Backward(size_t start_word = 0, size_t end_word = LFG_K);
39
40 bool Reinitialize(u32 seed_out[SEED_SIZE]);
41 bool Initialize(bool check_existing_data);
42
43 static constexpr size_t LFG_K = 521;
44 static constexpr size_t LFG_J = 32;
45
46 std::array<u32, LFG_K> m_buffer{};
47
48 size_t m_position_bytes = 0;
49 };
50
51 } // namespace DiscIO