@@ -51,24 +51,22 @@ impl<'a, M: BnbMetric> Iterator for BnbIter<'a, M> {
51
51
52
52
let selector = branch. selector ;
53
53
54
- self . insert_new_branches ( & selector) ;
55
-
56
- if branch. is_exclusion {
57
- return Some ( None ) ;
54
+ let mut return_val = None ;
55
+ if !branch. is_exclusion {
56
+ if let Some ( score) = self . metric . score ( & selector) {
57
+ let better = match self . best {
58
+ Some ( best_score) => score < best_score,
59
+ None => true ,
60
+ } ;
61
+ if better {
62
+ self . best = Some ( score) ;
63
+ return_val = Some ( score) ;
64
+ }
65
+ } ;
58
66
}
59
67
60
- let score = match self . metric . score ( & selector) {
61
- Some ( score) => score,
62
- None => return Some ( None ) ,
63
- } ;
64
-
65
- if let Some ( best_score) = & self . best {
66
- if score >= * best_score {
67
- return Some ( None ) ;
68
- }
69
- }
70
- self . best = Some ( score) ;
71
- Some ( Some ( ( selector, score) ) )
68
+ self . insert_new_branches ( & selector) ;
69
+ Some ( return_val. map ( |score| ( selector, score) ) )
72
70
}
73
71
}
74
72
@@ -92,7 +90,11 @@ impl<'a, M: BnbMetric> BnbIter<'a, M> {
92
90
fn consider_adding_to_queue ( & mut self , cs : & CoinSelector < ' a > , is_exclusion : bool ) {
93
91
let bound = self . metric . bound ( cs) ;
94
92
if let Some ( bound) = bound {
95
- if self . best . is_none ( ) || self . best . as_ref ( ) . unwrap ( ) >= & bound {
93
+ let is_good_enough = match self . best {
94
+ Some ( best) => best > bound,
95
+ None => true ,
96
+ } ;
97
+ if is_good_enough {
96
98
let branch = Branch {
97
99
lower_bound : bound,
98
100
selector : cs. clone ( ) ,
0 commit comments