Skip to main content

HandleMultiMap Class Template

Stores a one-to-many relation between handle domains. More...

Declaration

template <typename TOneHandle, typename TManyHandle> class helios::engine::core::container::HandleMultiMap<TOneHandle, TManyHandle> { ... }

Public Member Functions Index

template <typename TOneHandle, typename TManyHandle>
ConstIteratorbegin () const noexcept

Returns an iterator to the first dense binding. More...

template <typename TOneHandle, typename TManyHandle>
ConstIteratorend () const noexcept

Returns the end iterator for dense binding iteration. More...

template <typename TOneEntity, typename TManyEntity>
boolbind (TOneEntity oneEntity, TManyEntity manyEntity)

Binds two entities by forwarding their handles. More...

template <typename TOneHandle, typename TManyHandle>
boolbind (const TOneHandle key, const TManyHandle value)

Binds a value handle to a key handle. More...

template <typename TOneHandle, typename TManyHandle>
TOneHandlekey (const TManyHandle value) const noexcept

Returns the owning key handle for a value handle. More...

template <typename TOneHandle, typename TManyHandle>
auto values (const TOneHandle key) const noexcept -> std::span< const TManyHandle >

Returns all value handles bound to a key handle. More...

template <typename TOneHandle, typename TManyHandle>
voidclear ()

Removes all bindings and clears all internal lookup structures. More...

template <typename TOneHandle, typename TManyHandle>
voidreserve (std::size_t keyCapacity, std::size_t valueCapacity)

Reserves capacity for dense key/value storage. More...

Private Member Attributes Index

template <typename TOneHandle, typename TManyHandle>
std::vector< std::vector< TManyHandle > >values_

Forward mapping from key handle id to associated value handles. More...

template <typename TOneHandle, typename TManyHandle>
std::vector< TOneHandle >keys_

Reverse mapping from value handle id to owning key handle. More...

template <typename TOneHandle, typename TManyHandle>
std::vector< TManyHandle >denseValues_

Dense list of all currently bound value handles. More...

Description

Stores a one-to-many relation between handle domains.

The map keeps two dense lookup structures:

  • values_: key handle id -> list of associated value handles.
  • keys_: value handle id -> owning key handle.

The implementation uses entityId as direct index and therefore expects stable id semantics for both handle types.

Template Parameters
TOneHandle

Handle type representing the "one" side.

TManyHandle

Handle type representing the "many" side.

Definition at line 35 of file HandleMultiMap.ixx.

Public Member Functions

begin()

template <typename TOneHandle, typename TManyHandle>
ConstIterator helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::begin ()
inline noexcept

Returns an iterator to the first dense binding.

Definition at line 131 of file HandleMultiMap.ixx.

132 return ConstIterator(this, 0);
133 }

bind()

template <typename TOneEntity, typename TManyEntity>
bool helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::bind (TOneEntity oneEntity, TManyEntity manyEntity)
inline

Binds two entities by forwarding their handles.

Template Parameters
TOneEntity

Entity type on the "one" side.

TManyEntity

Entity type on the "many" side.

Parameters
oneEntity

Entity owning the relation.

manyEntity

Entity associated with the owner.

Returns

true if the binding was inserted, otherwise false.

Definition at line 151 of file HandleMultiMap.ixx.

152 return bind(oneEntity.handle(), manyEntity.handle());
153 }

References helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::bind and helios::registerComponents.

Referenced by helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::bind.

bind()

template <typename TOneHandle, typename TManyHandle>
bool helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::bind (const TOneHandle key, const TManyHandle value)
inline

Binds a value handle to a key handle.

Inserts the value into the key bucket and stores reverse ownership in keys_. Returns false if the value is already bound.

Parameters
key

Key handle on the "one" side.

value

Value handle on the "many" side.

Returns

true if the binding was inserted, otherwise false.

Definition at line 166 of file HandleMultiMap.ixx.

