![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
Dense-packed storage indexed by external uint32_t keys. More...
#include <sparse_set.h>
Public Member Functions | |
| T & | add (uint32_t key, T &&value) |
| Insert an element at the given key. | |
| void | remove (uint32_t key) |
| Remove the element at the given key via swap-and-pop. | |
| void | removeIfPresent (uint32_t key) override |
| Remove the element at the given key if one is present. | |
| bool | contains (uint32_t key) const |
| Test whether a key is present. | |
| T & | get (uint32_t key) |
| Access the element at the given key. | |
| template<typename Fn> | |
| void | forEach (Fn &&fn) |
| Iterate all live elements densely (no holes). | |
| size_t | size () const |
| Number of live elements. | |
| void | clear () |
| Drop every element. | |
| void | compact () override |
| Shrink the sparse array to fit only live keys, reclaiming wasted memory. | |
| uint32_t | keyAt (uint32_t denseIndex) const |
| Access the sparse key stored at a dense index. | |
| T & | dataAt (uint32_t denseIndex) |
| Access the element stored at a dense index. | |
Dense-packed storage indexed by external uint32_t keys.
Dense iteration; O(1) add, remove, contains and get; swap-and-pop removal. The caller owns the key lifecycle and generations.
| T | Element type to store. |
|
inline |
Insert an element at the given key.
| key | External sparse key; not 0, not already present. |
| value | Element to insert. |
|
inline |
Remove the element at the given key via swap-and-pop.
| key | External sparse key; must be present. |
|
inlineoverridevirtual |
Remove the element at the given key if one is present.
| key | External sparse key; absent is a no-op. |
Implements Vkm::Engine::ISparseSet.
|
inline |
Test whether a key is present.
| key | External sparse key. |
|
inline |
Access the element at the given key.
| key | External sparse key; must be present. |
|
inline |
Iterate all live elements densely (no holes).
Do not add or remove while this runs: swap-and-pop skips the moved element, and an add can reallocate under fn. Collect keys and act afterwards.
| Fn | Callable as void(uint32_t, T&). |
| fn | Called once per live element, with its key, in packed order. |
|
inline |
Number of live elements.
|
inline |
Drop every element.
Capacity is kept, so a rebuild does not allocate again.
|
inlineoverridevirtual |
Shrink the sparse array to fit only live keys, reclaiming wasted memory.
Always shrinks, since a bulk build in ascending key order leaves mostly geometric over-allocation rather than entries past the highest key. The dense arrays are unaffected.
Implements Vkm::Engine::ISparseSet.
|
inline |
|
inline |
Access the element stored at a dense index.
| denseIndex | Position in packed order (< size()). |