From f375e0cfb01da2afc69a99c45315fa2abac6c9d4 Mon Sep 17 00:00:00 2001 From: psucien Date: Tue, 18 Jun 2024 15:02:01 +0200 Subject: [PATCH] common: slot_vector: added `IsAllocated` to check if a slot already exists --- src/common/slot_vector.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/slot_vector.h b/src/common/slot_vector.h index 06c057c2..85d9d849 100644 --- a/src/common/slot_vector.h +++ b/src/common/slot_vector.h @@ -54,6 +54,13 @@ public: return values[id.index].object; } + bool IsAllocated(SlotId id) const { + if (id && id.index / 64 < stored_bitset.size()) { + return ((stored_bitset[id.index / 64] >> (id.index % 64)) & 1) != 0; + } + return false; + } + template [[nodiscard]] SlotId insert(Args&&... args) noexcept { const u32 index = FreeValueIndex();