tabled/settings/peaker/
right.rs1use super::Peaker;
2
3#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash)]
5pub struct PriorityRight {
6 i: Option<usize>,
7}
8
9impl PriorityRight {
10 pub const fn new() -> Self {
12 Self { i: None }
13 }
14}
15
16impl Peaker for PriorityRight {
17 fn peak(&mut self, min: &[usize], widths: &[usize]) -> Option<usize> {
18 if widths.is_empty() {
19 return None;
20 }
21
22 if self.i.is_none() {
23 self.i = Some(widths.len() - 1);
24 }
25
26 let col = self.i.expect("checked");
27 if widths[col] > min[col] {
28 return Some(col);
29 }
30
31 if col == 0 {
32 return None;
33 }
34
35 let mut col = col - 1;
36 while widths[col] == min[col] {
37 if col == 0 {
38 return None;
39 }
40
41 col -= 1;
42 }
43
44 Some(col)
45 }
46}