166 bool bind(const TOneHandle key, const TManyHandle value) {
167
168 const auto keyIdx = key.entityId;
169 const auto valueIdx = value.entityId;
170
171 // assert that the value was not already registered.
172 if (valueIdx < keys_.size()
173 && keys_[valueIdx].isValid()) {
174 assert(false && "Value already exists");
175 return false;
176 }
177
178 // one idx to many handles
179 if (values_.size() <= keyIdx) {
180 values_.resize(keyIdx + 1);
181 }
182 values_[keyIdx].push_back(value);
183
184 // many idx to one handles
185 if (keys_.size() <= valueIdx) {
186 keys_.resize(valueIdx + 1);
187 }
188 keys_[valueIdx] = key;
189
190 // dense value iteration
191 denseValues_.push_back(value);
192
193 return true;
194 }

References helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::key and helios::registerComponents.

clear()

template <typename TOneHandle, typename TManyHandle>
void helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::clear ()
inline

Removes all bindings and clears all internal lookup structures.

Definition at line 232 of file HandleMultiMap.ixx.

232 void clear() {
233 values_.clear();
234 keys_.clear();
235 denseValues_.clear();
236 }

end()

template <typename TOneHandle, typename TManyHandle>
ConstIterator helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::end ()
inline noexcept

Returns the end iterator for dense binding iteration.

Definition at line 136 of file HandleMultiMap.ixx.

137 return ConstIterator(this, denseValues_.size());
138 }

key()

template <typename TOneHandle, typename TManyHandle>
TOneHandle helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::key (const TManyHandle value)
inline noexcept

Returns the owning key handle for a value handle.

Parameters
value

Value handle from the "many" side.

Returns

Owning key handle, or default-constructed handle if not found.

Definition at line 203 of file HandleMultiMap.ixx.

203 [[nodiscard]] TOneHandle key(const TManyHandle value) const noexcept {
204 const auto valueIdx = value.entityId;
205
206 if (keys_.size() <= valueIdx) {
207 return TOneHandle{};
208 }
209
210 return keys_[valueIdx];
211 }

Reference helios::registerComponents.

Referenced by helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::bind and helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::values.

reserve()

template <typename TOneHandle, typename TManyHandle>
void helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::reserve (std::size_t keyCapacity, std::size_t valueCapacity)
inline

Reserves capacity for dense key/value storage.

Parameters
keyCapacity

Expected number of distinct keys.

valueCapacity

Expected number of bound values.

Definition at line 244 of file HandleMultiMap.ixx.

244 void reserve(std::size_t keyCapacity, std::size_t valueCapacity) {
245 keys_.reserve(valueCapacity);
246 values_.reserve(keyCapacity);
247 denseValues_.reserve(valueCapacity);
248 }

Reference helios::registerComponents.

values()

template <typename TOneHandle, typename TManyHandle>
std::span< const TManyHandle > helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::values (const TOneHandle key)
inline noexcept

Returns all value handles bound to a key handle.

Parameters
key

Key handle from the "one" side.

Returns

Read-only span of associated value handles. Empty if key is unknown.

Definition at line 220 of file HandleMultiMap.ixx.

220 [[nodiscard]] std::span<const TManyHandle> values(const TOneHandle key) const noexcept {
221
222 const auto keyIdx = key.entityId;
223
224 if (values_.size() <= keyIdx) {
225 return {};
226 }
227
228 return values_[keyIdx];
229 }

References helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::key and helios::registerComponents.

Private Member Attributes

denseValues_

template <typename TOneHandle, typename TManyHandle>
std::vector<TManyHandle> helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::denseValues_

Dense list of all currently bound value handles.

Used by the iterator to avoid scanning holes in keys_.

Definition at line 52 of file HandleMultiMap.ixx.

52 std::vector<TManyHandle> denseValues_;

keys_

template <typename TOneHandle, typename TManyHandle>
std::vector<TOneHandle> helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::keys_

Reverse mapping from value handle id to owning key handle.

Definition at line 45 of file HandleMultiMap.ixx.

45 std::vector<TOneHandle> keys_;

values_

template <typename TOneHandle, typename TManyHandle>
std::vector<std::vector<TManyHandle> > helios::engine::core::container::HandleMultiMap< TOneHandle, TManyHandle >::values_

Forward mapping from key handle id to associated value handles.

Definition at line 40 of file HandleMultiMap.ixx.

40 std::vector<std::vector<TManyHandle>> values_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.