Function malachite_base::slices::slice_move_left
source · Expand description
Given a slice and an starting index, copies the subslice starting from that index to the beginning of the slice.
In other words, this function copies the contents of &xs[starting_index..]
to
&xs[..xs.len() - starting_index]
.
In other other words, if $k$ is starting_index
, the sequence $[x_0, x_1, \ldots, x_{n-1}]$
becomes $[x_k, x_{k+1}, \ldots, x_{n-1}, x_{n-k}, x_{n-k+1}, \ldots, x_{n-1}]$.
If starting_index
is zero or xs.len()
, nothing happens.
Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.len()
.
Panics
Panics if starting_index
is greater than the length of xs
.
Examples
use malachite_base::slices::slice_move_left;
let xs = &mut [1, 2, 3, 4, 5, 6];
slice_move_left::<u32>(xs, 2);
assert_eq!(xs, &[3, 4, 5, 6, 5, 6]);