@@ -15,7 +15,6 @@ pub struct TreeInterface {
1515 num_nodes : tsk_size_t ,
1616 array_len : tsk_size_t ,
1717 flags : TreeFlags ,
18- nodes : crate :: NodeTable ,
1918}
2019
2120impl TreeInterface {
@@ -25,16 +24,11 @@ impl TreeInterface {
2524 array_len : tsk_size_t ,
2625 flags : TreeFlags ,
2726 ) -> Self {
28- let nodes = crate :: NodeTable :: new_from_table (
29- & mut unsafe { * ( * non_owned_pointer. as_ref ( ) . tree_sequence ) . tables } . nodes ,
30- )
31- . expect ( "null pointer to tsk_node_table_t" ) ;
3227 Self {
3328 non_owned_pointer,
3429 num_nodes,
3530 array_len,
3631 flags,
37- nodes,
3832 }
3933 }
4034
@@ -495,9 +489,9 @@ impl TreeInterface {
495489 /// (and the tree sequence from which it came).
496490 ///
497491 /// This is a convenience function for accessing node times, etc..
498- fn node_table ( & self ) -> & crate :: NodeTable {
499- & self . nodes
500- }
492+ // fn node_table(&self) -> &crate::NodeTable {
493+ // &self.nodes
494+ // }
501495
502496 /// Calculate the total length of the tree via a preorder traversal.
503497 ///
@@ -509,13 +503,19 @@ impl TreeInterface {
509503 ///
510504 /// [`TskitError`] may be returned if a node index is out of range.
511505 pub fn total_branch_length ( & self , by_span : bool ) -> Result < Time , TskitError > {
512- let nt = self . node_table ( ) ;
506+ let time: & [ Time ] = sys:: generate_slice (
507+ unsafe {
508+ ( * ( * ( * self . non_owned_pointer . as_ptr ( ) ) . tree_sequence ) . tables )
509+ . nodes
510+ . time
511+ } ,
512+ self . num_nodes ,
513+ ) ;
513514 let mut b = Time :: from ( 0. ) ;
514515 for n in self . traverse_nodes ( NodeTraversalOrder :: Preorder ) {
515516 let p = self . parent ( n) . ok_or ( TskitError :: IndexError { } ) ?;
516517 if p != NodeId :: NULL {
517- b += nt. time ( p) . ok_or ( TskitError :: IndexError { } ) ?
518- - nt. time ( n) . ok_or ( TskitError :: IndexError { } ) ?;
518+ b += time[ p. as_usize ( ) ] - time[ n. as_usize ( ) ]
519519 }
520520 }
521521
0 commit comments