use super::Peaker;
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash)]
pub struct PriorityMax {
side: bool,
}
impl PriorityMax {
pub fn new(priorities_right: bool) -> Self {
Self {
side: priorities_right,
}
}
pub fn left() -> Self {
Self::new(false)
}
pub fn right() -> Self {
Self::new(true)
}
}
impl Peaker for PriorityMax {
fn peak(&mut self, mins: &[usize], widths: &[usize]) -> Option<usize> {
if self.side {
(0..widths.len())
.filter(|&i| mins.is_empty() || widths[i] > mins[i])
.max_by_key(|&i| widths[i])
.filter(|&col| widths[col] != 0)
} else {
(0..widths.len())
.rev()
.filter(|&i| mins.is_empty() || widths[i] > mins[i])
.max_by_key(|&i| widths[i])
.filter(|&col| widths[col] != 0)
}
}
}