pub fn exhaustive_signed_inclusive_range<T: PrimitiveSigned>(
    a: T,
    b: T
) -> ExhaustiveSignedRange<T>Notable traits for ExhaustiveSignedRange<T>impl<T: PrimitiveSigned> Iterator for ExhaustiveSignedRange<T> type Item = T;
Expand description

Generates all signed integers in the closed interval $[a, b]$, in order of increasing absolute value.

When two numbers have the same absolute value, the positive one comes first. $a$ must be less than or equal to $b$. If $a$ and $b$ are equal, the range contains a single element.

The output satisfies $(|x_i|, \operatorname{sgn}(-x_i)) <_\mathrm{lex} (|x_j|, \operatorname{sgn}(-x_j))$ whenever $i, j \in [0, b - a]$ and $i < j$.

The output length is $b - a + 1$.

Complexity per iteration

Constant time and additional memory.

Panics

Panics if $a > b$.

Examples

extern crate itertools;

use itertools::Itertools;
use malachite_base::num::exhaustive::exhaustive_signed_inclusive_range;

assert_eq!(
    exhaustive_signed_inclusive_range::<i8>(-5, 5).collect_vec(),
    &[0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5]
)