mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:57:45 +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
1 changed files with 7 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue