Skip to main content

LinearLookupStrategy Class

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

Declaration

class helios::core::ecs::LinearLookupStrategy { ... }

Public Constructors Index

LinearLookupStrategy (const size_t capacity)

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

Public Member Functions Index

boolremove (const StrongId_t id)

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

booladd (const StrongId_t id)

Registers a strong ID. More...

boolhas (const StrongId_t id) const

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

Private Member Attributes Index

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.

See Also

EntityRegistry

See Also

HashedLookupStrategy

Definition at line 29 of file LinearLookupStrategy.ixx.

Public Constructors

LinearLookupStrategy()

helios::core::ecs::LinearLookupStrategy::LinearLookupStrategy (const size_t capacity)
inline explicit

Constructs a strategy with pre-allocated capacity.

Parameters
capacity

The initial capacity to reserve.

Definition at line 43 of file LinearLookupStrategy.ixx.

43 explicit LinearLookupStrategy(const size_t capacity) {
44 strongIds_.reserve(capacity);
45 };

Public Member Functions

add()

bool helios::core::ecs::LinearLookupStrategy::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 82 of file LinearLookupStrategy.ixx.

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

Reference has.

has()

bool helios::core::ecs::LinearLookupStrategy::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 97 of file LinearLookupStrategy.ixx.

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

Referenced by add.

remove()

bool helios::core::ecs::LinearLookupStrategy::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 54 of file LinearLookupStrategy.ixx.

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

Private Member Attributes

strongIds_

std::vector<StrongId_t> helios::core::ecs::LinearLookupStrategy::strongIds_

Vector of registered strong IDs.

Definition at line 34 of file LinearLookupStrategy.ixx.

34 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.