Basic module

array_unordered_remove_by_index

procedure · 1 overloadSource

Removes the element at index by moving the last element into its place, in constant time.

The order of the array changes (unless the removed element was the last one), so do not use it where order matters, or while iterating forward by index without revisiting index. Only the count is lowered; the memory is kept. An out-of-range index fails an assert.

ExampleOpen in playground ↗
values: [..] int;
array_add(*values, 1, 2, 3, 4);
array_unordered_remove_by_index(*values, 0);
assert(values.count == 3 && values[0] == 4 && values[1] == 2);
array_free(values);
array_unordered_remove_by_index :: (array_pointer: *[] $T, index: s64)

Removes the element at index by moving the last element into its place, in constant time.

The order of the array changes (unless the removed element was the last one), so do not use it where order matters, or while iterating forward by index without revisiting index. Only the count is lowered; the memory is kept. An out-of-range index fails an assert.

Parameters

array_pointer: *[] $T
index: s64
ExampleOpen in playground ↗
values: [..] int;
array_add(*values, 1, 2, 3, 4);
array_unordered_remove_by_index(*values, 0);
assert(values.count == 3 && values[0] == 4 && values[1] == 2);
array_free(values);

See also