macro_rules! split_into_chunks {
    ($xs: expr, $n: expr, [$($xs_i: ident),*], $xs_last: ident) => { ... };
}
Expand description

Splits an immutable slice into adjacent immutable 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

#[macro_use]
extern crate malachite_base;

fn main() {
    let xs = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
    split_into_chunks!(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]);
}