Engine → Core → slot_map.h
slot_map
| Type | Class |
| Namespace | conjure::core |
| Include File Path | engine/include/conjure/core/containers/slot_map.h |
| Source File Path | N/A |
| API ↗ | Containers |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | slot_map() = default; | |
| public | slot_map(
const slot_map &) = default; | |
| public | slot_map(
slot_map &&other) noexcept; | Takes the elements, slots and keys of other, which is left empty (no slots) and reusable. Keys issued by other address the new map. |
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~slot_map() = default; |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | INVALID_ | static constexpr u32 | std:: | |
| public | MAX_ | static constexpr usize | static_ | Largest number of slots the key's index type can address. |
| private | mEntries | std::vector<entry> | {} | |
| private | mFreeCount | u32 | 0 | |
| private | mFreeHead | u32 | INVALID_INDEX | |
| private | m | u32 | 0 | |
| private | mSlots | std::vector<slot_entry> | {} |
Functions
Public
capacity
capacity[[nodiscard]] usize capacity() const noexcept;Elements the dense storage can hold without reallocating.
cbegin
cbegin[[nodiscard]] const_iterator cbegin() const noexcept;cend
cend[[nodiscard]] const_iterator cend() const noexcept;clear
clearvoid clear();Erases every element. Every outstanding key becomes stale (generations are bumped); slots and capacity are kept for reuse.
contains
contains[[nodiscard]] bool contains(
Key key) const noexcept;True when key addresses a live element.
emplace
emplacetemplate <typename... Args> [[nodiscard]] Key emplace(
Args &&...args);Constructs an element in place and returns its key. Returns the null key (and asserts) when the key's index type cannot address another slot.
empty
empty[[nodiscard]] bool empty() const noexcept;entries
entries[[nodiscard]] std::span<entry> entries() noexcept;The live {key, value} entries in dense storage order (the order iteration uses).
[[nodiscard]] std::span<const entry> entries() const noexcept;erase
erasebool erase(
Key key);Destroys the element addressed by key. Returns false for null, stale or unknown keys. The slot's generation is bumped so every outstanding copy of the key becomes stale; a generation that would wrap to 0 retires the slot for good.
iterator erase(
const_iterator position);Erases the element an iterator points at. Returns the iterator to the element that now occupies that storage position (or end()), so erase-while-iterating works. The iterator must point at an element of this map; end() and iterators of other maps assert and leave the map unchanged.
find
find[[nodiscard]] T *find(
Key key) noexcept;The element addressed by key, or nullptr when the key is null, stale or unknown. Allocation-free, O(1).
[[nodiscard]] const T *find(
Key key) const noexcept;free_slot_count
free_slot_count[[nodiscard]] usize free_slot_count() const noexcept;Slots on the free list, reused by the next insertions.
insert
insert[[nodiscard]] Key insert(
T &&value);Moves an element in and returns its key.
[[nodiscard]] Key insert(
const T &value);Copies an element in and returns its key.
key_at
key_at[[nodiscard]] Key key_at(
usize denseIndex) const noexcept;Key of the element at dense position denseIndex (the order iteration uses). Asserts and returns the null key when the position is out of range.
retired_slot_count
retired_slot_count[[nodiscard]] usize retired_slot_count() const noexcept;Slots whose generation wrapped; they are never reused.
slot_count
slot_count[[nodiscard]] usize slot_count() const noexcept;Slots in the indirection table (live + free + retired).
Private
erase_at
erase_atvoid erase_at(
u32 denseIndex);live_slot
live_slot[[nodiscard]] const slot_entry *live_slot(
Key key) const noexcept;make_key
make_keyBuilds a key field by field so key types that declare their members in any order (or add more) work.
release_slot
release_slotvoid release_slot(
u32 slotIndex) noexcept;Marks a slot free (or retired when its generation wraps). The caller has already removed the element from the dense storage.