AK: Add Vector::unstable_remove(index)

This removes an item at an index without preserving the sort order of
the Vector.

This enables constant-time removal from unsorted Vectors, as it avoids
shifting all of the entries following the removed one.
This commit is contained in:
Andreas Kling 2020-01-15 19:24:25 +01:00
parent 542098d90d
commit 575664cda3

View file

@ -278,6 +278,13 @@ public:
return value;
}
void unstable_remove(int index)
{
ASSERT(index < m_size);
swap(at(index), at(m_size - 1));
take_last();
}
void remove(int index)
{
ASSERT(index < m_size);