Skip to content

Commit

Permalink
Check two invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Mar 18, 2024
1 parent 3ec5573 commit 4d96da1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/k_smallest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4d96da1

Please sign in to comment.