NBest

Struct NBest 

Source
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: Ord> NBest<T, ()>

Source

pub fn new(n: usize) -> Self

Returns a new NBest with the specified capacity, for items implementing the Ord trait

Source

pub fn with_iter<I>(n: usize, iter: I) -> Self
where I: IntoIterator<Item = T>,

Returns a new NBest, built from the contents of an iterator

Source§

impl<T, F: Fn(&T, &T) -> Ordering + Clone> NBest<T, F>

Source

pub fn with_cmp_fn(n: usize, func: F) -> Self
where F: Fn(&T, &T) -> Ordering,

Returns a new NBest, using the supplied function to perform comparisons

Source

pub fn with_cmp_fn_and_iter<I>(n: usize, func: F, iter: I) -> Self
where F: Fn(&T, &T) -> Ordering, I: IntoIterator<Item = T>,

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>,

Source

pub fn push(&mut self, item: T)

Adds a new element, discarding the lowest element if the collection is at capacity

Source

pub fn pop(&mut self) -> Option<T>

Returns the least element contained within the collection, or None if the collection is empty

Source

pub fn len(&self) -> usize

Returns the number of elements contained within the collection

len() will always be less than capacity.

Source

pub fn capacity(&self) -> usize

Returns the maximum number of elements the collection will collect

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Returns an iterator over the elements contained within the collection, in an unspecified order

Source

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

Source

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>,

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T, F> IntoIterator for NBest<T, F>
where Self: NBestWrapper<T, F>,

Source§

fn into_iter(self) -> Self::IntoIter

Consumes the collection and returns an iterator over the elements, in an unspecified order

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, F>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<T, F> Freeze for NBest<T, F>
where F: Freeze,

§

impl<T, F = ()> !RefUnwindSafe for NBest<T, F>

§

impl<T, F = ()> !Send for NBest<T, F>

§

impl<T, F = ()> !Sync for NBest<T, F>

§

impl<T, F = ()> !Unpin for NBest<T, F>

§

impl<T, F = ()> !UnwindSafe for NBest<T, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.