|
6 | 6 |
|
7 | 7 | namespace REL |
8 | 8 | { |
9 | | - template <class T> |
10 | | - class Offset2ID |
| 9 | + class Offset2ID : |
| 10 | + public REX::Singleton<Offset2ID> |
11 | 11 | { |
12 | 12 | public: |
13 | | - using value_type = T; |
| 13 | + using value_type = IDDB::MAPPING; |
14 | 14 | using container_type = std::vector<value_type>; |
15 | 15 | using size_type = typename container_type::size_type; |
16 | 16 | using const_iterator = typename container_type::const_iterator; |
17 | 17 | using const_reverse_iterator = typename container_type::const_reverse_iterator; |
18 | 18 |
|
19 | | - template <class ExecutionPolicy> |
20 | | - explicit Offset2ID(ExecutionPolicy&& a_policy) // NOLINT(bugprone-forwarding-reference-overload) |
21 | | - requires(std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>) |
| 19 | + void load(std::span<IDDB::MAPPING> a_span) |
22 | 20 | { |
23 | 21 | const auto iddb = IDDB::GetSingleton(); |
24 | | - const auto id2offset = iddb->get_id2offset<T>(); |
| 22 | + const auto id2offset = iddb->get_id2offset<IDDB::MAPPING>(); |
25 | 23 | _offset2id.reserve(id2offset.size()); |
26 | 24 | _offset2id.insert(_offset2id.begin(), id2offset.begin(), id2offset.end()); |
27 | | - std::sort(a_policy, _offset2id.begin(), _offset2id.end(), [](auto&& a_lhs, auto&& a_rhs) { |
| 25 | + std::sort(std::execution::sequenced_policy{}, _offset2id.begin(), _offset2id.end(), [](auto&& a_lhs, auto&& a_rhs) { |
28 | 26 | return a_lhs.offset < a_rhs.offset; |
29 | 27 | }); |
30 | 28 | } |
31 | 29 |
|
32 | | - Offset2ID() : |
33 | | - Offset2ID(std::execution::sequenced_policy{}) |
34 | | - {} |
| 30 | + void load(std::span<std::uint32_t> a_span) |
| 31 | + { |
| 32 | + const auto iddb = IDDB::GetSingleton(); |
| 33 | + const auto id2offset = iddb->get_id2offset<std::uint32_t>(); |
| 34 | + _offset2id.reserve(id2offset.size()); |
| 35 | + |
| 36 | + std::uint64_t id{ 0 }; |
| 37 | + for (auto offset : id2offset) { |
| 38 | + value_type map{ id++, offset }; |
| 39 | + _offset2id.emplace_back(map); |
| 40 | + } |
| 41 | + std::sort(std::execution::sequenced_policy{}, _offset2id.begin(), _offset2id.end(), [](auto&& a_lhs, auto&& a_rhs) { |
| 42 | + return a_lhs.offset < a_rhs.offset; |
| 43 | + }); |
| 44 | + } |
35 | 45 |
|
36 | 46 | [[nodiscard]] std::uint64_t operator()(std::size_t a_offset) const |
37 | 47 | { |
@@ -74,9 +84,6 @@ namespace REL |
74 | 84 |
|
75 | 85 | [[nodiscard]] size_type size() const noexcept { return _offset2id.size(); } |
76 | 86 |
|
77 | | - protected: |
78 | | - friend class IDDB; |
79 | | - |
80 | 87 | private: |
81 | 88 | container_type _offset2id; |
82 | 89 | }; |
|
0 commit comments