#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StackHeightStats {
min_positive_height_or_zero: usize,
max_height: usize,
}
impl Default for StackHeightStats {
fn default() -> Self {
Self {
min_positive_height_or_zero: 0,
max_height: 0,
}
}
}
impl StackHeightStats {
#[inline]
pub(crate) fn observe(&mut self, h: usize) {
self.max_height = self.max_height.max(h);
if h == 0 {
return;
}
if self.min_positive_height_or_zero == 0 || h < self.min_positive_height_or_zero {
self.min_positive_height_or_zero = h;
}
}
}
impl StackHeightStats {
#[inline]
pub const fn min_positive_height_or_zero(&self) -> usize {
self.min_positive_height_or_zero
}
#[inline]
pub const fn max_height(&self) -> usize {
self.max_height
}
}
impl StackHeightStats {
#[inline]
pub const fn has_positive_height(&self) -> bool {
self.max_height != 0
}
#[inline]
pub const fn has_overlap(&self) -> bool {
self.max_height > 1
}
#[inline]
pub const fn is_uniform_positive_height(&self) -> bool {
self.min_positive_height_or_zero != 0 && self.min_positive_height_or_zero == self.max_height
}
}
#[cfg(test)]
pub(crate) mod test_support;