File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -668,6 +668,11 @@ impl NodeIterator for PreorderNodeIterator<'_> {
668
668
None => {
669
669
if let Some ( r) = self . root_stack . pop ( ) {
670
670
self . current_node_ = Some ( r) ;
671
+ let mut c = self . tree . right_child ( r) . unwrap ( ) ;
672
+ while c != NodeId :: NULL {
673
+ self . node_stack . push ( c) ;
674
+ c = self . tree . left_sib ( c) . unwrap ( ) ;
675
+ }
671
676
}
672
677
}
673
678
} ;
@@ -1428,8 +1433,30 @@ pub(crate) mod test_trees {
1428
1433
assert_eq ! ( nsamples, tree. num_tracked_samples( n) . unwrap( ) ) ;
1429
1434
}
1430
1435
assert_eq ! ( preoder_nodes. len( ) , postoder_nodes. len( ) ) ;
1436
+
1437
+ // Test our preorder against the tskit functions in 0.99.15
1438
+ {
1439
+ let mut nodes: Vec < NodeId > = vec ! [
1440
+ NodeId :: NULL ;
1441
+ unsafe { ll_bindings:: tsk_tree_get_size_bound( tree. as_ptr( ) ) }
1442
+ as usize
1443
+ ] ;
1444
+ let mut num_nodes: tsk_size_t = 0 ;
1445
+ let ptr = std:: ptr:: addr_of_mut!( num_nodes) ;
1446
+ unsafe {
1447
+ ll_bindings:: tsk_tree_preorder (
1448
+ tree. as_ptr ( ) ,
1449
+ -1 ,
1450
+ nodes. as_mut_ptr ( ) as * mut tsk_id_t ,
1451
+ ptr,
1452
+ ) ;
1453
+ }
1454
+ assert_eq ! ( num_nodes as usize , preoder_nodes. len( ) ) ;
1455
+ for i in 0 ..num_nodes as usize {
1456
+ assert_eq ! ( preoder_nodes[ i] , nodes[ i] ) ;
1457
+ }
1458
+ }
1431
1459
}
1432
- assert ! ( false ) ;
1433
1460
}
1434
1461
1435
1462
#[ test]
You can’t perform that action at this time.
0 commit comments