18 constexpr explicit operator bool() const noexcept {
return index != 0; }
30 constexpr bool operator!=(
const StorageIndex& other)
const noexcept {
31 return !(*
this == other);
35static_assert(
sizeof(StorageIndex) == 8,
"StorageIndex must be 8 bytes");
43 static constexpr uint32_t ALIVE_BIT = uint32_t(1) << 31;
44 static constexpr uint32_t GEN_MASK = ~ALIVE_BIT;
51 void setAlive(
bool alive) { value = (value & GEN_MASK) | (alive ? ALIVE_BIT : 0); }
58 void bumpGeneration() { value = (value & ALIVE_BIT) | (((value & GEN_MASK) + 1) & GEN_MASK); }
60 bool alive()
const {
return value & ALIVE_BIT; }
61 uint32_t generation()
const {
return value & GEN_MASK; }
64static_assert(
sizeof(
GenerationIndex) == 4,
"GenerationIndex must be 4 bytes");
73using TypeId = uint32_t;
82 TypeId typeIdFromInfo(
const std::type_info& info);
88 static const TypeId s_id = detail::typeIdFromInfo(
typeid(T));
Per-slot alive flag (bit 31) and generation counter (bits 0-30) in one uint32_t.
Definition types.h:40
void setAlive(bool alive)
Set the alive/dead status, leaving the generation untouched.
Definition types.h:51
void bumpGeneration()
Increment the generation counter, preserving the alive bit.
Definition types.h:58
Opaque handle pairing a sparse-array index with a generation counter.
Definition types.h:14
constexpr bool operator==(const StorageIndex &other) const noexcept
Compare two handles for identity.
Definition types.h:27
uint32_t generation
The slot's generation when minted.
Definition types.h:16
uint32_t index
Sparse slot index; 0 is null.
Definition types.h:15