From d7a5cbfc95cc0574f6eafdb5e5c517b2bac41526 Mon Sep 17 00:00:00 2001 From: psucien Date: Sat, 22 Jun 2024 19:04:42 +0200 Subject: [PATCH] common: slot_vector: added `is_allocated` to check if the 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..fa3e899b 100644 --- a/src/common/slot_vector.h +++ b/src/common/slot_vector.h @@ -54,6 +54,13 @@ public: return values[id.index].object; } + bool is_allocated(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();