pub struct NBest<T, F = ()>where
Self: NBestWrapper<T, F>,{ /* private fields */ }Expand description
Collection to keep the N highest elements, and discard the others
Implementations§
Source§impl<T, F: Fn(&T, &T) -> Ordering + Clone> NBest<T, F>
impl<T, F: Fn(&T, &T) -> Ordering + Clone> NBest<T, F>
Sourcepub fn with_cmp_fn(n: usize, func: F) -> Self
pub fn with_cmp_fn(n: usize, func: F) -> Self
Returns a new NBest, using the supplied function to perform comparisons
Sourcepub fn with_cmp_fn_and_iter<I>(n: usize, func: F, iter: I) -> Self
pub fn with_cmp_fn_and_iter<I>(n: usize, func: F, iter: I) -> Self
Returns a new NBest, built from the contents of an iterator, using the supplied function
Source§impl<T, F> NBest<T, F>where
Self: NBestWrapper<T, F>,
impl<T, F> NBest<T, F>where
Self: NBestWrapper<T, F>,
Sourcepub fn push(&mut self, item: T)
pub fn push(&mut self, item: T)
Adds a new element, discarding the lowest element if the collection is at capacity
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Returns the least element contained within the collection, or None if the collection is empty
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements contained within the collection
len() will always be less than capacity.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the maximum number of elements the collection will collect
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Returns an iterator over the elements contained within the collection, in an unspecified order
Sourcepub fn drain<'a>(&'a mut self) -> impl Iterator<Item = T> + 'a
pub fn drain<'a>(&'a mut self) -> impl Iterator<Item = T> + 'a
Empties the collection and returns an iterator over all contained elements, in an unspecified order
Sourcepub fn into_sorted_vec(self) -> Vec<T>
pub fn into_sorted_vec(self) -> Vec<T>
Consumes the collection, and returns all elements in a sorted Vec
Trait Implementations§
Source§impl<T, F> Extend<T> for NBest<T, F>where
Self: NBestWrapper<T, F>,
impl<T, F> Extend<T> for NBest<T, F>where
Self: NBestWrapper<T, F>,
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)