Skip to content

Engine → Core

slot_map.h

Dense storage addressed by generational keys. Insertion returns a key that stays valid until that element is erased; afterwards find() returns nullptr for it, even when the slot has been reused. Not thread-safe; concurrent const access is fine. T must be move-constructible and move-assignable (swap-remove). Pointers returned by find() and references and iterators obtained during iteration are invalidated by insert, emplace, erase, clear and reserve. A moved-from map is empty (no slots) and reusable.

Structs

File Description
slot_key Default key of a slot_map: a slot index and the generation of that slot when the key was issued. The all-zero key is null; generation 0 is never issued.
slot_map::slot_entry One slot of the indirection table. A slot is live (denseIndex valid), free (on the free list, generation = the one issued next) or retired (generation wrapped).
std::hash<conjure::core::slot_key>
std::tuple_element<0, conjure::core::slot_map_entry<Key, T>>
std::tuple_element<1, conjure::core::slot_map_entry<Key, T>>
std::tuple_size<conjure::core::slot_map_entry<Key, T>>

Classes

File Description
slot_map Dense storage addressed by generational keys. Insertion returns a key that stays valid until that element is erased; afterwards find() returns nullptr for it, even when the slot has been reused. Not thread-safe; concurrent const access is fine. T must be move-constructible and move-assignable (swap-remove). Pointers returned by find() and references and iterators obtained during iteration are invalidated by insert, emplace, erase, clear and reserve. A moved-from map is empty (no slots) and reusable.
slot_map_entry What a slot_map stores and what its iterators point at: the key and the element. Supports structured bindings (auto &[key, value] binds straight into the map's storage) and key()/value() accessors. The key is read-only; changing it would corrupt the map.

Type Aliases

slot_map::const_iterator

using const_iterator = const entry *;

slot_map::entry

using entry = slot_map_entry<Key, T>;

slot_map::generation_type

using generation_type = std::remove_cvref_t<decltype(Key::generation)>;

slot_map::index_type

using index_type = std::remove_cvref_t<decltype(Key::index)>;

slot_map::iterator

using iterator = entry *;

slot_map::key_type

using key_type = Key;

slot_map::size_type

using size_type = usize;

slot_map::value_type

using value_type = T;

std::tuple_element<0, conjure::core::slot_map_entry<Key, T>>::type

using type = const Key;

std::tuple_element<1, conjure::core::slot_map_entry<Key, T>>::type

using type = T;

Concepts

slot_key_type

template <typename Key> concept slot_key_type = std::is_trivially_copyable_v<Key> && std::is_default_constructible_v<Key> && std::unsigned_integral<std::remove_cvref_t<decltype(Key::index)>> && std::unsigned_integral<std::remove_cvref_t<decltype(Key::generation)>> && sizeof(Key::index) <= sizeof(u32) && sizeof(Key::generation) <= sizeof(u32) && requires( Key key, std::remove_cvref_t<decltype(Key::index)> index, std::remove_cvref_t<decltype(Key::generation)> generation ) { key.index = index; key.generation = generation; };

Requirements on a custom key type: trivially copyable, default constructible (the null key), with assignable unsigned index and generation fields of at most 32 bits each. Narrower fields are allowed: a u16 generation retires a slot after 65535 reuses.