Skip to main content

TopK

Struct TopK 

Source
pub struct TopK { /* private fields */ }
Expand description

Collects the k best (smallest-score) neighbors from a stream of candidates in O(N log k) time and O(k) memory.

Never materializes all candidate distances — suitable for a brute-force scan over an arbitrarily large store, or for bounding a graph beam.

Implementations§

Source§

impl TopK

Source

pub fn new(k: usize) -> Self

Create a collector retaining up to k neighbors.

k == 0 yields a collector that keeps nothing.

Source

pub fn offer(&mut self, candidate: Neighbor)

Offer a candidate. Kept only if it ranks among the best k seen so far.

Source

pub fn worst_score(&self) -> Option<f32>

The current worst (largest) retained score, or None if empty.

Useful as a beam-search cutoff: once k neighbors are held, any candidate not better than this can be skipped.

Source

pub fn is_full(&self) -> bool

Whether the collector is full (holds exactly k neighbors).

Source

pub fn len(&self) -> usize

Number of neighbors currently retained.

Source

pub fn is_empty(&self) -> bool

Whether no neighbors are retained.

Source

pub fn into_sorted_vec(self) -> Vec<Neighbor>

Consume the collector, returning neighbors sorted ascending (best first).

Trait Implementations§

Source§

impl Debug for TopK

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for TopK

§

impl RefUnwindSafe for TopK

§

impl Send for TopK

§

impl Sync for TopK

§

impl Unpin for TopK

§

impl UnsafeUnpin for TopK

§

impl UnwindSafe for TopK

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.