diff --git a/src/k_smallest.rs b/src/k_smallest.rs index fe699fbd4..b909887f5 100644 --- a/src/k_smallest.rs +++ b/src/k_smallest.rs @@ -57,6 +57,7 @@ where } iter.for_each(|val| { + debug_assert_eq!(storage.len(), k); if is_less_than(&val, &storage[0]) { // Treating this as an push-and-pop saves having to write a sift-up implementation. // https://en.wikipedia.org/wiki/Binary_heap#Insert_then_extract diff --git a/src/lib.rs b/src/lib.rs index 73f841aa6..a297a6d80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3190,6 +3190,7 @@ pub trait Itertools: Iterator { let mut data: Vec<_> = iter.by_ref().take(n).collect(); // Update `data` cyclically. let idx = iter.fold(0, |i, val| { + debug_assert_eq!(data.len(), n); data[i] = val; if i + 1 == n { 0