SlotMap update
Some checks failed
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 7m16s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m15s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 5m40s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 5m42s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m55s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m1s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 7m19s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 7m1s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Has been cancelled
Bigfoot / Clang Format Checks (push) Has been cancelled
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled

This commit is contained in:
2026-05-15 11:16:49 +02:00
parent b867701d2a
commit f2228a0182
2 changed files with 137 additions and 139 deletions

View File

@@ -28,11 +28,47 @@ TEST_F(SlotMapFixture, Insert)
const SlotMap<std::uint32_t>::SlotKey fourthKey = m_slotMap.Insert(3);
const SlotMap<std::uint32_t>::SlotKey fifthKey = m_slotMap.Insert(65);
EXPECT_FALSE(m_slotMap.Has(firstKey));
EXPECT_FALSE(m_slotMap.Has(secondKey));
EXPECT_TRUE(m_slotMap.Has(thirdKey));
EXPECT_TRUE(m_slotMap.Has(fourthKey));
EXPECT_TRUE(m_slotMap.Has(fifthKey));
EXPECT_FALSE(m_slotMap.Has(SlotMap<std::uint32_t>::SlotKey {}));
EXPECT_FALSE(m_slotMap.Has(SlotMap<std::uint32_t>::SlotKey {1, 4}));
EXPECT_EQ(m_slotMap.Get(firstKey), nullptr);
EXPECT_EQ(m_slotMap.Get(secondKey), nullptr);
EXPECT_EQ(*m_slotMap.Get(thirdKey), 42);
EXPECT_EQ(*m_slotMap.Get(fourthKey), 3);
EXPECT_EQ(*m_slotMap.Get(fifthKey), 65);
EXPECT_EQ(m_slotMap.Get(SlotMap<std::uint32_t>::SlotKey {}), nullptr);
EXPECT_EQ(m_slotMap.Get(SlotMap<std::uint32_t>::SlotKey {1, 4}), nullptr);
}
TEST(SlotMap, VersionOverflowDeactivatesSlot)
{
SlotMap<std::uint32_t, std::uint8_t> slotMap;
SlotMap<std::uint32_t, std::uint8_t>::SlotKey key = slotMap.Insert(1);
for (SlotMap<std::uint32_t, std::uint8_t>::SlotKey::VersionType i = 1;
i < SlotMap<std::uint32_t, std::uint8_t>::SlotKey::MAX_VERSION;
++i)
{
slotMap.Remove(key);
const SlotMap<std::uint32_t, std::uint8_t>::SlotKey newKey = slotMap.Insert(1);
EXPECT_EQ(newKey.GetIndex(), key.GetIndex());
key = newKey;
}
// Slot is at MAX_VERSION — one more remove should overflow and permanently deactivate it
EXPECT_EQ(key.GetVersion(), (SlotMap<std::uint32_t, std::uint8_t>::SlotKey::MAX_VERSION));
slotMap.Remove(key);
EXPECT_FALSE(slotMap.Has(key));
// Dead slot must not be recycled; a new insert must allocate a fresh slot index
const SlotMap<std::uint32_t, std::uint8_t>::SlotKey newKey = slotMap.Insert(2);
EXPECT_NE(newKey.GetIndex(), key.GetIndex());
}
} // namespace Bigfoot