Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
template size_t handle_map::erase(Id_T handle)
if (!isValid(handle)) { return 0; }
m_fragmented = 1;
Id_T innerId = m_sparseIds[handle.index];
uint32_t innerIndex = innerId.index;
// push this slot to the back of the freelist = 1;
// increment generation so remaining outer ids go stale
innerId.index = 0xFFFFFFFF;
// max numeric value represents the end of the freelist
m_sparseIds[handle.index] = innerId;
// write outer id changes back to the array
if (freeListEmpty())
// if the freelist was empty, it now starts (and ends) at this index
m_freeListFront = handle.index;
m_freeListBack = m_freeListFront;
m_sparseIds[m_freeListBack].index = handle.index;
// previous back of the freelist points to new back
m_freeListBack = handle.index;
// new freelist back is stored
// remove the component by swapping with the last element, then pop_back
if (innerIndex != m_items.size() - 1)
std::swap(, m_items.back());
std::swap(, m_meta.back());
// fix the ComponentId index of the swapped component
m_sparseIds[].index = innerIndex;
return 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.