Skip to main content

DenseRuntimeHandleRegistry Class Template

Maps strong identifiers to dense, contiguous runtime indices. More...

Declaration

template <typename StrongIdentifier, typename RuntimeId> class helios::core::container::DenseRuntimeHandleRegistry<StrongIdentifier, RuntimeId> { ... }

Public Constructors Index

template <typename StrongIdentifier, typename RuntimeId>
DenseRuntimeHandleRegistry (const size_t defaultCapacity=DEFAULT_RUNTIME_HANDLE_REGISTRY_CAPACITY)

Constructs the registry with a reserved capacity. More...

Public Member Functions Index

template <typename StrongIdentifier, typename RuntimeId>
boolhas (StrongIdentifier strongId) const noexcept

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

template <typename StrongIdentifier, typename RuntimeId>
auto runtimeId (StrongIdentifier strongId) const noexcept -> std::optional< RuntimeId >

Returns the runtime index for a registered identifier. More...

template <typename StrongIdentifier, typename RuntimeId>
auto getOrCreate (std::string strId) -> RuntimeHandle< StrongIdentifier, RuntimeId >

Returns an existing handle or creates a new one from a string key. More...

template <typename StrongIdentifier, typename RuntimeId>
auto getOrCreate (const StrongIdentifier strongId) -> RuntimeHandle< StrongIdentifier, RuntimeId >

Returns an existing handle or registers a new entry. More...

Private Member Attributes Index

template <typename StrongIdentifier, typename RuntimeId>
std::vector< StrongId_t >ids_

Dense storage of registered strong-ID values. More...

Description

Maps strong identifiers to dense, contiguous runtime indices.

`DenseRuntimeHandleRegistry` maintains a compact vector of `StrongId` values. The position of each entry in the vector serves as its `RuntimeId`, enabling O(1) access in downstream pools that are indexed by the same `RuntimeId`.

Registration is idempotent: calling `getOrCreate()` with an already registered identifier returns the existing handle without duplication.

## Complexity

  • `has()` / `runtimeId()` — O(n) linear scan.
  • `getOrCreate()` — O(n) lookup + amortised O(1) append on miss.

## Usage

```cpp using MeshHandleRegistry = DenseRuntimeHandleRegistry<MeshId, MeshRuntimeId>;

MeshHandleRegistry registry; auto handle = registry.getOrCreate("player_mesh"); auto runtimeId = handle.runtimeId; // dense index into MeshPool bool exists = registry.has(MeshId{"player_mesh"}); ```

Template Parameters
StrongIdentifier

A `StrongId<Tag>` type used as the stable key.

RuntimeId

An unsigned integer type (typically `uint32_t`) used as the dense index.

See Also

RuntimeHandle

See Also

StrongId

Definition at line 60 of file DenseRuntimeHandleRegistry.ixx.

Public Constructors

DenseRuntimeHandleRegistry()

template <typename StrongIdentifier, typename RuntimeId>
helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::DenseRuntimeHandleRegistry (const size_t defaultCapacity=DEFAULT_RUNTIME_HANDLE_REGISTRY_CAPACITY)
inline explicit

Constructs the registry with a reserved capacity.

Parameters
defaultCapacity

Initial capacity hint for the internal vector.

Definition at line 76 of file DenseRuntimeHandleRegistry.ixx.

76 explicit DenseRuntimeHandleRegistry(const size_t defaultCapacity = DEFAULT_RUNTIME_HANDLE_REGISTRY_CAPACITY) {
77 ids_.reserve(defaultCapacity);
78 }

Public Member Functions

getOrCreate()

template <typename StrongIdentifier, typename RuntimeId>
RuntimeHandle< StrongIdentifier, RuntimeId > helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::getOrCreate (std::string strId)
inline

Returns an existing handle or creates a new one from a string key.

Constructs a `StrongIdentifier` from `strId` and delegates to the `StrongIdentifier` overload.

Parameters
strId

String key that is hashed into a `StrongIdentifier`.

Returns

The existing or newly created handle.

Definition at line 120 of file DenseRuntimeHandleRegistry.ixx.

121 return getOrCreate(StrongIdentifier{std::move(strId)});
122 }

Reference helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::getOrCreate.

Referenced by helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::getOrCreate.

getOrCreate()

template <typename StrongIdentifier, typename RuntimeId>
RuntimeHandle< StrongIdentifier, RuntimeId > helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::getOrCreate (const StrongIdentifier strongId)
inline

Returns an existing handle or registers a new entry.

If the identifier is already registered, the existing handle is returned. Otherwise a new entry is appended and a fresh `RuntimeId` is assigned.

Parameters
strongId

The identifier to register.

Returns

The existing or newly created handle.

Precondition

The registry must not have reached its reserved capacity.

Definition at line 137 of file DenseRuntimeHandleRegistry.ixx.

138 const auto rid = runtimeId(strongId);
139 if (rid.has_value()) {
140 return RuntimeHandle<StrongIdentifier, RuntimeId>(strongId, *rid);
141 }
142
143 assert(ids_.size() < ids_.capacity() && "DenseRuntimeHandleRegistry capacity exceeded");
144 ids_.push_back(strongId.value());
146 strongId,
147 RuntimeId{static_cast<RuntimeId>(ids_.size() - 1)}
148 };
149 }

Reference helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::runtimeId.

has()

template <typename StrongIdentifier, typename RuntimeId>
bool helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::has (StrongIdentifier strongId)
inline nodiscard noexcept

Checks whether a strong identifier is registered.

Parameters
strongId

The identifier to look up.

Returns

True if the identifier is present.

Definition at line 87 of file DenseRuntimeHandleRegistry.ixx.

87 [[nodiscard]] bool has(StrongIdentifier strongId) const noexcept {
88 return std::ranges::find(ids_, strongId.value()) != ids_.end();
89 }

runtimeId()

template <typename StrongIdentifier, typename RuntimeId>
std::optional< RuntimeId > helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::runtimeId (StrongIdentifier strongId)
inline nodiscard noexcept

Returns the runtime index for a registered identifier.

Parameters
strongId

The identifier to look up.

Returns

The associated `RuntimeId`, or `std::nullopt` if not registered.

Definition at line 98 of file DenseRuntimeHandleRegistry.ixx.

98 [[nodiscard]] std::optional<RuntimeId> runtimeId(StrongIdentifier strongId) const noexcept {
99 auto it = std::ranges::find(ids_, strongId.value());
100
101 if (it == ids_.end()) {
102 return std::nullopt;
103 }
104
105 return RuntimeId{static_cast<RuntimeId>(
106 std::distance(ids_.begin(), it))
107 };
108 }

Referenced by helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::getOrCreate.

Private Member Attributes

ids_

template <typename StrongIdentifier, typename RuntimeId>
std::vector<StrongId_t> helios::core::container::DenseRuntimeHandleRegistry< StrongIdentifier, RuntimeId >::ids_

Dense storage of registered strong-ID values.

The index of each entry is its corresponding `RuntimeId`.

Definition at line 67 of file DenseRuntimeHandleRegistry.ixx.

67 std::vector<StrongId_t> ids_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.