pub struct MovingMax<T> {
push_stack: Vec<(T, T)>,
pop_stack: Vec<(T, T)>,
}Expand description
Keep track of the maximum value in a sliding window.
See MovingMin for more details.
let mut moving_max = MovingMax::<i32>::new();
moving_max.push(2);
moving_max.push(3);
moving_max.push(1);
assert_eq!(moving_max.max(), Some(&3));
assert_eq!(moving_max.pop(), Some(2));
assert_eq!(moving_max.max(), Some(&3));
assert_eq!(moving_max.pop(), Some(3));
assert_eq!(moving_max.max(), Some(&1));
assert_eq!(moving_max.pop(), Some(1));
assert_eq!(moving_max.max(), None);
assert_eq!(moving_max.pop(), None);Fields§
§push_stack: Vec<(T, T)>§pop_stack: Vec<(T, T)>Implementations§
Source§impl<T> MovingMax<T>where
T: Clone + PartialOrd,
impl<T> MovingMax<T>where
T: Clone + PartialOrd,
Sourcepub fn new() -> MovingMax<T>
pub fn new() -> MovingMax<T>
Creates a new MovingMax to keep track of the maximum in a sliding window.
Sourcepub fn with_capacity(capacity: usize) -> MovingMax<T>
pub fn with_capacity(capacity: usize) -> MovingMax<T>
Creates a new MovingMax to keep track of the maximum in a sliding window with
capacity allocated slots.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for MovingMax<T>
impl<T> RefUnwindSafe for MovingMax<T>where
T: RefUnwindSafe,
impl<T> Send for MovingMax<T>where
T: Send,
impl<T> Sync for MovingMax<T>where
T: Sync,
impl<T> Unpin for MovingMax<T>where
T: Unpin,
impl<T> UnwindSafe for MovingMax<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more