@@ -121,8 +121,7 @@ pub trait Strategy<G: Graph>: Debug {
121
121
fn midpoint (
122
122
& self ,
123
123
graph : & G ,
124
- success_bounds : & HashSet < G :: Node > ,
125
- failure_bounds : & HashSet < G :: Node > ,
124
+ bounds : & Bounds < G :: Node > ,
126
125
statuses : & IndexMap < G :: Node , Status > ,
127
126
) -> Result < Option < G :: Node > , Self :: Error > ;
128
127
}
@@ -274,8 +273,7 @@ impl<G: Graph> Search<G> {
274
273
275
274
#[ derive( Debug ) ]
276
275
struct State < G : Graph > {
277
- success_bounds : HashSet < G :: Node > ,
278
- failure_bounds : HashSet < G :: Node > ,
276
+ bounds : Bounds < G :: Node > ,
279
277
statuses : IndexMap < G :: Node , Status > ,
280
278
}
281
279
@@ -292,24 +290,16 @@ impl<G: Graph> Search<G> {
292
290
fn next ( & mut self ) -> Option < Self :: Item > {
293
291
while let Some ( state) = self . states . pop_front ( ) {
294
292
debug ! ( ?state, "Popped speculation state" ) ;
295
- let State {
296
- success_bounds,
297
- failure_bounds,
298
- statuses,
299
- } = state;
300
-
301
- let node = match self . strategy . midpoint (
302
- self . graph ,
303
- & success_bounds,
304
- & failure_bounds,
305
- & statuses,
306
- ) {
293
+ let State { bounds, statuses } = state;
294
+
295
+ let node = match self . strategy . midpoint ( self . graph , & bounds, & statuses) {
307
296
Ok ( Some ( node) ) => node,
308
297
Ok ( None ) => continue ,
309
298
Err ( err) => return Some ( Err ( SearchError :: Strategy ( err) ) ) ,
310
299
} ;
311
300
312
- for success_node in success_bounds. iter ( ) {
301
+ let Bounds { success, failure } = bounds;
302
+ for success_node in success. iter ( ) {
313
303
match self . graph . is_ancestor ( node. clone ( ) , success_node. clone ( ) ) {
314
304
Ok ( true ) => {
315
305
return Some ( Err ( SearchError :: AlreadySearchedMidpoint {
@@ -321,7 +311,7 @@ impl<G: Graph> Search<G> {
321
311
Err ( err) => return Some ( Err ( SearchError :: Graph ( err) ) ) ,
322
312
}
323
313
}
324
- for failure_node in failure_bounds . iter ( ) {
314
+ for failure_node in failure . iter ( ) {
325
315
match self . graph . is_ancestor ( failure_node. clone ( ) , node. clone ( ) ) {
326
316
Ok ( true ) => {
327
317
return Some ( Err ( SearchError :: AlreadySearchedMidpoint {
@@ -336,14 +326,16 @@ impl<G: Graph> Search<G> {
336
326
337
327
// Speculate failure:
338
328
self . states . push_back ( State {
339
- success_bounds : success_bounds. clone ( ) ,
340
- failure_bounds : {
341
- let mut failure_bounds = failure_bounds. clone ( ) ;
342
- failure_bounds. insert ( node. clone ( ) ) ;
343
- match self . graph . simplify_failure_bounds ( failure_bounds) {
344
- Ok ( bounds) => bounds,
345
- Err ( err) => return Some ( Err ( SearchError :: Graph ( err) ) ) ,
346
- }
329
+ bounds : Bounds {
330
+ success : success. clone ( ) ,
331
+ failure : {
332
+ let mut failure_bounds = failure. clone ( ) ;
333
+ failure_bounds. insert ( node. clone ( ) ) ;
334
+ match self . graph . simplify_failure_bounds ( failure_bounds) {
335
+ Ok ( bounds) => bounds,
336
+ Err ( err) => return Some ( Err ( SearchError :: Graph ( err) ) ) ,
337
+ }
338
+ } ,
347
339
} ,
348
340
statuses : {
349
341
let mut statuses = statuses. clone ( ) ;
@@ -354,15 +346,17 @@ impl<G: Graph> Search<G> {
354
346
355
347
// Speculate success:
356
348
self . states . push_back ( State {
357
- success_bounds : {
358
- let mut success_bounds = success_bounds. clone ( ) ;
359
- success_bounds. insert ( node. clone ( ) ) ;
360
- match self . graph . simplify_success_bounds ( success_bounds) {
361
- Ok ( bounds) => bounds,
362
- Err ( err) => return Some ( Err ( SearchError :: Graph ( err) ) ) ,
363
- }
349
+ bounds : Bounds {
350
+ success : {
351
+ let mut success_bounds = success. clone ( ) ;
352
+ success_bounds. insert ( node. clone ( ) ) ;
353
+ match self . graph . simplify_success_bounds ( success_bounds) {
354
+ Ok ( bounds) => bounds,
355
+ Err ( err) => return Some ( Err ( SearchError :: Graph ( err) ) ) ,
356
+ }
357
+ } ,
358
+ failure : failure. clone ( ) ,
364
359
} ,
365
- failure_bounds : failure_bounds. clone ( ) ,
366
360
statuses : {
367
361
let mut statuses = statuses. clone ( ) ;
368
362
statuses. insert ( node. clone ( ) , Status :: Success ) ;
@@ -379,8 +373,10 @@ impl<G: Graph> Search<G> {
379
373
}
380
374
381
375
let initial_state = State {
382
- success_bounds : success_bounds. clone ( ) ,
383
- failure_bounds : failure_bounds. clone ( ) ,
376
+ bounds : Bounds {
377
+ success : success_bounds. clone ( ) ,
378
+ failure : failure_bounds. clone ( ) ,
379
+ } ,
384
380
statuses : self . nodes . clone ( ) ,
385
381
} ;
386
382
let iter = Iter {
0 commit comments