#[cfg(feature = "no_std")]
use core::cmp::Ordering;
#[cfg(not(feature = "no_std"))]
use std::cmp::Ordering;
use super::Opt;
pub fn check_sorted_opt_ary_with(opt_ary: &[Opt]) -> bool {
let mut target = opt_ary.to_vec();
target.sort_by(|&a, &b| match a.lon.cmp(b.lon) {
Ordering::Less => Ordering::Less,
Ordering::Greater => Ordering::Greater,
Ordering::Equal => match a.sho.cmp(&b.sho) {
Ordering::Less => Ordering::Less,
Ordering::Greater => Ordering::Greater,
Ordering::Equal => a.num.cmp(&b.num),
},
});
target == opt_ary
}
pub fn check_sorted_sho_idx_ary_with(sho_idx_ary: &[(u8, usize)]) -> bool {
let mut target = sho_idx_ary.to_vec();
target.sort_by(|&a, &b| match a.0.cmp(&b.0) {
Ordering::Less => Ordering::Less,
Ordering::Greater => Ordering::Greater,
Ordering::Equal => a.1.cmp(&b.1),
});
target == sho_idx_ary
}
pub fn check_sorted_opt_ary_and_sho_idx_ary_with(
opt_ary: &[Opt],
sho_idx_ary: &[(u8, usize)],
) -> bool {
let mut prev_sho: u8 = 0u8;
for sho in sho_idx_ary {
if (prev_sho > 0 && prev_sho >= sho.0) || opt_ary[sho.1].sho != sho.0 {
return false;
}
prev_sho = sho.0;
}
let mut prev_lon: &str = "";
for o in opt_ary {
if prev_lon > o.lon || (!prev_lon.is_empty() && prev_lon == o.lon) {
return false;
}
prev_lon = o.lon;
}
true
}