Skip to content

Commit ba8e675

Browse files
Check two invariants
1 parent 5632546 commit ba8e675

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/k_smallest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ where
5757
}
5858

5959
iter.for_each(|val| {
60+
debug_assert_eq!(storage.len(), k);
6061
if is_less_than(&val, &storage[0]) {
6162
// Treating this as an push-and-pop saves having to write a sift-up implementation.
6263
// https://en.wikipedia.org/wiki/Binary_heap#Insert_then_extract

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3188,6 +3188,7 @@ pub trait Itertools: Iterator {
31883188
let mut data: Vec<_> = iter.by_ref().take(n).collect();
31893189
// Update `data` cyclically.
31903190
let idx = iter.fold(0, |i, val| {
3191+
debug_assert_eq!(data.len(), n);
31913192
data[i] = val;
31923193
if i + 1 == n {
31933194
0

0 commit comments

Comments
 (0)