Struct sliding_extrema::SlidingExtrema
source · pub struct SlidingExtrema<T: Clone, F: ExtremumFunction<T>> { /* private fields */ }
Expand description
T is the datatype of the items in the queue. F is a function that compares two items and returns the extreme value. I.e, if you’re implementing a ‘max’-function, F should be a function returning the largest of two values.
Implementations§
source§impl<T: Clone, F: ExtremumFunction<T>> SlidingExtrema<T, F>
impl<T: Clone, F: ExtremumFunction<T>> SlidingExtrema<T, F>
sourcepub fn new(extremum: F) -> SlidingExtrema<T, F>
pub fn new(extremum: F) -> SlidingExtrema<T, F>
Create a new empty queue with the given comparator. Note that using this function, the comparator can be stateful.
source§impl<T: Clone> SlidingExtrema<T, CustomExtremum<T>>
impl<T: Clone> SlidingExtrema<T, CustomExtremum<T>>
sourcepub fn new_dynamic(
extremum: fn(_: &T, _: &T) -> T
) -> SlidingExtrema<T, CustomExtremum<T>>
pub fn new_dynamic( extremum: fn(_: &T, _: &T) -> T ) -> SlidingExtrema<T, CustomExtremum<T>>
Create a new empty queue with the given comparator-function. This allows the function to be varied at runtime, without making the implementing closure/function type be a part of the SlidingExtrema-type instantiation. Note, the comparator must be stateless. Typically, finding the min/max between two functions doesn’t require any state. But if it does, use the ‘new’ function and implement the trait ‘ExtremumFunction’.
source§impl<T: Clone, F: ExtremumFunction<T>> SlidingExtrema<T, F>
impl<T: Clone, F: ExtremumFunction<T>> SlidingExtrema<T, F>
sourcepub fn get_extrema(&self) -> Option<T>
pub fn get_extrema(&self) -> Option<T>
Get the current extreme value of all the items in the queue. Performance is amortized O(1)