From b51f26a34f018494c249ebf79daf9225ba619677 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet <44676486+Philippe-Cholet@users.noreply.github.com> Date: Sun, 17 Mar 2024 09:37:44 +0100 Subject: [PATCH] Check two invariants --- src/k_smallest.rs | 1 + src/lib.rs | 1 + 2 files changed, 2 insertions(+) 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