mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 18:15:58 +00:00
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:
parent
542098d90d
commit
575664cda3
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue