Skip to main content

LinearLookupStrategy.ixx File

Linear-scan lookup strategy for strong ID collision detection. More...

Included Headers

#include <vector> #include <algorithm> #include <ranges> #include <cstddef> #include <helios.ecs.types.TypeDefs>

Namespaces Index

namespacehelios
namespaceecs
namespacestrategies

Classes Index

classLinearLookupStrategy<TCapacity>

Lookup strategy using a flat vector with linear scan. More...

Description

Linear-scan lookup strategy for strong ID collision detection.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <vector>
8#include <algorithm>
9#include <ranges>
10#include <cstddef>
11
12export module helios.ecs.strategies.LinearLookupStrategy;
13
14import helios.ecs.types.TypeDefs;
15
16using namespace helios::ecs::types;
17export namespace helios::ecs::strategies {
18
32 template<size_t TCapacity>
34
38 std::vector<StrongId_t> strongIds_;
39
40 public:
41
47 explicit LinearLookupStrategy(const size_t capacity = TCapacity) {
48 strongIds_.reserve(capacity);
49 };
50
58 [[nodiscard]] bool remove(const StrongId_t id) {
59
60 const auto it = std::ranges::find(strongIds_, id);
61
62 if (it == strongIds_.end()) {
63 return false;
64 }
65
66 if (it == strongIds_.end() - 1) {
67 strongIds_.pop_back();
68 return true;
69 }
70
71 const auto idx = std::distance(strongIds_.begin(), it);
72 const auto tmp = strongIds_.back();
73 strongIds_[idx] = tmp;
74 strongIds_.pop_back();
75
76 return true;
77 }
78
86 [[nodiscard]] bool add(const StrongId_t id) {
87 if (has(id)) {
88 return false;
89 }
90 strongIds_.push_back(id);
91 return true;
92 }
93
101 [[nodiscard]] bool has(const StrongId_t id) const {
102 return std::ranges::find(strongIds_, id) != strongIds_.end();
103 }
104
105
106 };
107
108
109}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.