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
impl TopK
Sourcepub fn new(k: usize) -> Self
pub fn new(k: usize) -> Self
Create a collector retaining up to k neighbors.
k == 0 yields a collector that keeps nothing.
Sourcepub fn offer(&mut self, candidate: Neighbor)
pub fn offer(&mut self, candidate: Neighbor)
Offer a candidate. Kept only if it ranks among the best k seen so far.
Sourcepub fn worst_score(&self) -> Option<f32>
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.
Sourcepub fn into_sorted_vec(self) -> Vec<Neighbor>
pub fn into_sorted_vec(self) -> Vec<Neighbor>
Consume the collector, returning neighbors sorted ascending (best first).
Trait Implementations§
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> 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