From acc4ef7b4ce4c7ab8090e916243a49806a652a00 Mon Sep 17 00:00:00 2001 From: psucien Date: Tue, 25 Jun 2024 09:43:25 +0200 Subject: [PATCH] common: slot_vector: added `is_allocated` to check if the slot already exists --- src/common/slot_vector.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/slot_vector.h b/src/common/slot_vector.h index 06c057c2..f0982e29 100644 --- a/src/common/slot_vector.h +++ b/src/common/slot_vector.h @@ -54,6 +54,10 @@ public: return values[id.index].object; } + bool is_allocated(SlotId id) const { + return ReadStorageBit(id.index); + } + template [[nodiscard]] SlotId insert(Args&&... args) noexcept { const u32 index = FreeValueIndex(); @@ -107,7 +111,7 @@ private: stored_bitset[index / 64] &= ~(u64(1) << (index % 64)); } - bool ReadStorageBit(u32 index) noexcept { + bool ReadStorageBit(u32 index) const noexcept { return ((stored_bitset[index / 64] >> (index % 64)) & 1) != 0; }