@@ -296,8 +296,13 @@ impl TreeInterface {
296
296
fn left_sample ( & self , u : NodeId ) -> Result < NodeId , TskitError > {
297
297
err_if_not_tracking_samples ! (
298
298
self . flags,
299
- unsafe_tsk_column_access!( u. 0 , 0 , self . num_nodes, ( * self . as_ptr( ) ) . left_sample, NodeId )
300
- . unwrap( )
299
+ unsafe_tsk_column_access!(
300
+ u. 0 ,
301
+ 0 ,
302
+ self . num_nodes,
303
+ ( * self . as_ptr( ) ) . left_sample,
304
+ NodeId
305
+ ) ?
301
306
)
302
307
}
303
308
@@ -310,8 +315,7 @@ impl TreeInterface {
310
315
self . num_nodes,
311
316
( * self . as_ptr( ) ) . right_sample,
312
317
NodeId
313
- )
314
- . unwrap( )
318
+ ) ?
315
319
)
316
320
}
317
321
@@ -588,16 +592,20 @@ struct PreorderNodeIterator<'a> {
588
592
589
593
impl < ' a > PreorderNodeIterator < ' a > {
590
594
fn new ( tree : & ' a TreeInterface ) -> Self {
595
+ debug_assert ! ( tree. right_child( tree. virtual_root( ) ) . is_ok( ) ) ;
591
596
let mut rv = PreorderNodeIterator {
592
- current_root : tree. right_child ( tree. virtual_root ( ) ) . unwrap ( ) ,
597
+ current_root : tree
598
+ . right_child ( tree. virtual_root ( ) )
599
+ . unwrap_or ( NodeId :: NULL ) ,
593
600
node_stack : vec ! [ ] ,
594
601
tree,
595
602
current_node_ : None ,
596
603
} ;
597
604
let mut c = rv. current_root ;
598
605
while !c. is_null ( ) {
599
606
rv. node_stack . push ( c) ;
600
- c = rv. tree . left_sib ( c) . unwrap ( ) ;
607
+ debug_assert ! ( rv. tree. left_sib( c) . is_ok( ) ) ;
608
+ c = rv. tree . left_sib ( c) . unwrap_or ( NodeId :: NULL ) ;
601
609
}
602
610
rv
603
611
}
@@ -610,10 +618,12 @@ impl NodeIterator for PreorderNodeIterator<'_> {
610
618
// NOTE: process children right-to-left
611
619
// because we later pop them from a steck
612
620
// to generate the expected left-to-right ordering.
613
- let mut c = self . tree . right_child ( u) . unwrap ( ) ;
621
+ debug_assert ! ( self . tree. right_child( u) . is_ok( ) ) ;
622
+ let mut c = self . tree . right_child ( u) . unwrap_or ( NodeId :: NULL ) ;
614
623
while c != NodeId :: NULL {
615
624
self . node_stack . push ( c) ;
616
- c = self . tree . left_sib ( c) . unwrap ( ) ;
625
+ debug_assert ! ( self . tree. right_child( c) . is_ok( ) ) ;
626
+ c = self . tree . left_sib ( c) . unwrap_or ( NodeId :: NULL ) ;
617
627
}
618
628
} ;
619
629
}
@@ -642,7 +652,7 @@ impl<'a> PostorderNodeIterator<'a> {
642
652
// NOTE: this fn does not return error codes
643
653
usize :: try_from( unsafe {
644
654
ll_bindings:: tsk_tree_get_size_bound( tree. as_ptr( ) )
645
- } ) . unwrap ( )
655
+ } ) . unwrap_or ( usize :: MAX )
646
656
] ;
647
657
648
658
let rv = unsafe {
@@ -664,7 +674,7 @@ impl<'a> PostorderNodeIterator<'a> {
664
674
Self {
665
675
nodes,
666
676
current_node_index : 0 ,
667
- num_nodes_current_tree : usize:: try_from ( num_nodes_current_tree) . unwrap ( ) ,
677
+ num_nodes_current_tree : usize:: try_from ( num_nodes_current_tree) . unwrap_or ( 0 ) ,
668
678
tree : std:: marker:: PhantomData ,
669
679
}
670
680
}
@@ -692,9 +702,10 @@ struct RootIterator<'a> {
692
702
693
703
impl < ' a > RootIterator < ' a > {
694
704
fn new ( tree : & ' a TreeInterface ) -> Self {
705
+ debug_assert ! ( tree. left_child( tree. virtual_root( ) ) . is_ok( ) ) ;
695
706
RootIterator {
696
707
current_root : None ,
697
- next_root : tree. left_child ( tree. virtual_root ( ) ) . unwrap ( ) ,
708
+ next_root : tree. left_child ( tree. virtual_root ( ) ) . unwrap_or ( NodeId :: NULL ) ,
698
709
tree,
699
710
}
700
711
}
@@ -707,7 +718,8 @@ impl NodeIterator for RootIterator<'_> {
707
718
r => {
708
719
assert ! ( r >= 0 ) ;
709
720
let cr = Some ( r) ;
710
- self . next_root = self . tree . right_sib ( r) . unwrap ( ) ;
721
+ debug_assert ! ( self . tree. right_sib( r) . is_ok( ) ) ;
722
+ self . next_root = self . tree . right_sib ( r) . unwrap_or ( NodeId :: NULL ) ;
711
723
cr
712
724
}
713
725
} ;
@@ -745,7 +757,8 @@ impl NodeIterator for ChildIterator<'_> {
745
757
r => {
746
758
assert ! ( r >= 0 ) ;
747
759
let cr = Some ( r) ;
748
- self . next_child = self . tree . right_sib ( r) . unwrap ( ) ;
760
+ debug_assert ! ( self . tree. right_sib( r) . is_ok( ) ) ;
761
+ self . next_child = self . tree . right_sib ( r) . unwrap_or ( NodeId :: NULL ) ;
749
762
cr
750
763
}
751
764
} ;
@@ -793,7 +806,8 @@ impl NodeIterator for ParentsIterator<'_> {
793
806
r => {
794
807
assert ! ( r >= 0 ) ;
795
808
let cr = Some ( r) ;
796
- self . next_node = self . tree . parent ( r) . unwrap ( ) ;
809
+ debug_assert ! ( self . tree. parent( r) . is_ok( ) ) ;
810
+ self . next_node = self . tree . parent ( r) . unwrap_or ( NodeId :: NULL ) ;
797
811
cr
798
812
}
799
813
} ;
@@ -834,14 +848,12 @@ impl NodeIterator for SamplesIterator<'_> {
834
848
NodeId :: NULL => None ,
835
849
r => {
836
850
if r == self . last_sample_index {
837
- //let cr = Some(self.tree.samples(r).unwrap());
838
851
let cr =
839
852
Some ( unsafe { * ( * self . tree . as_ptr ( ) ) . samples . offset ( r. 0 as isize ) } . into ( ) ) ;
840
853
self . next_sample_index = NodeId :: NULL ;
841
854
cr
842
855
} else {
843
856
assert ! ( r >= 0 ) ;
844
- //let cr = Some(self.tree.samples(r).unwrap());
845
857
let cr =
846
858
Some ( unsafe { * ( * self . tree . as_ptr ( ) ) . samples . offset ( r. 0 as isize ) } . into ( ) ) ;
847
859
//self.next_sample_index = self.next_sample[r];
0 commit comments