Skip to content

Commit 557cb89

Browse files
Merge #745
745: Do not sum options r=phimuemue a=Philippe-Cholet A mistake on my part, discovered in time as code is still commented out. Note that it passed tests. It only returns None if the iterator yields None. But it would overflow whenever an addition does. Do not product options either, as multiplications could overflow the same way. That's how I found out. I guess `checked_sum` and `checked_product` methods would be nice. EDIT: ~Would you be interested?~ Related: rust-lang/rust#95485 Co-authored-by: Philippe-Cholet <[email protected]>
2 parents c7a038e + 79a1b15 commit 557cb89

File tree

2 files changed

+0
-6
lines changed

2 files changed

+0
-6
lines changed

src/combinations.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ fn remaining_for(n: usize, first: bool, indices: &[usize]) -> Option<usize> {
208208
indices
209209
.iter()
210210
.enumerate()
211-
// TODO: Once the MSRV hits 1.37.0, we can sum options instead:
212-
// .map(|(i, n0)| checked_binomial(n - 1 - *n0, k - i))
213-
// .sum()
214211
.fold(Some(0), |sum, (i, n0)| {
215212
sum.and_then(|s| s.checked_add(checked_binomial(n - 1 - *n0, k - i)?))
216213
})

src/combinations_with_replacement.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ fn remaining_for(n: usize, first: bool, indices: &[usize]) -> Option<usize> {
157157
indices
158158
.iter()
159159
.enumerate()
160-
// TODO: Once the MSRV hits 1.37.0, we can sum options instead:
161-
// .map(|(i, n0)| count(n - 1 - *n0, k - i))
162-
// .sum()
163160
.fold(Some(0), |sum, (i, n0)| {
164161
sum.and_then(|s| s.checked_add(count(n - 1 - *n0, k - i)?))
165162
})

0 commit comments

Comments
 (0)