Skip to main content

LinearLookupStrategy Class Template

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

Declaration

template <size_t TCapacity> class helios::ecs::strategies::LinearLookupStrategy<TCapacity> { ... }

Public Constructors Index

template <size_t TCapacity>
LinearLookupStrategy (const size_t capacity=TCapacity)

Constructs a strategy with pre-allocated capacity. More...

Public Member Functions Index

template <size_t TCapacity>
boolremove (const StrongId_t id)

Removes a strong ID using swap-and-pop. More...

template <size_t TCapacity>
booladd (const StrongId_t id)

Registers a strong ID. More...

template <size_t TCapacity>
boolhas (const StrongId_t id) const

Checks whether a strong ID is registered. More...

Private Member Attributes Index

template <size_t TCapacity>
std::vector< StrongId_t >strongIds_

Vector of registered strong IDs. More...

Description

Lookup strategy using a flat vector with linear scan.

`LinearLookupStrategy` stores strong IDs in a contiguous vector and performs linear scans for membership tests. Swap-and-pop is used for O(1) removal. Suitable for small registries where hash overhead is undesirable.

Template Parameters
TCapacity

Default initial capacity for pre-allocation.

See Also

EntityRegistry

See Also

HashedLookupStrategy

Definition at line 32 of file LinearLookupStrategy.ixx.

Public Constructors

LinearLookupStrategy()

template <size_t TCapacity>
helios::ecs::strategies::LinearLookupStrategy< TCapacity >::LinearLookupStrategy (const size_t capacity=TCapacity)
inline explicit

Constructs a strategy with pre-allocated capacity.

Parameters
capacity

The initial capacity to reserve.

Definition at line 46 of file LinearLookupStrategy.ixx.

46 explicit LinearLookupStrategy(const size_t capacity = TCapacity) {
47 strongIds_.reserve(capacity);
48 };

Public Member Functions

add()

template <size_t TCapacity>
bool helios::ecs::strategies::LinearLookupStrategy< TCapacity >::add (const StrongId_t id)
inline nodiscard

Registers a strong ID.

Parameters
id

The strong ID to add.

Returns

True if inserted, false if already present.

Definition at line 85 of file LinearLookupStrategy.ixx.

85 [[nodiscard]] bool add(const StrongId_t id) {
86 if (has(id)) {
87 return false;
88 }
89 strongIds_.push_back(id);
90 return true;
91 }

Reference helios::ecs::strategies::LinearLookupStrategy< TCapacity >::has.

has()

template <size_t TCapacity>
bool helios::ecs::strategies::LinearLookupStrategy< TCapacity >::has (const StrongId_t id)
inline nodiscard

Checks whether a strong ID is registered.

Parameters
id

The strong ID to test.

Returns

True if the ID is present.

Definition at line 100 of file LinearLookupStrategy.ixx.

100 [[nodiscard]] bool has(const StrongId_t id) const {
101 return std::ranges::find(strongIds_, id) != strongIds_.end();
102 }

Referenced by helios::ecs::strategies::LinearLookupStrategy< TCapacity >::add.

remove()

template <size_t TCapacity>
bool helios::ecs::strategies::LinearLookupStrategy< TCapacity >::remove (const StrongId_t id)
inline nodiscard

Removes a strong ID using swap-and-pop.

Parameters
id

The strong ID to remove.

Returns

True if removed, false if not found.

Definition at line 57 of file LinearLookupStrategy.ixx.

57 [[nodiscard]] bool remove(const StrongId_t id) {
58
59 const auto it = std::ranges::find(strongIds_, id);
60
61 if (it == strongIds_.end()) {
62 return false;
63 }
64
65 if (it == strongIds_.end() - 1) {
66 strongIds_.pop_back();
67 return true;
68 }
69
70 const auto idx = std::distance(strongIds_.begin(), it);
71 const auto tmp = strongIds_.back();
72 strongIds_[idx] = tmp;
73 strongIds_.pop_back();
74
75 return true;
76 }

Private Member Attributes

strongIds_

template <size_t TCapacity>
std::vector<StrongId_t> helios::ecs::strategies::LinearLookupStrategy< TCapacity >::strongIds_

Vector of registered strong IDs.

Definition at line 37 of file LinearLookupStrategy.ixx.

37 std::vector<StrongId_t> strongIds_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.