macro_rules! split_into_chunks_mut { ($xs: expr, $n: expr, [$($xs_i: ident),*], $xs_last: ident) => { ... }; }
Expand description
Splits a mutable slice into adjacent mutable chunks.
An input slice $\mathbf{x}$, a chunk length $n$, and $k + 1$ output slice names $\mathbf{x}_0,
\mathbf{x}_1, \ldots, \mathbf{x}_k$ are given. The last output slice name, $\mathbf{x}_k$, is
specified via a separate argument called xs_last
.
The first $k$ output slice names are assigned adjacent length-$n$ chunks from $\mathbf{x}$. If $|\mathbf{x}| < kn$, the generated code panics.
The last slice, $\mathbf{x}_k$, which is assigned to xs_last
, has length $|\mathbf{x}| - kn$.
This length may be greater than $n$.
§Worst-case complexity
$T(k) = O(k)$
$M(k) = O(1)$
where $T$ is time, $M$ is additional memory, and $k$ is the number of output slice names xs_i
.
§Examples
use malachite_base::slices::slice_set_zero;
use malachite_base::split_into_chunks_mut;
let xs = &mut [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
split_into_chunks_mut!(xs, 3, [xs_1, xs_2, xs_3], xs_4);
assert_eq!(xs_1, &[0, 1, 2]);
assert_eq!(xs_2, &[3, 4, 5]);
assert_eq!(xs_3, &[6, 7, 8]);
assert_eq!(xs_4, &[9, 10, 11, 12]);
slice_set_zero(xs_2);
assert_eq!(xs, &[0, 1, 2, 0, 0, 0, 6, 7, 8, 9, 10, 11, 12]);