Skip to main content

push_bounded

Function push_bounded 

Source
pub fn push_bounded<K: Ord, R>(
    heap: &mut BinaryHeap<HeapEntry<K, R>>,
    count: usize,
    entry: HeapEntry<K, R>,
)
Expand description

Keeps the count smallest HeapEntrys seen so far – the standard bounded-heap top-K algorithm: push while under capacity, otherwise evict the current worst-kept entry if entry ranks ahead of it. Provably identical final set (and, via BinaryHeap::into_sorted_vec, identical order) to “collect everything, sort ascending by the same key, truncate” – at O(count) memory instead of O(n).