DoxigAlpha

swapRemove

Removes the element at the specified index and returns it. The empty slot is filled from the end of the list. Invalidates pointers to last element. This operation is O(1). Asserts that the list is not empty. Asserts that the index is in bounds.

Function parameters

Parameters

#
self:*Self
i:usize

Deprecated.

Functions

#
Managed
Deprecated.
AlignedManaged
Deprecated.
Aligned
A contiguous, growable list of arbitrarily aligned items in memory.

Source

Implementation

#
pub fn swapRemove(self: *Self, i: usize) T {
    if (self.items.len - 1 == i) return self.pop().?;

    const old_item = self.items[i];
    self.items[i] = self.pop().?;
    return old_item;
}