@@ -330,27 +330,31 @@ impl<'a, 'b, G: RandomAccessGraph> Iterator for BfsOrder<'a, 'b, G> {
330
330
}
331
331
332
332
// the successors are exhausted, so we need to move to the next node
333
- self . current_node = match self . visit . queue . pop_front ( ) {
334
- // if we have a node, we can continue visiting its successors
335
- Some ( Some ( node) ) => node. into ( ) ,
336
- // new level separator, so we increment the distance
337
- Some ( None ) => {
338
- self . distance += 1 ;
339
- self . visit . queue . push_back ( None ) ;
340
- // TODO: this assumes the iter are fuse
341
- continue ;
342
- }
343
- // if the queue is empty, we need to find the next unvisited node
344
- None => {
345
- while self . visit . visited [ self . start ] {
346
- self . start += 1 ;
347
- if self . start >= self . visit . graph . num_nodes ( ) {
348
- return None ;
333
+ self . current_node = loop {
334
+ match self . visit . queue . pop_front ( ) {
335
+ // if we have a node, we can continue visiting its successors
336
+ Some ( Some ( node) ) => break node. into ( ) ,
337
+ // new level separator, so we increment the distance
338
+ Some ( None ) => {
339
+ self . distance += 1 ;
340
+ // if the queue is not empty, we need to add a new level separator
341
+ if !self . visit . queue . is_empty ( ) {
342
+ self . visit . queue . push_back ( None ) ;
343
+ }
344
+ continue ;
345
+ }
346
+ // if the queue is empty, we need to find the next unvisited node
347
+ None => {
348
+ while self . visit . visited [ self . start ] {
349
+ self . start += 1 ;
350
+ if self . start >= self . visit . graph . num_nodes ( ) {
351
+ return None ;
352
+ }
349
353
}
354
+ self . visit . visited . set ( self . start , true ) ;
355
+ self . distance = 0 ; // new visits, new distance
356
+ break self . start
350
357
}
351
- self . visit . visited . set ( self . start , true ) ;
352
- self . distance = 0 ; // new visits, new distance
353
- self . start
354
358
}
355
359
} ;
356
360
// reset the successors iterator for the new current node
0 commit comments