malachite_base/orderings/
exhaustive.rs

1// Copyright © 2025 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::orderings::ORDERINGS;
10use core::cmp::Ordering::{self, *};
11use core::iter::Copied;
12use core::slice::Iter;
13
14pub type ExhaustiveOrderings = Copied<Iter<'static, Ordering>>;
15
16/// Generates all [`Ordering`]s, in increasing order.
17///
18/// The output length is 3.
19///
20/// # Worst-case complexity per iteration
21/// Constant time and additional memory.
22///
23/// # Examples
24/// ```
25/// use itertools::Itertools;
26/// use malachite_base::orderings::exhaustive::orderings_increasing;
27/// use std::cmp::Ordering::*;
28///
29/// assert_eq!(
30///     orderings_increasing().collect_vec(),
31///     &[Less, Equal, Greater]
32/// );
33/// ```
34#[inline]
35pub fn orderings_increasing() -> ExhaustiveOrderings {
36    [Less, Equal, Greater].iter().copied()
37}
38
39/// Generates all [`Ordering`]s, with `Equal` coming first.
40///
41/// The output length is 3.
42///
43/// # Worst-case complexity per iteration
44/// Constant time and additional memory.
45///
46/// # Examples
47/// ```
48/// use itertools::Itertools;
49/// use malachite_base::orderings::exhaustive::exhaustive_orderings;
50/// use std::cmp::Ordering::*;
51///
52/// assert_eq!(
53///     exhaustive_orderings().collect_vec(),
54///     &[Equal, Less, Greater]
55/// );
56/// ```
57#[inline]
58pub fn exhaustive_orderings() -> Copied<Iter<'static, Ordering>> {
59    ORDERINGS.iter().copied()
60}