Basic module

array_ordered_remove_by_index

procedure · 1 overloadSource

Removes the element at index and shifts the later ones down, keeping their order.

Takes a pointer to the array (a dynamic array or a view) and only lowers its count: the memory stays, and the removed element is not destroyed or freed. An out-of-range index fails an assert. Linear in the number of elements shifted; array_unordered_remove_by_index is constant time when order does not matter.

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

Removes the element at index and shifts the later ones down, keeping their order.

Takes a pointer to the array (a dynamic array or a view) and only lowers its count: the memory stays, and the removed element is not destroyed or freed. An out-of-range index fails an assert. Linear in the number of elements shifted; array_unordered_remove_by_index is constant time when order does not matter.

Parameters

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

See also