pub fn exhaustive_natural_inclusive_range(
a: Natural,
b: Natural
) -> ExhaustiveNaturalRange ⓘ
Expand description
Generates all Natural
s in the closed interval $[a, b]$, in ascending order.
a
must be less than or equal to b
. If a
and b
are equal, the range contains a single
element. To generate all Natural
s in an infinite interval, use
exhaustive_natural_range_to_infinity
.
The output is $(k)_{k=a}^{b}$.
The output length is $b - a + 1$.
§Worst-case complexity per iteration
$T(i) = O(i)$
$M(i) = O(i)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration number.
Although the time and space complexities are worst-case linear, the worst case is very rare. If
we exclude the cases where the least-significant limb of the previously-generated value is
Limb::MAX
, the worst case space and time complexities are constant.
§Panics
Panics if $a>b$.
§Examples
use itertools::Itertools;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::exhaustive::exhaustive_natural_inclusive_range;
use malachite_nz::natural::Natural;
assert_eq!(
exhaustive_natural_inclusive_range(Natural::from(5u32), Natural::from(10u32)).collect_vec()
.to_debug_string(),
"[5, 6, 7, 8, 9, 10]"
)