Skip to content

Commit 900f1e8

Browse files
committed
k_smallest: Comment what we do with peek_mut()
1 parent 036a451 commit 900f1e8

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/k_smallest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn k_smallest<T: Ord, I: Iterator<Item = T>>(mut iter: I, k: usize) -
1010
debug_assert_eq!(heap.len(), k);
1111
// Guaranteed not-None, since we keep exactly k>0 elements in the heap.
1212
let mut lorgest = heap.peek_mut().unwrap();
13+
// Equivalent to heap.push(min(i, heap.pop())) but more efficient.
1314
if *lorgest > i { *lorgest = i; }
1415
}
1516

0 commit comments

Comments
 (0)