tabled/settings/peaker/
max.rs1use super::Peaker;
2
3#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash)]
5pub struct PriorityMax {
6 side: bool,
7}
8
9impl PriorityMax {
10 pub fn new(priorities_right: bool) -> Self {
16 Self {
17 side: priorities_right,
18 }
19 }
20
21 pub fn left() -> Self {
24 Self::new(false)
25 }
26
27 pub fn right() -> Self {
30 Self::new(true)
31 }
32}
33
34impl Peaker for PriorityMax {
35 fn peak(&mut self, mins: &[usize], widths: &[usize]) -> Option<usize> {
36 if self.side {
37 (0..widths.len())
38 .filter(|&i| mins.is_empty() || widths[i] > mins[i])
39 .max_by_key(|&i| widths[i])
40 .filter(|&col| widths[col] != 0)
41 } else {
42 (0..widths.len())
43 .rev()
44 .filter(|&i| mins.is_empty() || widths[i] > mins[i])
45 .max_by_key(|&i| widths[i])
46 .filter(|&col| widths[col] != 0)
47 }
48 }
49}