Skip to content

Commit 51670c9

Browse files
committed
k_smollest: Add debug_assert for invariant
1 parent 46a739f commit 51670c9

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
@@ -7,6 +7,7 @@ pub(crate) fn k_smallest<T: Ord, I: Iterator<Item = T>>(mut iter: I, k: usize) -
77
let mut heap = iter.by_ref().take(k).collect::<BinaryHeap<_>>();
88

99
for i in iter {
10+
debug_assert_eq!(heap.len(), k);
1011
// Guaranteed not-None, since we keep exactly k>0 elements in the heap.
1112
let mut lorgest = heap.peek_mut().unwrap();
1213
if *lorgest > i { *lorgest = i; }

0 commit comments

Comments
 (0)